Compare commits

...

88 commits

Author SHA1 Message Date
397d2bcf70
feat: /titles page implementation with cursor pagination 2025-11-19 10:54:52 +03:00
a515769823
Merge branch 'dev-ars' into front 2025-11-19 01:13:19 +03:00
cdfa14cece feat: cursor added 2025-11-19 00:41:54 +03:00
b976c35b8e
feat: titles page
Some checks failed
Build and Deploy Go App / build (push) Failing after 11m8s
Build and Deploy Go App / deploy (push) Has been skipped
2025-11-18 05:15:38 +03:00
6836cfa057 feat: stub for get user titles written
Some checks failed
Build and Deploy Go App / build (push) Has been cancelled
Build and Deploy Go App / deploy (push) Has been cancelled
2025-11-18 05:11:35 +03:00
09d0d1eb4d feat: get user titles described 2025-11-18 04:59:19 +03:00
8deba7afd9 fix
All checks were successful
Build and Deploy Go App / build (push) Successful in 17m41s
Build and Deploy Go App / deploy (push) Successful in 3m34s
2025-11-18 04:19:34 +03:00
8371121130 fix
All checks were successful
Build and Deploy Go App / build (push) Successful in 17m59s
Build and Deploy Go App / deploy (push) Successful in 3m34s
2025-11-18 03:12:16 +03:00
148ae646b1 feat
All checks were successful
Build and Deploy Go App / build (push) Successful in 17m38s
Build and Deploy Go App / deploy (push) Successful in 3m33s
2025-11-17 09:39:26 +03:00
76d28d0170 Merge branch 'dev-ars' into dev
Some checks failed
Build and Deploy Go App / build (push) Has been cancelled
Build and Deploy Go App / deploy (push) Has been cancelled
2025-11-17 09:27:32 +03:00
df45a327e6 fix 2025-11-17 09:26:58 +03:00
abf09e5f5e Merge branch 'dev-ars' of ssh://meowgit.nekoea.red:22222/nihonium/nyanimedb into dev-ars 2025-11-17 03:56:27 +03:00
35a4e173f0 feat: query GetReviewById added 2025-11-17 03:55:42 +03:00
f888ac9b70
review: review notes for titles.go 2025-11-17 02:41:45 +03:00
fe54b61822 Merge branch 'dev-ars' into dev
All checks were successful
Build and Deploy Go App / build (push) Successful in 17m29s
Build and Deploy Go App / deploy (push) Successful in 3m26s
2025-11-16 04:52:52 +03:00
b81cc86beb fix: 2025-11-16 04:52:11 +03:00
29f0a61299 feat: reviews table added 2025-11-16 04:15:33 +03:00
96611825bc Merge branch 'dev-ars' into dev
All checks were successful
Build and Deploy Go App / build (push) Successful in 18m14s
Build and Deploy Go App / deploy (push) Successful in 3m34s
2025-11-16 03:45:06 +03:00
47989ab10d feat: /titles/{id} endpoint implemented 2025-11-16 03:38:51 +03:00
cefbbec1dc feat: wrote query to get one title 2025-11-16 02:43:28 +03:00
13a283ae8d feat: GetTitles now returns all the field needed 2025-11-16 02:38:36 +03:00
d1180a426f feat: new schema for images 2025-11-16 02:14:38 +03:00
e18f4a44c3 feat: more fields for titles and refactored schemas 2025-11-16 01:47:11 +03:00
4949a3c25f refactor: new types 2025-11-15 23:00:40 +03:00
e6dc27fd55 feat: statements for tags added 2025-11-15 19:19:39 +03:00
3cca6ee168 feat: statements for studios table added 2025-11-15 18:56:46 +03:00
2edf96571b feat: field studio_name added to title in openapi 2025-11-15 18:20:27 +03:00
f49fad2307 fix: tmp commeneted method
All checks were successful
Build and Deploy Go App / build (push) Successful in 18m15s
Build and Deploy Go App / deploy (push) Successful in 4m50s
2025-11-15 03:01:38 +03:00
5cc6757900 feat: minor changes to db and new query
Some checks failed
Build and Deploy Go App / build (push) Failing after 5m56s
Build and Deploy Go App / deploy (push) Has been skipped
2025-11-15 02:51:52 +03:00
e8783a0e9d feat: get title func written 2025-11-15 02:51:13 +03:00
ae01eec0fd fix!: some types were changed 2025-11-15 02:50:29 +03:00
d04248ab7a feat 2025-11-15 01:02:30 +03:00
d2450ffc89 feat: titles.go added 2025-11-15 00:52:23 +03:00
c2dc762700 feat: openapi changes 2025-11-15 00:46:47 +03:00
765e75e8bb feat: new responses added 2025-11-15 00:04:43 +03:00
7fed5ed536 feat: get titles added with all components needed 2025-11-14 23:57:34 +03:00
f24edc5dd7 feat: external_services table create 2025-11-14 15:34:48 +03:00
83fee98059 feat: external_ids table is added for binding user sessions in tg and
other services
2025-11-14 15:22:14 +03:00
bac889b627 fix: regexps for mail and nickname were corrected 2025-11-05 17:20:09 +03:00
4ffa7dc93e feat: add new user handler was uncommented 2025-11-05 17:11:43 +03:00
6d538ed154 feat: common code for back functions are now in handlers/common.go 2025-11-01 21:17:42 +03:00
6ed47b667c
feat: proxy api requests via frontend
All checks were successful
Build and Deploy Go App / build (push) Successful in 8m23s
Build and Deploy Go App / deploy (push) Successful in 3m31s
2025-10-26 04:06:38 +03:00
66281838b2
fix: new psql feature
All checks were successful
Build and Deploy Go App / build (push) Successful in 8m46s
Build and Deploy Go App / deploy (push) Successful in 3m35s
2025-10-26 03:18:54 +03:00
feb763509e
fix: regenerated frontend openapi functions
All checks were successful
Build and Deploy Go App / build (push) Successful in 8m44s
Build and Deploy Go App / deploy (push) Successful in 3m24s
2025-10-26 02:51:53 +03:00
fd1e129a5f
fix: remove templates from cicd
Some checks failed
Build and Deploy Go App / build (push) Has been cancelled
Build and Deploy Go App / deploy (push) Has been cancelled
2025-10-26 02:49:50 +03:00
92c06bbb50
fix: remove templates from backend Dockerfile
Some checks failed
Build and Deploy Go App / build (push) Failing after 5m49s
Build and Deploy Go App / deploy (push) Has been skipped
2025-10-26 02:44:28 +03:00
e12812d202
feat: frontend first routing implementation
Some checks failed
Build and Deploy Go App / build (push) Failing after 6m8s
Build and Deploy Go App / deploy (push) Has been skipped
2025-10-26 02:39:54 +03:00
948e036e8c
feat: implemented /users/{id} api route 2025-10-26 02:34:45 +03:00
71e2661fb9
feat!: rewritten db scheme 2025-10-26 02:09:44 +03:00
db53ae04e3
refact!: project structure
Some checks failed
Build and Deploy Go App / build (push) Failing after 4m35s
Build and Deploy Go App / deploy (push) Has been skipped
2025-10-25 21:05:16 +03:00
fd0ca4411b
feat: created UserPage.tsx
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m33s
Build and Deploy Go App / deploy (push) Successful in 2m52s
2025-10-11 05:24:11 +03:00
827431bb2f
fix: App.tsx user field names
All checks were successful
Build and Deploy Go App / build (push) Successful in 7m1s
Build and Deploy Go App / deploy (push) Successful in 2m55s
2025-10-11 04:54:39 +03:00
0b5ea285de
fix: regenerated api
Some checks failed
Build and Deploy Go App / build (push) Failing after 4m6s
Build and Deploy Go App / deploy (push) Has been skipped
2025-10-11 04:52:21 +03:00
a0df0dff00
feat: add User scahema to api 2025-10-11 04:51:50 +03:00
f2188f6363
fix: temp fix for API endpoint
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m42s
Build and Deploy Go App / deploy (push) Successful in 2m53s
2025-10-11 04:33:56 +03:00
8e44b8b7b4
feat: fetch user info
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m46s
Build and Deploy Go App / deploy (push) Successful in 2m54s
2025-10-11 04:25:57 +03:00
28c38ca1a0 feat: db url env added
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m44s
Build and Deploy Go App / deploy (push) Successful in 2m47s
2025-10-11 02:27:13 +03:00
102d15c5fd feat: connection to db logic added to main
Some checks failed
Build and Deploy Go App / build (push) Successful in 8m52s
Build and Deploy Go App / deploy (push) Has been cancelled
2025-10-11 02:19:33 +03:00
eda59c68d3 feat: all the work with db now here, for some time it dups ../api dir 2025-10-11 02:18:14 +03:00
e239c0ca04 fix: now use strictgin 2025-10-11 02:16:48 +03:00
80285ba7da feat: implementation for handlers were written 2025-10-11 02:13:08 +03:00
31a09037cb feat: sql queries were written and used to generate queries.go 2025-10-11 02:11:06 +03:00
2d2d97ec27 feat: field mail added in user table 2025-10-10 22:03:10 +03:00
03f5b3b3db Merge remote-tracking branch 'origin/dev' into dev-ars 2025-10-10 21:39:47 +03:00
29c034bd1a feat: passhash field added to users table 2025-10-10 21:36:53 +03:00
de1479c995
feat: run cicd on dev branch push
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m30s
Build and Deploy Go App / deploy (push) Successful in 2m50s
2025-10-10 13:51:40 +03:00
18722db340 fix: topology sort for tables (references) 2025-10-10 01:23:09 +03:00
8b317ae655 feat: added all table to sql scheme 2025-10-10 01:12:35 +03:00
cbbb135a72 feat: first sql-scheme added 2025-10-09 22:27:54 +03:00
8f1701eb92 Merge pull request 'first PoC frontend' (#3) from cicd into master
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m27s
Build and Deploy Go App / deploy (push) Successful in 2m47s
Reviewed-on: #3
2025-10-09 17:48:20 +03:00
11d073f275
fix: docker-compose -> docker compose
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m32s
Build and Deploy Go App / deploy (push) Successful in 2m44s
2025-10-09 17:37:10 +03:00
c1e8d52aea
fix: repull docker images before deploying
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m17s
Build and Deploy Go App / deploy (push) Successful in 2m41s
2025-10-09 17:31:40 +03:00
9091d11810
fix: writing env var to .env
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m17s
Build and Deploy Go App / deploy (push) Successful in 2m41s
2025-10-09 17:23:33 +03:00
35fa8dd005
fix: use .env for vite build
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m30s
Build and Deploy Go App / deploy (push) Successful in 2m41s
2025-10-09 17:13:45 +03:00
1e834ba69c
tmp: add echo env var
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m14s
Build and Deploy Go App / deploy (push) Successful in 2m42s
2025-10-09 16:28:27 +03:00
78680c6425
fix: moved env to task for build job
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m23s
Build and Deploy Go App / deploy (push) Successful in 2m41s
2025-10-09 16:20:25 +03:00
a2c6074b3d
fix: moved env to container for build job
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m36s
Build and Deploy Go App / deploy (push) Successful in 2m41s
2025-10-09 16:10:47 +03:00
17217cfa6c
fix: removed frontend build args
All checks were successful
Build and Deploy Go App / build (push) Successful in 6m15s
Build and Deploy Go App / deploy (push) Successful in 2m42s
2025-10-09 15:55:11 +03:00
6a352803d4
fix: frontend build args
Some checks failed
Build and Deploy Go App / build (push) Has been cancelled
Build and Deploy Go App / deploy (push) Has been cancelled
2025-10-09 15:52:10 +03:00
a7e99b222d
fix: docker build context
All checks were successful
Build and Deploy Go App / build (push) Successful in 8m11s
Build and Deploy Go App / deploy (push) Successful in 2m39s
2025-10-09 15:40:17 +03:00
ed965e9c21
fix: backend Dockerfile paths
Some checks failed
Build and Deploy Go App / build (push) Failing after 6m15s
Build and Deploy Go App / deploy (push) Has been skipped
2025-10-09 15:33:49 +03:00
cfc753bf84
fix: frontend build
Some checks failed
Build and Deploy Go App / build (push) Failing after 6m32s
Build and Deploy Go App / deploy (push) Has been skipped
2025-10-09 15:28:25 +03:00
951db38e4c
feat: build frontend via cicd
Some checks failed
Build and Deploy Go App / build (push) Failing after 6m34s
Build and Deploy Go App / deploy (push) Has been skipped
2025-10-09 15:16:48 +03:00
f680e16be5
feat: modified dockerfiles for cicd build 2025-10-09 15:16:19 +03:00
4085efd372
Merge branch 'front' into cicd
Some checks failed
Build and Deploy Go App / build (push) Failing after 3m2s
Build and Deploy Go App / deploy (push) Has been skipped
2025-10-09 14:46:48 +03:00
e2a9bcbc93
feat: added backend/frontend to buildx 2025-10-09 14:46:16 +03:00
f4a96db942
refact: renamed server to backend 2025-10-09 14:45:41 +03:00
bd865c709e feat: added openapi spec
All checks were successful
Build and Deploy Go App / build (push) Successful in 5m20s
Build and Deploy Go App / deploy (push) Successful in 2m38s
2025-10-09 03:18:17 +03:00
68 changed files with 6004 additions and 330 deletions

View file

@ -5,6 +5,7 @@ on:
branches:
- master
- cicd
- dev
jobs:
build:
@ -12,31 +13,54 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
# Build backend
- uses: actions/setup-go@v6
with:
go-version: '^1.25'
check-latest: false
cache-dependency-path: |
modules/server/go.sum
modules/backend/go.sum
- name: Build Go app
run: |
cd modules/backend
go mod tidy
go build -o nyanimedb .
tar -czvf nyanimedb-backend.tar.gz nyanimedb
- name: Upload built backend to artifactory
uses: actions/upload-artifact@v3
with:
name: nyanimedb-backend.tar.gz
path: modules/backend/nyanimedb-backend.tar.gz
# Build frontend
- uses: actions/setup-node@v5
with:
node-version-file: modules/frontend/package.json
cache: npm
cache-dependency-path: modules/frontend/package-lock.json
- name: Build frontend
env:
VITE_BACKEND_API_BASE_URL: ${{ vars.BACKEND_API_BASE_URL }}
run: |
cd modules/frontend
npm install
npm run build
tar -czvf nyanimedb-frontend.tar.gz dist/
- name: Upload built frontend to artifactory
uses: actions/upload-artifact@v3
with:
name: nyanimedb-frontend.tar.gz
path: modules/frontend/nyanimedb-frontend.tar.gz
# Build Docker images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Build application
- name: Build Go app
run: |
cd modules/server
go mod tidy
go build -o nyanimedb .
- name: Upload built application to artifactory
uses: actions/upload-artifact@v3
with:
name: nyanimedb
path: modules/server/nyanimedb
# Build Docker image
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
@ -44,13 +68,21 @@ jobs:
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Build and push
- name: Build and push backend image
uses: docker/build-push-action@v6
with:
context: ./modules/server
file: Dockerfiles/Dockerfile_server
context: .
file: Dockerfiles/Dockerfile_backend
push: true
tags: meowgit.nekoea.red/nihonium/nyanimedb:latest
tags: meowgit.nekoea.red/nihonium/nyanimedb-backend:latest
- name: Build and push frontend image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfiles/Dockerfile_frontend
push: true
tags: meowgit.nekoea.red/nihonium/nyanimedb-frontend:latest
deploy:
runs-on: self-hosted
@ -62,6 +94,7 @@ jobs:
POSTGRES_PORT: 5432
POSTGRES_VERSION: 18
LOG_LEVEL: ${{ vars.LOG_LEVEL }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
steps:
- name: Checkout code
@ -71,4 +104,5 @@ jobs:
run: |
cd deploy
docker compose down || true
docker compose pull || true
docker compose up -d

View file

@ -0,0 +1,6 @@
FROM ubuntu:22.04
WORKDIR /app
COPY --chmod=755 modules/backend/nyanimedb /app
EXPOSE 8080
ENTRYPOINT ["/app/nyanimedb"]

View file

@ -1,13 +1,5 @@
FROM node:20-alpine AS builder
ARG VITE_BACKEND_API_BASE_URL
ENV VITE_BACKEND_API_BASE_URL=$VITE_BACKEND_API_BASE_URL
WORKDIR /app
COPY modules/frontend/ ./
RUN echo "VITE_BACKEND_API_BASE_URL=$VITE_BACKEND_API_BASE_URL"
RUN npm install
RUN npm run build
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY modules/frontend/dist /usr/share/nginx/html
COPY modules/frontend/nginx-default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View file

@ -1,20 +0,0 @@
FROM ubuntu:22.04
WORKDIR /app
COPY --chmod=755 nyanimedb /app
COPY templates /app/templates
EXPOSE 8080
ENTRYPOINT ["/app/nyanimedb"]
# FROM golang:1.25 AS builder
# ARG VERSION=dev
# WORKDIR /go/src/app
# COPY main.go .
# RUN go build -o main -ldflags=-X=main.version=${VERSION} main.go
# FROM debian:buster-slim
# COPY --from=builder /go/src/app/main /go/bin/main
# ENV PATH="/go/bin:${PATH}"
# CMD ["main"]

1213
api/api.gen.go Normal file

File diff suppressed because it is too large Load diff

6
api/oapi-codegen.yaml Normal file
View file

@ -0,0 +1,6 @@
package: oapi
generate:
strict-server: true
gin-server: true
models: true
output: api/api.gen.go

837
api/openapi.yaml Normal file
View file

@ -0,0 +1,837 @@
openapi: 3.1.1
info:
title: Titles, Users, Reviews, Tags, and Media API
version: 1.0.0
servers:
- url: /api/v1
paths:
/titles:
get:
summary: Get titles
parameters:
- $ref: '#/components/parameters/cursor'
- $ref: '#/components/parameters/title_sort'
- in: query
name: sort_forward
default: true
schema:
type: boolean
- in: query
name: word
schema:
type: string
- in: query
name: status
schema:
$ref: '#/components/schemas/TitleStatus'
- in: query
name: rating
schema:
type: number
format: double
- in: query
name: release_year
schema:
type: integer
format: int32
- in: query
name: release_season
schema:
$ref: '#/components/schemas/ReleaseSeason'
- in: query
name: limit
schema:
type: integer
format: int32
default: 10
- in: query
name: offset
schema:
type: integer
format: int32
default: 0
- in: query
name: fields
schema:
type: string
default: all
responses:
'200':
description: List of titles
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Title'
'204':
description: No titles found
'400':
description: Request params are not correct
'500':
description: Unknown server error
/titles/{title_id}:
get:
summary: Get title description
parameters:
- in: path
name: title_id
required: true
schema:
type: integer
format: int64
- in: query
name: fields
schema:
type: string
default: all
responses:
'200':
description: Title description
content:
application/json:
schema:
$ref: '#/components/schemas/Title'
'404':
description: Title not found
'400':
description: Request params are not correct
'500':
description: Unknown server error
'204':
description: No title found
# patch:
# summary: Update title info
# parameters:
# - in: path
# name: title_id
# required: true
# schema:
# type: string
# requestBody:
# required: true
# content:
# application/json:
# schema:
# $ref: '#/components/schemas/Title'
# responses:
# '200':
# description: Update result
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# user_json:
# $ref: '#/components/schemas/User'
# /titles/{title_id}/reviews:
# get:
# summary: Get title reviews
# parameters:
# - in: path
# name: title_id
# required: true
# schema:
# type: string
# - in: query
# name: limit
# schema:
# type: integer
# default: 10
# - in: query
# name: offset
# schema:
# type: integer
# default: 0
# responses:
# '200':
# description: List of reviews
# content:
# application/json:
# schema:
# type: array
# items:
# $ref: '#/components/schemas/Review'
# '204':
# description: No reviews found
/users/{user_id}:
get:
summary: Get user info
parameters:
- in: path
name: user_id
required: true
schema:
type: string
- in: query
name: fields
schema:
type: string
default: all
responses:
'200':
description: User info
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'404':
description: User not found
'400':
description: Request params are not correct
'500':
description: Unknown server error
# patch:
# summary: Update user
# parameters:
# - in: path
# name: user_id
# required: true
# schema:
# type: string
# requestBody:
# required: true
# content:
# application/json:
# schema:
# $ref: '#/components/schemas/User'
# responses:
# '200':
# description: Update result
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# delete:
# summary: Delete user
# parameters:
# - in: path
# name: user_id
# required: true
# schema:
# type: string
# responses:
# '200':
# description: Delete result
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# /users:
# get:
# summary: Search user
# parameters:
# - in: query
# name: query
# schema:
# type: string
# - in: query
# name: fields
# schema:
# type: string
# responses:
# '200':
# description: List of users
# content:
# application/json:
# schema:
# type: array
# items:
# $ref: '#/components/schemas/User'
# post:
# summary: Add new user
# requestBody:
# required: true
# content:
# application/json:
# schema:
# $ref: '#/components/schemas/User'
# responses:
# '200':
# description: Add result
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# user_json:
# $ref: '#/components/schemas/User'
/users/{user_id}/titles/:
get:
summary: Get user titles
parameters:
- $ref: '#/components/parameters/cursor'
- in: path
name: user_id
required: true
schema:
type: string
- in: query
name: word
schema:
type: string
- in: query
name: status
schema:
$ref: '#/components/schemas/TitleStatus'
- in: query
name: watch_status
schema:
$ref: '#/components/schemas/UserTitleStatus'
- in: query
name: rating
schema:
type: number
format: double
- in: query
name: release_year
schema:
type: integer
format: int32
- in: query
name: release_season
schema:
$ref: '#/components/schemas/ReleaseSeason'
- in: query
name: limit
schema:
type: integer
format: int32
default: 10
- in: query
name: fields
schema:
type: string
default: all
responses:
'200':
description: List of user titles
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UserTitle'
'204':
description: No titles found
'400':
description: Request params are not correct
'500':
description: Unknown server error
# post:
# summary: Add user title
# parameters:
# - in: path
# name: user_id
# required: true
# schema:
# type: string
# requestBody:
# required: true
# content:
# application/json:
# schema:
# type: object
# properties:
# title_id:
# type: string
# status:
# type: string
# responses:
# '200':
# description: Add result
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# patch:
# summary: Update user title
# parameters:
# - in: path
# name: user_id
# required: true
# schema:
# type: string
# requestBody:
# required: true
# content:
# application/json:
# schema:
# $ref: '#/components/schemas/UserTitle'
# responses:
# '200':
# description: Update result
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# delete:
# summary: Delete user title
# parameters:
# - in: path
# name: user_id
# required: true
# schema:
# type: string
# - in: query
# name: title_id
# schema:
# type: string
# responses:
# '200':
# description: Delete result
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# /users/{user_id}/reviews:
# get:
# summary: Get user reviews
# parameters:
# - in: path
# name: user_id
# required: true
# schema:
# type: string
# - in: query
# name: limit
# schema:
# type: integer
# default: 10
# - in: query
# name: offset
# schema:
# type: integer
# default: 0
# responses:
# '200':
# description: List of reviews
# content:
# application/json:
# schema:
# type: array
# items:
# $ref: '#/components/schemas/Review'
# /reviews:
# post:
# summary: Add review
# requestBody:
# required: true
# content:
# application/json:
# schema:
# $ref: '#/components/schemas/Review'
# responses:
# '200':
# description: Add result
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# /reviews/{review_id}:
# patch:
# summary: Update review
# parameters:
# - in: path
# name: review_id
# required: true
# schema:
# type: string
# requestBody:
# required: true
# content:
# application/json:
# schema:
# $ref: '#/components/schemas/Review'
# responses:
# '200':
# description: Update result
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# delete:
# summary: Delete review
# parameters:
# - in: path
# name: review_id
# required: true
# schema:
# type: string
# responses:
# '200':
# description: Delete result
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# /tags:
# get:
# summary: Get tags
# parameters:
# - in: query
# name: limit
# schema:
# type: integer
# default: 10
# - in: query
# name: offset
# schema:
# type: integer
# default: 0
# - in: query
# name: fields
# schema:
# type: string
# responses:
# '200':
# description: List of tags
# content:
# application/json:
# schema:
# type: array
# items:
# $ref: '#/components/schemas/Tag'
# /media:
# post:
# summary: Upload image
# responses:
# '200':
# description: Upload result
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# image_id:
# type: string
# get:
# summary: Get image path
# parameters:
# - in: query
# name: image_id
# required: true
# schema:
# type: string
# responses:
# '200':
# description: Image path
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# image_path:
# type: string
components:
parameters:
cursor: # example base64( {id: 1, param: 2019})
in: query
name: cursor
required: false
schema:
type: string
title_sort:
in: query
name: sort
required: false
schema:
$ref: '#/components/schemas/TitleSort'
schemas:
TitleSort:
type: string
description: Title sort order
default: id
enum:
- id
- year
- rating
- views
Image:
type: object
properties:
id:
type: integer
format: int64
storage_type:
type: string
image_path:
type: string
TitleStatus:
type: string
description: Title status
enum:
- finished
- ongoing
- planned
ReleaseSeason:
type: string
description: Title release season
enum:
- winter
- spring
- summer
- fall
UserTitleStatus:
type: string
description: User's title status
enum:
- finished
- planned
- dropped
- in-progress
Review:
type: object
additionalProperties: true
Tag:
type: object
description: "A localized tag: keys are language codes (ISO 639-1), values are tag names"
additionalProperties:
type: string
example:
en: "Shojo"
ru: "Сёдзё"
ja: "少女"
Tags:
type: array
description: "Array of localized tags"
items:
$ref: '#/components/schemas/Tag'
example:
- en: "Shojo"
ru: "Сёдзё"
ja: "少女"
- en: "Shounen"
ru: "Сёнен"
ja: "少年"
Studio:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
poster:
$ref: '#/components/schemas/Image'
description:
type: string
Title:
type: object
required:
- id
- title_names
- tags
properties:
id:
type: integer
format: int64
description: Unique title ID (primary key)
example: 1
title_names:
type: object
description: "Localized titles. Key = language (ISO 639-1), value = list of names"
additionalProperties:
type: array
items:
type: string
example: "Attack on Titan"
minItems: 1
example: ["Attack on Titan", "AoT"]
example:
en: ["Attack on Titan", "AoT"]
ru: ["Атака титанов", "Титаны"]
ja: ["進撃の巨人"]
studio:
$ref: '#/components/schemas/Studio'
tags:
$ref: '#/components/schemas/Tags'
poster:
$ref: '#/components/schemas/Image'
title_status:
$ref: '#/components/schemas/TitleStatus'
rating:
type: number
format: double
rating_count:
type: integer
format: int32
release_year:
type: integer
format: int32
release_season:
$ref: '#/components/schemas/ReleaseSeason'
episodes_aired:
type: integer
format: int32
episodes_all:
type: integer
format: int32
episodes_len:
type: object
additionalProperties:
type: number
format: double
additionalProperties: true
User:
type: object
properties:
id:
type: integer
format: int64
description: Unique user ID (primary key)
example: 1
avatar_id:
type: integer
format: int64
description: ID of the user avatar (references images table)
nullable: true
example: null
mail:
type: string
format: email
description: User email
example: "john.doe@example.com"
nickname:
type: string
description: Username (alphanumeric + _ or -)
maxLength: 16
example: "john_doe_42"
disp_name:
type: string
description: Display name
maxLength: 32
example: "John Doe"
user_desc:
type: string
description: User description
maxLength: 512
example: "Just a regular user."
creation_date:
type: string
format: date-time
description: Timestamp when the user was created
example: "2025-10-10T23:45:47.908073Z"
required:
- user_id
- nickname
# - creation_date
UserTitle:
type: object
required:
- user_id
- title_id
- status
properties:
user_id:
type: integer
format: int64
title_id:
type: integer
format: int64
status:
$ref: '#/components/schemas/UserTitleStatus'
rate:
type: integer
format: int32
review_id:
type: integer
format: int64
ctime:
type: string
format: date-time
additionalProperties: true

View file

@ -1,2 +1,7 @@
#!/bin/bash
docker buildx build --platform linux/amd64 -t meowgit.nekoea.red/nihonium/forgejo-runner:latest -f ./Dockerfiles/Dockerfile_forgejo-runner . --push
#!/usr/bin/env bash
export BACKEND_API_BASE_URL="http://127.0.0.1:8080"
docker buildx build --platform linux/amd64 -t meowgit.nekoea.red/nihonium/forgejo-runner:latest -f ./Dockerfiles/Dockerfile_forgejo-runner . --push
docker buildx build --build-arg VITE_BACKEND_API_BASE_URL=${BACKEND_API_BASE_URL} --platform linux/amd64 -t meowgit.nekoea.red/nihonium/nyanimedb-frontend:latest -f .\Dockerfiles\Dockerfile_frontend . --push
docker buildx build --platform linux/amd64 -t meowgit.nekoea.red/nihonium/nyanimedb-backend:latest -f .\Dockerfiles\Dockerfile_backend . --push

View file

@ -10,7 +10,7 @@ services:
ports:
- "${POSTGRES_PORT}:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
- postgres_data:/var/lib/postgresql
# pgadmin:
# image: dpage/pgadmin4:${PGADMIN_VERSION}
@ -32,6 +32,7 @@ services:
restart: always
environment:
LOG_LEVEL: ${LOG_LEVEL}
DATABASE_URL: ${DATABASE_URL}
ports:
- "8080:8080"
depends_on:

3
deploy/generate.sh Normal file
View file

@ -0,0 +1,3 @@
npx openapi-typescript-codegen --input ..\..\api\openapi.yaml --output ./src/api --client axios
oapi-codegen --config=api/oapi-codegen.yaml .\api\openapi.yaml
sqlc generate -f .\sql\sqlc.yaml

View file

@ -1,26 +1,37 @@
module nyanimedb-server
module nyanimedb
go 1.25.0
require (
github.com/gin-contrib/cors v1.7.6
github.com/gin-gonic/gin v1.11.0
github.com/jackc/pgx/v5 v5.7.6
github.com/oapi-codegen/runtime v1.1.2
github.com/pelletier/go-toml/v2 v2.2.4
golang.org/x/crypto v0.40.0
)
require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/bytedance/sonic v1.14.0 // indirect
github.com/bytedance/sonic/loader v0.3.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/gin-gonic/gin v1.11.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.27.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/goccy/go-yaml v1.18.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.54.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
@ -28,7 +39,6 @@ require (
github.com/ugorji/go/codec v1.3.0 // indirect
go.uber.org/mock v0.5.0 // indirect
golang.org/x/arch v0.20.0 // indirect
golang.org/x/crypto v0.40.0 // indirect
golang.org/x/mod v0.25.0 // indirect
golang.org/x/net v0.42.0 // indirect
golang.org/x/sync v0.16.0 // indirect

View file

@ -1,3 +1,7 @@
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=
github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=
@ -5,38 +9,60 @@ github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFos
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
github.com/gin-contrib/cors v1.7.6 h1:3gQ8GMzs1Ylpf70y8bMw4fVpycXIeX1ZemuSQIsnQQY=
github.com/gin-contrib/cors v1.7.6/go.mod h1:Ulcl+xN4jel9t1Ry8vqph23a60FwH9xVLd+3ykmTjOk=
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
github.com/gin-gonic/gin v1.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk=
github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=
github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.7.6 h1:rWQc5FwZSPX58r1OQmkuaNicxdmExaEz5A2DO2hUuTk=
github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/oapi-codegen/runtime v1.1.2 h1:P2+CubHq8fO4Q6fV1tqDBZHCwpVpvPg7oKiYzQgXIyI=
github.com/oapi-codegen/runtime v1.1.2/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
@ -44,6 +70,7 @@ github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQB
github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@ -52,6 +79,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=
@ -68,7 +97,6 @@ golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
@ -81,4 +109,5 @@ google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7I
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -0,0 +1,19 @@
package handlers
import (
sqlc "nyanimedb/sql"
"strconv"
)
type Server struct {
db *sqlc.Queries
}
func NewServer(db *sqlc.Queries) Server {
return Server{db: db}
}
func parseInt64(s string) (int32, error) {
i, err := strconv.ParseInt(s, 10, 64)
return int32(i), err
}

View file

@ -0,0 +1,262 @@
package handlers
import (
"context"
"encoding/json"
"fmt"
oapi "nyanimedb/api"
sqlc "nyanimedb/sql"
"github.com/jackc/pgx/v5"
log "github.com/sirupsen/logrus"
)
func Word2Sqlc(s *string) *string {
if s == nil || *s == "" {
return nil
}
return s
}
func TitleStatus2Sqlc(s *oapi.TitleStatus) (*sqlc.TitleStatusT, error) {
if s == nil {
return nil, nil
}
var t sqlc.TitleStatusT
switch *s {
case oapi.TitleStatusFinished:
t = sqlc.TitleStatusTFinished
case oapi.TitleStatusOngoing:
t = sqlc.TitleStatusTOngoing
case oapi.TitleStatusPlanned:
t = sqlc.TitleStatusTPlanned
default:
return nil, fmt.Errorf("unexpected tittle status: %s", *s)
}
return &t, nil
}
func ReleaseSeason2sqlc(s *oapi.ReleaseSeason) (*sqlc.ReleaseSeasonT, error) {
if s == nil {
return nil, nil
}
var t sqlc.ReleaseSeasonT
switch *s {
case oapi.Winter:
t = sqlc.ReleaseSeasonTWinter
case oapi.Spring:
t = sqlc.ReleaseSeasonTSpring
case oapi.Summer:
t = sqlc.ReleaseSeasonTSummer
case oapi.Fall:
t = sqlc.ReleaseSeasonTFall
default:
return nil, fmt.Errorf("unexpected release season: %s", *s)
}
return &t, nil
}
func (s Server) GetTagsByTitleId(ctx context.Context, id int64) (oapi.Tags, error) {
sqlc_title_tags, err := s.db.GetTitleTags(ctx, id)
if err != nil {
if err == pgx.ErrNoRows {
return nil, nil
}
return nil, fmt.Errorf("query GetTitleTags: %v", err)
}
oapi_tag_names := make(oapi.Tags, 1)
for _, title_tag := range sqlc_title_tags {
oapi_tag_name := make(map[string]string, 1)
err = json.Unmarshal(title_tag, &oapi_tag_name)
if err != nil {
return nil, fmt.Errorf("unmarshalling title_tag: %v", err)
}
oapi_tag_names = append(oapi_tag_names, oapi_tag_name)
}
return oapi_tag_names, nil
}
func (s Server) GetImage(ctx context.Context, id int64) (*oapi.Image, error) {
var oapi_image oapi.Image
sqlc_image, err := s.db.GetImageByID(ctx, id)
if err != nil {
if err == pgx.ErrNoRows {
return nil, nil //todo: error reference in db
}
return &oapi_image, fmt.Errorf("query GetImageByID: %v", err)
}
//can cast and dont use brain cause all this fields required in image table
oapi_image.Id = &sqlc_image.ID
oapi_image.ImagePath = &sqlc_image.ImagePath
storageTypeStr := string(sqlc_image.StorageType)
oapi_image.StorageType = &storageTypeStr
return &oapi_image, nil
}
func (s Server) GetStudio(ctx context.Context, id int64) (*oapi.Studio, error) {
var oapi_studio oapi.Studio
sqlc_studio, err := s.db.GetStudioByID(ctx, id)
if err != nil {
if err == pgx.ErrNoRows {
return nil, nil
}
return &oapi_studio, fmt.Errorf("query GetStudioByID: %v", err)
}
oapi_studio.Id = sqlc_studio.ID
oapi_studio.Name = sqlc_studio.StudioName
oapi_studio.Description = sqlc_studio.StudioDesc
if sqlc_studio.IllustID == nil {
return &oapi_studio, nil
}
oapi_illust, err := s.GetImage(ctx, *sqlc_studio.IllustID)
if err != nil {
return &oapi_studio, fmt.Errorf("GetImage: %v", err)
}
if oapi_illust != nil {
oapi_studio.Poster = oapi_illust
}
return &oapi_studio, nil
}
func (s Server) mapTitle(ctx context.Context, title sqlc.Title) (oapi.Title, error) {
var oapi_title oapi.Title
title_names := make(map[string][]string, 1)
err := json.Unmarshal(title.TitleNames, &title_names)
if err != nil {
return oapi_title, fmt.Errorf("unmarshal TitleNames: %v", err)
}
episodes_lens := make(map[string]float64, 1)
err = json.Unmarshal(title.EpisodesLen, &episodes_lens)
if err != nil {
return oapi_title, fmt.Errorf("unmarshal EpisodesLen: %v", err)
}
oapi_tag_names, err := s.GetTagsByTitleId(ctx, title.ID)
if err != nil {
return oapi_title, fmt.Errorf("GetTagsByTitleId: %v", err)
}
if oapi_tag_names != nil {
oapi_title.Tags = oapi_tag_names
}
if title.PosterID != nil {
oapi_image, err := s.GetImage(ctx, *title.PosterID)
if err != nil {
return oapi_title, fmt.Errorf("GetImage: %v", err)
}
if oapi_image != nil {
oapi_title.Poster = oapi_image
}
}
oapi_studio, err := s.GetStudio(ctx, title.StudioID)
if err != nil {
return oapi_title, fmt.Errorf("GetStudio: %v", err)
}
if oapi_studio != nil {
oapi_title.Studio = oapi_studio
}
if title.ReleaseSeason != nil {
rs := oapi.ReleaseSeason(*title.ReleaseSeason)
oapi_title.ReleaseSeason = &rs
} else {
oapi_title.ReleaseSeason = nil
}
ts := oapi.TitleStatus(title.TitleStatus)
oapi_title.TitleStatus = &ts
oapi_title.Id = title.ID
oapi_title.Rating = title.Rating
oapi_title.RatingCount = title.RatingCount
oapi_title.ReleaseYear = title.ReleaseYear
oapi_title.TitleNames = title_names
oapi_title.EpisodesAired = title.EpisodesAired
oapi_title.EpisodesAll = title.EpisodesAll
oapi_title.EpisodesLen = &episodes_lens
return oapi_title, nil
}
func (s Server) GetTitlesTitleId(ctx context.Context, request oapi.GetTitlesTitleIdRequestObject) (oapi.GetTitlesTitleIdResponseObject, error) {
var oapi_title oapi.Title
sqlc_title, err := s.db.GetTitleByID(ctx, request.TitleId)
if err != nil {
if err == pgx.ErrNoRows {
return oapi.GetTitlesTitleId204Response{}, nil
}
log.Errorf("%v", err)
return oapi.GetTitlesTitleId500Response{}, nil
}
oapi_title, err = s.mapTitle(ctx, sqlc_title)
if err != nil {
log.Errorf("%v", err)
return oapi.GetTitlesTitleId500Response{}, nil
}
return oapi.GetTitlesTitleId200JSONResponse(oapi_title), nil
}
func (s Server) GetTitles(ctx context.Context, request oapi.GetTitlesRequestObject) (oapi.GetTitlesResponseObject, error) {
opai_titles := make([]oapi.Title, 0)
word := Word2Sqlc(request.Params.Word)
status, err := TitleStatus2Sqlc(request.Params.Status)
if err != nil {
log.Errorf("%v", err)
return oapi.GetTitles400Response{}, err
}
season, err := ReleaseSeason2sqlc(request.Params.ReleaseSeason)
if err != nil {
log.Errorf("%v", err)
return oapi.GetTitles400Response{}, err
}
// param = nil means it will not be used
titles, err := s.db.SearchTitles(ctx, sqlc.SearchTitlesParams{
Word: word,
Status: status,
Rating: request.Params.Rating,
ReleaseYear: request.Params.ReleaseYear,
ReleaseSeason: season,
Offset: request.Params.Offset,
Limit: request.Params.Limit,
})
if err != nil {
log.Errorf("%v", err)
return oapi.GetTitles500Response{}, nil
}
if len(titles) == 0 {
return oapi.GetTitles204Response{}, nil
}
for _, title := range titles {
t, err := s.mapTitle(ctx, title)
if err != nil {
log.Errorf("%v", err)
return oapi.GetTitles500Response{}, nil
}
opai_titles = append(opai_titles, t)
}
return oapi.GetTitles200JSONResponse(opai_titles), nil
}

View file

@ -0,0 +1,83 @@
package handlers
import (
"context"
oapi "nyanimedb/api"
sqlc "nyanimedb/sql"
"time"
"github.com/jackc/pgx/v5"
"github.com/oapi-codegen/runtime/types"
)
// type Server struct {
// db *sqlc.Queries
// }
// func NewServer(db *sqlc.Queries) Server {
// return Server{db: db}
// }
// func parseInt64(s string) (int32, error) {
// i, err := strconv.ParseInt(s, 10, 64)
// return int32(i), err
// }
func mapUser(u sqlc.GetUserByIDRow) oapi.User {
return oapi.User{
AvatarId: u.AvatarID,
CreationDate: &u.CreationDate,
DispName: u.DispName,
Id: &u.ID,
Mail: (*types.Email)(u.Mail),
Nickname: u.Nickname,
UserDesc: u.UserDesc,
}
}
func (s Server) GetUsersUserId(ctx context.Context, req oapi.GetUsersUserIdRequestObject) (oapi.GetUsersUserIdResponseObject, error) {
userID, err := parseInt64(req.UserId)
if err != nil {
return oapi.GetUsersUserId404Response{}, nil
}
user, err := s.db.GetUserByID(context.TODO(), int64(userID))
if err != nil {
if err == pgx.ErrNoRows {
return oapi.GetUsersUserId404Response{}, nil
}
return nil, err
}
return oapi.GetUsersUserId200JSONResponse(mapUser(user)), nil
}
func (s Server) GetUsersUserIdTitles(ctx context.Context, request oapi.GetUsersUserIdTitlesRequestObject) (oapi.GetUsersUserIdTitlesResponseObject, error) {
var rate int32 = 9
var review_id int64 = 3
time := time.Date(2025, 1, 15, 10, 30, 0, 0, time.UTC)
var userTitles = []oapi.UserTitle{
{
UserId: 101,
TitleId: 2001,
Status: oapi.UserTitleStatusFinished,
Rate: &rate,
Ctime: &time,
},
{
UserId: 102,
TitleId: 2002,
Status: oapi.UserTitleStatusInProgress,
ReviewId: &review_id,
Ctime: &time,
},
{
UserId: 103,
TitleId: 2003,
Status: oapi.UserTitleStatusDropped,
Ctime: &time,
},
}
return oapi.GetUsersUserIdTitles200JSONResponse(userTitles), nil
}

119
modules/backend/main.go Normal file
View file

@ -0,0 +1,119 @@
package main
import (
"context"
"fmt"
sqlc "nyanimedb/sql"
"os"
"reflect"
"time"
oapi "nyanimedb/api"
handlers "nyanimedb/modules/backend/handlers"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v5"
"github.com/pelletier/go-toml/v2"
)
var AppConfig Config
func main() {
// if len(os.Args) != 2 {
// AppConfig.Mode = "env"
// } else {
// AppConfig.Mode = "argv"
// }
// err := InitConfig()
// if err != nil {
// log.Fatalf("Failed to init config: %v\n", err)
// }
conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
os.Exit(1)
}
defer conn.Close(context.Background())
r := gin.Default()
queries := sqlc.New(conn)
server := handlers.NewServer(queries)
// r.LoadHTMLGlob("templates/*")
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"}, // allow all origins, change to specific domains in production
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowHeaders: []string{"Origin", "Content-Type", "Accept"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
}))
oapi.RegisterHandlers(r, oapi.NewStrictHandler(
server,
// сюда можно добавить middlewares, если нужно
[]oapi.StrictMiddlewareFunc{},
))
// r.GET("/", func(c *gin.Context) {
// c.HTML(http.StatusOK, "index.html", gin.H{
// "title": "Welcome Page",
// "message": "Hello, Gin with HTML templates!",
// })
// })
// r.GET("/api", func(c *gin.Context) {
// items := []Item{
// {ID: 1, Title: "First Item", Description: "This is the description of the first item."},
// {ID: 2, Title: "Second Item", Description: "This is the description of the second item."},
// {ID: 3, Title: "Third Item", Description: "This is the description of the third item."},
// }
// c.JSON(http.StatusOK, items)
// })
r.Run(":8080")
}
func InitConfig() error {
if AppConfig.Mode == "argv" {
content, err := os.ReadFile(os.Args[1])
if err != nil {
return err
}
toml.Unmarshal(content, &AppConfig)
fmt.Printf("%+v\n", AppConfig)
return nil
} else if AppConfig.Mode == "env" {
f := reflect.ValueOf(AppConfig)
for i := 0; i < f.NumField(); i++ {
field := f.Type().Field(i)
tag := field.Tag
env_var := tag.Get("env")
fmt.Printf("Field: %v.\nEnvironment variable: %v.\n", field.Name, env_var)
if env_var != "" {
env_value, exists := os.LookupEnv(env_var)
if !exists {
return fmt.Errorf("there is no env variable %s", env_var)
}
err := setField(&AppConfig, field.Name, env_value)
if err != nil {
return fmt.Errorf("failed to set config field %s: %v", field.Name, err)
}
}
}
return nil
} else {
return fmt.Errorf("incorrect config mode")
}
}

208
modules/backend/queries.sql Normal file
View file

@ -0,0 +1,208 @@
-- name: GetImageByID :one
SELECT id, storage_type, image_path
FROM images
WHERE id = sqlc.arg('illust_id')::bigint;
-- name: CreateImage :one
INSERT INTO images (storage_type, image_path)
VALUES ($1, $2)
RETURNING id, storage_type, image_path;
-- name: GetUserByID :one
SELECT id, avatar_id, mail, nickname, disp_name, user_desc, creation_date
FROM users
WHERE id = $1;
-- name: GetStudioByID :one
SELECT *
FROM studios
WHERE id = sqlc.arg('studio_id')::bigint;
-- name: InsertStudio :one
INSERT INTO studios (studio_name, illust_id, studio_desc)
VALUES (
sqlc.arg('studio_name')::text,
sqlc.narg('illust_id')::bigint,
sqlc.narg('studio_desc')::text)
RETURNING id, studio_name, illust_id, studio_desc;
-- name: GetTitleTags :many
SELECT
tag_names
FROM tags as g
JOIN title_tags as t ON(t.tag_id = g.id)
WHERE t.title_id = sqlc.arg('title_id')::bigint;
-- name: InsertTitleTags :one
INSERT INTO title_tags (title_id, tag_id)
VALUES (
sqlc.arg('title_id')::bigint,
sqlc.arg('tag_id')::bigint)
RETURNING title_id, tag_id;
-- name: InsertTag :one
INSERT INTO tags (tag_names)
VALUES (
sqlc.arg('tag_names')::jsonb)
RETURNING id, tag_names;
-- -- name: ListUsers :many
-- SELECT user_id, avatar_id, passhash, mail, nickname, disp_name, user_desc, creation_date
-- FROM users
-- ORDER BY user_id
-- LIMIT $1 OFFSET $2;
-- -- name: CreateUser :one
-- INSERT INTO users (avatar_id, passhash, mail, nickname, disp_name, user_desc, creation_date)
-- VALUES ($1, $2, $3, $4, $5, $6, $7)
-- RETURNING user_id, avatar_id, nickname, disp_name, user_desc, creation_date;
-- -- name: UpdateUser :one
-- UPDATE users
-- SET
-- avatar_id = COALESCE(sqlc.narg('avatar_id'), avatar_id),
-- disp_name = COALESCE(sqlc.narg('disp_name'), disp_name),
-- user_desc = COALESCE(sqlc.narg('user_desc'), user_desc),
-- passhash = COALESCE(sqlc.narg('passhash'), passhash)
-- WHERE user_id = sqlc.arg('user_id')
-- RETURNING user_id, avatar_id, nickname, disp_name, user_desc, creation_date;
-- -- name: DeleteUser :exec
-- DELETE FROM users
-- WHERE user_id = $1;
-- name: GetTitleByID :one
SELECT *
FROM titles
WHERE id = sqlc.arg('title_id')::bigint;
-- name: SearchTitles :many
SELECT
*
FROM titles
WHERE
CASE
WHEN sqlc.narg('word')::text IS NOT NULL THEN
(
SELECT bool_and(
EXISTS (
SELECT 1
FROM jsonb_each_text(title_names) AS t(key, val)
WHERE val ILIKE pattern
)
)
FROM unnest(
ARRAY(
SELECT '%' || trim(w) || '%'
FROM unnest(string_to_array(sqlc.narg('word')::text, ' ')) AS w
WHERE trim(w) <> ''
)
) AS pattern
)
ELSE true
END
AND (sqlc.narg('status')::title_status_t IS NULL OR title_status = sqlc.narg('status')::title_status_t)
AND (sqlc.narg('rating')::float IS NULL OR rating >= sqlc.narg('rating')::float)
AND (sqlc.narg('release_year')::int IS NULL OR release_year = sqlc.narg('release_year')::int)
AND (sqlc.narg('release_season')::release_season_t IS NULL OR release_season = sqlc.narg('release_season')::release_season_t)
LIMIT COALESCE(sqlc.narg('limit')::int, 100) -- 100 is default limit
OFFSET sqlc.narg('offset')::int;
-- -- name: ListTitles :many
-- SELECT title_id, title_names, studio_id, poster_id, signal_ids,
-- title_status, rating, rating_count, release_year, release_season,
-- season, episodes_aired, episodes_all, episodes_len
-- FROM titles
-- ORDER BY title_id
-- LIMIT $1 OFFSET $2;
-- -- name: UpdateTitle :one
-- UPDATE titles
-- SET
-- title_names = COALESCE(sqlc.narg('title_names'), title_names),
-- studio_id = COALESCE(sqlc.narg('studio_id'), studio_id),
-- poster_id = COALESCE(sqlc.narg('poster_id'), poster_id),
-- signal_ids = COALESCE(sqlc.narg('signal_ids'), signal_ids),
-- title_status = COALESCE(sqlc.narg('title_status'), title_status),
-- release_year = COALESCE(sqlc.narg('release_year'), release_year),
-- release_season = COALESCE(sqlc.narg('release_season'), release_season),
-- episodes_aired = COALESCE(sqlc.narg('episodes_aired'), episodes_aired),
-- episodes_all = COALESCE(sqlc.narg('episodes_all'), episodes_all),
-- episodes_len = COALESCE(sqlc.narg('episodes_len'), episodes_len)
-- WHERE title_id = sqlc.arg('title_id')
-- RETURNING *;
-- name: GetReviewByID :one
SELECT *
FROM reviews
WHERE review_id = sqlc.arg('review_id')::bigint;
-- -- name: CreateReview :one
-- INSERT INTO reviews (user_id, title_id, image_ids, review_text, creation_date)
-- VALUES ($1, $2, $3, $4, $5)
-- RETURNING review_id, user_id, title_id, image_ids, review_text, creation_date;
-- -- name: UpdateReview :one
-- UPDATE reviews
-- SET
-- image_ids = COALESCE(sqlc.narg('image_ids'), image_ids),
-- review_text = COALESCE(sqlc.narg('review_text'), review_text)
-- WHERE review_id = sqlc.arg('review_id')
-- RETURNING *;
-- -- name: DeleteReview :exec
-- DELETE FROM reviews
-- WHERE review_id = $1;
-- name: ListReviewsByTitle :many
-- SELECT review_id, user_id, title_id, image_ids, review_text, creation_date
-- FROM reviews
-- WHERE title_id = $1
-- ORDER BY creation_date DESC
-- LIMIT $2 OFFSET $3;
-- -- name: ListReviewsByUser :many
-- SELECT review_id, user_id, title_id, image_ids, review_text, creation_date
-- FROM reviews
-- WHERE user_id = $1
-- ORDER BY creation_date DESC
-- LIMIT $2 OFFSET $3;
-- -- name: GetUserTitle :one
-- SELECT usertitle_id, user_id, title_id, status, rate, review_id
-- FROM usertitles
-- WHERE user_id = $1 AND title_id = $2;
-- -- name: ListUserTitles :many
-- SELECT usertitle_id, user_id, title_id, status, rate, review_id
-- FROM usertitles
-- WHERE user_id = $1
-- ORDER BY usertitle_id
-- LIMIT $2 OFFSET $3;
-- -- name: CreateUserTitle :one
-- INSERT INTO usertitles (user_id, title_id, status, rate, review_id)
-- VALUES ($1, $2, $3, $4, $5)
-- RETURNING usertitle_id, user_id, title_id, status, rate, review_id;
-- -- name: UpdateUserTitle :one
-- UPDATE usertitles
-- SET
-- status = COALESCE(sqlc.narg('status'), status),
-- rate = COALESCE(sqlc.narg('rate'), rate),
-- review_id = COALESCE(sqlc.narg('review_id'), review_id)
-- WHERE user_id = $1 AND title_id = $2
-- RETURNING *;
-- -- name: DeleteUserTitle :exec
-- DELETE FROM usertitles
-- WHERE user_id = $1 AND ($2::int IS NULL OR title_id = $2);
-- -- name: ListTags :many
-- SELECT tag_id, tag_names
-- FROM tags
-- ORDER BY tag_id
-- LIMIT $1 OFFSET $2;

12
modules/backend/types.go Normal file
View file

@ -0,0 +1,12 @@
package main
type Config struct {
Mode string
LogLevel string `toml:"LogLevel" env:"LOG_LEVEL"`
}
type Item struct {
ID int `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
}

View file

@ -0,0 +1,29 @@
server {
listen 80;
listen [::]:80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api/v1/ {
rewrite ^/api/v1/(.*)$ /$1 break;
proxy_pass http://nyanimedb-backend:8080/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

File diff suppressed because it is too large Load diff

View file

@ -10,9 +10,13 @@
"preview": "vite preview"
},
"dependencies": {
"@heroicons/react": "^2.2.0",
"@tailwindcss/vite": "^4.1.17",
"axios": "^1.12.2",
"react": "^19.1.1",
"react-dom": "^19.1.1"
"react-dom": "^19.1.1",
"react-router-dom": "^7.9.4",
"tailwindcss": "^4.1.17"
},
"devDependencies": {
"@eslint/js": "^9.36.0",
@ -24,6 +28,7 @@
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.22",
"globals": "^16.4.0",
"openapi-typescript-codegen": "^0.29.0",
"typescript": "~5.9.3",
"typescript-eslint": "^8.45.0",
"vite": "^7.1.7"

View file

@ -1,38 +1,17 @@
import React, { useEffect, useState } from "react";
import { fetchItems } from "./services/api";
import type { Item } from "./services/api";
import ItemTemplate from "./components/ItemTemplate";
import React from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import UserPage from "./pages/UserPage/UserPage";
import TitlesPage from "./pages/TitlesPage/TitlesPage";
const App: React.FC = () => {
const [items, setItems] = useState<Item[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const getData = async () => {
try {
const data = await fetchItems();
setItems(data);
} catch (err) {
setError("Failed to fetch items.");
} finally {
setLoading(false);
}
};
getData();
}, []);
if (loading) return <div>Loading...</div>;
if (error) return <div>{error}</div>;
return (
<div style={{ padding: "2rem" }}>
<h1>Items List</h1>
{items.map((item) => (
<ItemTemplate key={item.id} item={item} />
))}
</div>
<Router>
<Routes>
<Route path="/users/:id" element={<UserPage />} />
<Route path="/titles" element={<TitlesPage />} />
</Routes>
</Router>
);
};
export default App;
export default App;

View file

@ -0,0 +1,25 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ApiRequestOptions } from './ApiRequestOptions';
import type { ApiResult } from './ApiResult';
export class ApiError extends Error {
public readonly url: string;
public readonly status: number;
public readonly statusText: string;
public readonly body: any;
public readonly request: ApiRequestOptions;
constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
super(message);
this.name = 'ApiError';
this.url = response.url;
this.status = response.status;
this.statusText = response.statusText;
this.body = response.body;
this.request = request;
}
}

View file

@ -0,0 +1,17 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type ApiRequestOptions = {
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
readonly url: string;
readonly path?: Record<string, any>;
readonly cookies?: Record<string, any>;
readonly headers?: Record<string, any>;
readonly query?: Record<string, any>;
readonly formData?: Record<string, any>;
readonly body?: any;
readonly mediaType?: string;
readonly responseHeader?: string;
readonly errors?: Record<number, string>;
};

View file

@ -0,0 +1,11 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type ApiResult = {
readonly url: string;
readonly ok: boolean;
readonly status: number;
readonly statusText: string;
readonly body: any;
};

View file

@ -0,0 +1,131 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export class CancelError extends Error {
constructor(message: string) {
super(message);
this.name = 'CancelError';
}
public get isCancelled(): boolean {
return true;
}
}
export interface OnCancel {
readonly isResolved: boolean;
readonly isRejected: boolean;
readonly isCancelled: boolean;
(cancelHandler: () => void): void;
}
export class CancelablePromise<T> implements Promise<T> {
#isResolved: boolean;
#isRejected: boolean;
#isCancelled: boolean;
readonly #cancelHandlers: (() => void)[];
readonly #promise: Promise<T>;
#resolve?: (value: T | PromiseLike<T>) => void;
#reject?: (reason?: any) => void;
constructor(
executor: (
resolve: (value: T | PromiseLike<T>) => void,
reject: (reason?: any) => void,
onCancel: OnCancel
) => void
) {
this.#isResolved = false;
this.#isRejected = false;
this.#isCancelled = false;
this.#cancelHandlers = [];
this.#promise = new Promise<T>((resolve, reject) => {
this.#resolve = resolve;
this.#reject = reject;
const onResolve = (value: T | PromiseLike<T>): void => {
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
return;
}
this.#isResolved = true;
if (this.#resolve) this.#resolve(value);
};
const onReject = (reason?: any): void => {
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
return;
}
this.#isRejected = true;
if (this.#reject) this.#reject(reason);
};
const onCancel = (cancelHandler: () => void): void => {
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
return;
}
this.#cancelHandlers.push(cancelHandler);
};
Object.defineProperty(onCancel, 'isResolved', {
get: (): boolean => this.#isResolved,
});
Object.defineProperty(onCancel, 'isRejected', {
get: (): boolean => this.#isRejected,
});
Object.defineProperty(onCancel, 'isCancelled', {
get: (): boolean => this.#isCancelled,
});
return executor(onResolve, onReject, onCancel as OnCancel);
});
}
get [Symbol.toStringTag]() {
return "Cancellable Promise";
}
public then<TResult1 = T, TResult2 = never>(
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
): Promise<TResult1 | TResult2> {
return this.#promise.then(onFulfilled, onRejected);
}
public catch<TResult = never>(
onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
): Promise<T | TResult> {
return this.#promise.catch(onRejected);
}
public finally(onFinally?: (() => void) | null): Promise<T> {
return this.#promise.finally(onFinally);
}
public cancel(): void {
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
return;
}
this.#isCancelled = true;
if (this.#cancelHandlers.length) {
try {
for (const cancelHandler of this.#cancelHandlers) {
cancelHandler();
}
} catch (error) {
console.warn('Cancellation threw an error', error);
return;
}
}
this.#cancelHandlers.length = 0;
if (this.#reject) this.#reject(new CancelError('Request aborted'));
}
public get isCancelled(): boolean {
return this.#isCancelled;
}
}

View file

@ -0,0 +1,32 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ApiRequestOptions } from './ApiRequestOptions';
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
type Headers = Record<string, string>;
export type OpenAPIConfig = {
BASE: string;
VERSION: string;
WITH_CREDENTIALS: boolean;
CREDENTIALS: 'include' | 'omit' | 'same-origin';
TOKEN?: string | Resolver<string> | undefined;
USERNAME?: string | Resolver<string> | undefined;
PASSWORD?: string | Resolver<string> | undefined;
HEADERS?: Headers | Resolver<Headers> | undefined;
ENCODE_PATH?: ((path: string) => string) | undefined;
};
export const OpenAPI: OpenAPIConfig = {
BASE: '/api/v1',
VERSION: '1.0.0',
WITH_CREDENTIALS: false,
CREDENTIALS: 'include',
TOKEN: undefined,
USERNAME: undefined,
PASSWORD: undefined,
HEADERS: undefined,
ENCODE_PATH: undefined,
};

View file

@ -0,0 +1,323 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import axios from 'axios';
import type { AxiosError, AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios';
import FormData from 'form-data';
import { ApiError } from './ApiError';
import type { ApiRequestOptions } from './ApiRequestOptions';
import type { ApiResult } from './ApiResult';
import { CancelablePromise } from './CancelablePromise';
import type { OnCancel } from './CancelablePromise';
import type { OpenAPIConfig } from './OpenAPI';
export const isDefined = <T>(value: T | null | undefined): value is Exclude<T, null | undefined> => {
return value !== undefined && value !== null;
};
export const isString = (value: any): value is string => {
return typeof value === 'string';
};
export const isStringWithValue = (value: any): value is string => {
return isString(value) && value !== '';
};
export const isBlob = (value: any): value is Blob => {
return (
typeof value === 'object' &&
typeof value.type === 'string' &&
typeof value.stream === 'function' &&
typeof value.arrayBuffer === 'function' &&
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
};
export const isFormData = (value: any): value is FormData => {
return value instanceof FormData;
};
export const isSuccess = (status: number): boolean => {
return status >= 200 && status < 300;
};
export const base64 = (str: string): string => {
try {
return btoa(str);
} catch (err) {
// @ts-ignore
return Buffer.from(str).toString('base64');
}
};
export const getQueryString = (params: Record<string, any>): string => {
const qs: string[] = [];
const append = (key: string, value: any) => {
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
};
const process = (key: string, value: any) => {
if (isDefined(value)) {
if (Array.isArray(value)) {
value.forEach(v => {
process(key, v);
});
} else if (typeof value === 'object') {
Object.entries(value).forEach(([k, v]) => {
process(`${key}[${k}]`, v);
});
} else {
append(key, value);
}
}
};
Object.entries(params).forEach(([key, value]) => {
process(key, value);
});
if (qs.length > 0) {
return `?${qs.join('&')}`;
}
return '';
};
const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
const encoder = config.ENCODE_PATH || encodeURI;
const path = options.url
.replace('{api-version}', config.VERSION)
.replace(/{(.*?)}/g, (substring: string, group: string) => {
if (options.path?.hasOwnProperty(group)) {
return encoder(String(options.path[group]));
}
return substring;
});
const url = `${config.BASE}${path}`;
if (options.query) {
return `${url}${getQueryString(options.query)}`;
}
return url;
};
export const getFormData = (options: ApiRequestOptions): FormData | undefined => {
if (options.formData) {
const formData = new FormData();
const process = (key: string, value: any) => {
if (isString(value) || isBlob(value)) {
formData.append(key, value);
} else {
formData.append(key, JSON.stringify(value));
}
};
Object.entries(options.formData)
.filter(([_, value]) => isDefined(value))
.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach(v => process(key, v));
} else {
process(key, value);
}
});
return formData;
}
return undefined;
};
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
export const resolve = async <T>(options: ApiRequestOptions, resolver?: T | Resolver<T>): Promise<T | undefined> => {
if (typeof resolver === 'function') {
return (resolver as Resolver<T>)(options);
}
return resolver;
};
export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions, formData?: FormData): Promise<Record<string, string>> => {
const [token, username, password, additionalHeaders] = await Promise.all([
resolve(options, config.TOKEN),
resolve(options, config.USERNAME),
resolve(options, config.PASSWORD),
resolve(options, config.HEADERS),
]);
const formHeaders = typeof formData?.getHeaders === 'function' && formData?.getHeaders() || {}
const headers = Object.entries({
Accept: 'application/json',
...additionalHeaders,
...options.headers,
...formHeaders,
})
.filter(([_, value]) => isDefined(value))
.reduce((headers, [key, value]) => ({
...headers,
[key]: String(value),
}), {} as Record<string, string>);
if (isStringWithValue(token)) {
headers['Authorization'] = `Bearer ${token}`;
}
if (isStringWithValue(username) && isStringWithValue(password)) {
const credentials = base64(`${username}:${password}`);
headers['Authorization'] = `Basic ${credentials}`;
}
if (options.body !== undefined) {
if (options.mediaType) {
headers['Content-Type'] = options.mediaType;
} else if (isBlob(options.body)) {
headers['Content-Type'] = options.body.type || 'application/octet-stream';
} else if (isString(options.body)) {
headers['Content-Type'] = 'text/plain';
} else if (!isFormData(options.body)) {
headers['Content-Type'] = 'application/json';
}
}
return headers;
};
export const getRequestBody = (options: ApiRequestOptions): any => {
if (options.body) {
return options.body;
}
return undefined;
};
export const sendRequest = async <T>(
config: OpenAPIConfig,
options: ApiRequestOptions,
url: string,
body: any,
formData: FormData | undefined,
headers: Record<string, string>,
onCancel: OnCancel,
axiosClient: AxiosInstance
): Promise<AxiosResponse<T>> => {
const source = axios.CancelToken.source();
const requestConfig: AxiosRequestConfig = {
url,
headers,
data: body ?? formData,
method: options.method,
withCredentials: config.WITH_CREDENTIALS,
withXSRFToken: config.CREDENTIALS === 'include' ? config.WITH_CREDENTIALS : false,
cancelToken: source.token,
};
onCancel(() => source.cancel('The user aborted a request.'));
try {
return await axiosClient.request(requestConfig);
} catch (error) {
const axiosError = error as AxiosError<T>;
if (axiosError.response) {
return axiosError.response;
}
throw error;
}
};
export const getResponseHeader = (response: AxiosResponse<any>, responseHeader?: string): string | undefined => {
if (responseHeader) {
const content = response.headers[responseHeader];
if (isString(content)) {
return content;
}
}
return undefined;
};
export const getResponseBody = (response: AxiosResponse<any>): any => {
if (response.status !== 204) {
return response.data;
}
return undefined;
};
export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
const errors: Record<number, string> = {
400: 'Bad Request',
401: 'Unauthorized',
403: 'Forbidden',
404: 'Not Found',
500: 'Internal Server Error',
502: 'Bad Gateway',
503: 'Service Unavailable',
...options.errors,
}
const error = errors[result.status];
if (error) {
throw new ApiError(options, result, error);
}
if (!result.ok) {
const errorStatus = result.status ?? 'unknown';
const errorStatusText = result.statusText ?? 'unknown';
const errorBody = (() => {
try {
return JSON.stringify(result.body, null, 2);
} catch (e) {
return undefined;
}
})();
throw new ApiError(options, result,
`Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`
);
}
};
/**
* Request method
* @param config The OpenAPI configuration object
* @param options The request options from the service
* @param axiosClient The axios client instance to use
* @returns CancelablePromise<T>
* @throws ApiError
*/
export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions, axiosClient: AxiosInstance = axios): CancelablePromise<T> => {
return new CancelablePromise(async (resolve, reject, onCancel) => {
try {
const url = getUrl(config, options);
const formData = getFormData(options);
const body = getRequestBody(options);
const headers = await getHeaders(config, options, formData);
if (!onCancel.isCancelled) {
const response = await sendRequest<T>(config, options, url, body, formData, headers, onCancel, axiosClient);
const responseBody = getResponseBody(response);
const responseHeader = getResponseHeader(response, options.responseHeader);
const result: ApiResult = {
url,
ok: isSuccess(response.status),
status: response.status,
statusText: response.statusText,
body: responseHeader ?? responseBody,
};
catchErrorCodes(options, result);
resolve(result.body);
}
} catch (error) {
reject(error);
}
});
};

View file

@ -0,0 +1,26 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export { ApiError } from './core/ApiError';
export { CancelablePromise, CancelError } from './core/CancelablePromise';
export { OpenAPI } from './core/OpenAPI';
export type { OpenAPIConfig } from './core/OpenAPI';
export type { cursor } from './models/cursor';
export type { CursorObj } from './models/CursorObj';
export type { Image } from './models/Image';
export type { ReleaseSeason } from './models/ReleaseSeason';
export type { Review } from './models/Review';
export type { Studio } from './models/Studio';
export type { Tag } from './models/Tag';
export type { Tags } from './models/Tags';
export type { Title } from './models/Title';
export type { title_sort } from './models/title_sort';
export type { TitleSort } from './models/TitleSort';
export type { TitleStatus } from './models/TitleStatus';
export type { User } from './models/User';
export type { UserTitle } from './models/UserTitle';
export type { UserTitleStatus } from './models/UserTitleStatus';
export { DefaultService } from './services/DefaultService';

View file

@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type CursorObj = {
id: number;
param?: string;
};

View file

@ -0,0 +1,10 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type Image = {
id?: number;
storage_type?: string;
image_path?: string;
};

View file

@ -0,0 +1,8 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
/**
* Title release season
*/
export type ReleaseSeason = 'winter' | 'spring' | 'summer' | 'fall';

View file

@ -0,0 +1,5 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type Review = Record<string, any>;

View file

@ -0,0 +1,12 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { Image } from './Image';
export type Studio = {
id: number;
name: string;
poster?: Image;
description?: string;
};

View file

@ -0,0 +1,8 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
/**
* A localized tag: keys are language codes (ISO 639-1), values are tag names
*/
export type Tag = Record<string, string>;

View file

@ -0,0 +1,9 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { Tag } from './Tag';
/**
* Array of localized tags
*/
export type Tags = Array<Tag>;

View file

@ -0,0 +1,5 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type Title = Record<string, any>;

View file

@ -0,0 +1,8 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
/**
* Title sort order
*/
export type TitleSort = 'id' | 'year' | 'rating' | 'views';

View file

@ -0,0 +1,8 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
/**
* Title status
*/
export type TitleStatus = 'finished' | 'ongoing' | 'planned';

View file

@ -0,0 +1,35 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type User = {
/**
* Unique user ID (primary key)
*/
id?: number;
/**
* ID of the user avatar (references images table)
*/
avatar_id?: number;
/**
* User email
*/
mail?: string;
/**
* Username (alphanumeric + _ or -)
*/
nickname: string;
/**
* Display name
*/
disp_name?: string;
/**
* User description
*/
user_desc?: string;
/**
* Timestamp when the user was created
*/
creation_date?: string;
};

View file

@ -0,0 +1,5 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type UserTitle = Record<string, any>;

View file

@ -0,0 +1,8 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
/**
* User's title status
*/
export type UserTitleStatus = 'finished' | 'planned' | 'dropped' | 'in-progress';

View file

@ -0,0 +1,5 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type cursor = string;

View file

@ -0,0 +1,6 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { TitleSort } from './TitleSort';
export type title_sort = TitleSort;

View file

@ -0,0 +1,178 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { CursorObj } from '../models/CursorObj';
import type { ReleaseSeason } from '../models/ReleaseSeason';
import type { Title } from '../models/Title';
import type { TitleSort } from '../models/TitleSort';
import type { TitleStatus } from '../models/TitleStatus';
import type { User } from '../models/User';
import type { UserTitle } from '../models/UserTitle';
import type { UserTitleStatus } from '../models/UserTitleStatus';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
export class DefaultService {
/**
* Get titles
* @param cursor
* @param sort
* @param sortForward
* @param word
* @param status
* @param rating
* @param releaseYear
* @param releaseSeason
* @param limit
* @param offset
* @param fields
* @returns any List of titles with cursor
* @throws ApiError
*/
public static getTitles(
cursor?: string,
sort?: TitleSort,
sortForward: boolean = true,
word?: string,
status?: TitleStatus,
rating?: number,
releaseYear?: number,
releaseSeason?: ReleaseSeason,
limit: number = 10,
offset?: number,
fields: string = 'all',
): CancelablePromise<{
/**
* List of titles
*/
data: Array<Title>;
cursor: CursorObj;
}> {
return __request(OpenAPI, {
method: 'GET',
url: '/titles',
query: {
'cursor': cursor,
'sort': sort,
'sort_forward': sortForward,
'word': word,
'status': status,
'rating': rating,
'release_year': releaseYear,
'release_season': releaseSeason,
'limit': limit,
'offset': offset,
'fields': fields,
},
errors: {
400: `Request params are not correct`,
500: `Unknown server error`,
},
});
}
/**
* Get title description
* @param titleId
* @param fields
* @returns Title Title description
* @throws ApiError
*/
public static getTitles1(
titleId: number,
fields: string = 'all',
): CancelablePromise<Title> {
return __request(OpenAPI, {
method: 'GET',
url: '/titles/{title_id}',
path: {
'title_id': titleId,
},
query: {
'fields': fields,
},
errors: {
400: `Request params are not correct`,
404: `Title not found`,
500: `Unknown server error`,
},
});
}
/**
* Get user info
* @param userId
* @param fields
* @returns User User info
* @throws ApiError
*/
public static getUsers(
userId: string,
fields: string = 'all',
): CancelablePromise<User> {
return __request(OpenAPI, {
method: 'GET',
url: '/users/{user_id}',
path: {
'user_id': userId,
},
query: {
'fields': fields,
},
errors: {
400: `Request params are not correct`,
404: `User not found`,
500: `Unknown server error`,
},
});
}
/**
* Get user titles
* @param userId
* @param cursor
* @param word
* @param status
* @param watchStatus
* @param rating
* @param releaseYear
* @param releaseSeason
* @param limit
* @param fields
* @returns UserTitle List of user titles
* @throws ApiError
*/
public static getUsersTitles(
userId: string,
cursor?: string,
word?: string,
status?: TitleStatus,
watchStatus?: UserTitleStatus,
rating?: number,
releaseYear?: number,
releaseSeason?: ReleaseSeason,
limit: number = 10,
fields: string = 'all',
): CancelablePromise<Array<UserTitle>> {
return __request(OpenAPI, {
method: 'GET',
url: '/users/{user_id}/titles/',
path: {
'user_id': userId,
},
query: {
'cursor': cursor,
'word': word,
'status': status,
'watch_status': watchStatus,
'rating': rating,
'release_year': releaseYear,
'release_season': releaseSeason,
'limit': limit,
'fields': fields,
},
errors: {
400: `Request params are not correct`,
500: `Unknown server error`,
},
});
}
}

View file

@ -0,0 +1,103 @@
import React, { useState, useEffect } from "react";
import { Squares2X2Icon, Bars3Icon } from "@heroicons/react/24/solid";
import type { CursorObj } from "../../api";
export type ListViewProps<T> = {
fetchItems: (cursor: string, limit: number) => Promise<{ items: T[]; cursor: CursorObj}>;
renderItem: (item: T, layout: "square" | "horizontal") => React.ReactNode;
pageSize?: number;
searchPlaceholder?: string;
setSearch: any;
};
export function ListView<T>({
fetchItems,
renderItem,
pageSize = 20,
searchPlaceholder = "Search...",
}: ListViewProps<T>) {
const [items, setItems] = useState<T[]>([]);
const [cursorObj, setCursorObj] = useState<CursorObj | undefined>(undefined);
const [loading, setLoading] = useState(true);
const [loadingMore, setLoadingMore] = useState(false);
const [search, setSearch] = useState("");
const [layout, setLayout] = useState<"square" | "horizontal">("horizontal");
const [error, setError] = useState<string | null>(null);
const loadItems = async (reset: boolean = false) => {
try {
if (reset) {
setLoading(true);
setCursorObj(undefined);
} else {
setLoadingMore(true);
}
const cursorStr = cursorObj ? btoa(JSON.stringify(cursorObj)) : ""
console.log("encoded cursor: " + cursorStr)
const result = await fetchItems(cursorStr, pageSize);
if (reset) setItems(result.items);
else setItems(prev => [...prev, ...result.items]);
setCursorObj(result.cursor);
setError(null);
} catch (err: any) {
console.error(err);
setError("Failed to fetch items.");
} finally {
setLoading(false);
setLoadingMore(false);
}
};
useEffect(() => {
loadItems(true);
}, [search]);
return (
<div className="w-full min-h-screen bg-gray-50 p-6 text-black flex flex-col items-center">
<div className="w-full sm:w-4/5 flex gap-4 mb-8">
<input
type="text"
placeholder={searchPlaceholder}
// value={search}
onChange={e => setSearch(e.target.value)}
className="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 text-black"
/>
<button
className="p-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition"
onClick={() =>
setLayout(prev => (prev === "square" ? "horizontal" : "square"))
}>
{layout === "square" ? <Squares2X2Icon className="w-6 h-6" /> : <Bars3Icon className="w-6 h-6" />}
</button>
</div>
{error && <div className="text-red-600 mb-6 font-medium">{error}</div>}
<div
className={`w-full sm:w-4/5 grid gap-6 ${
layout === "square" ? "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4" : "grid-cols-1"
}`}
>
{items.map(item => renderItem(item, layout))}
</div>
{cursorObj && (
<div className="mt-8 flex justify-center w-full sm:w-4/5">
<button
className="px-6 py-3 bg-blue-600 text-white font-semibold rounded-lg hover:bg-blue-700 transition disabled:opacity-50 disabled:cursor-not-allowed"
onClick={() => loadItems(false)}
disabled={loadingMore}
>
{loadingMore ? "Loading..." : "Load More"}
</button>
</div>
)}
{loading && <div className="mt-20 font-medium">Loading...</div>}
</div>
);
}

View file

@ -0,0 +1,22 @@
import type { Title } from "../../api/models/Title";
export function TitleCardHorizontal({ title }: { title: Title }) {
return (
<div style={{
display: "flex",
gap: 12,
padding: 12,
border: "1px solid #ddd",
borderRadius: 8
}}>
{title.poster?.image_path && (
<img src={title.poster.image_path} width={80} />
)}
<div>
<h3>{title.title_names["en"]}</h3>
<p>{title.release_year} · {title.release_season} · Rating: {title.rating}</p>
<p>Status: {title.title_status}</p>
</div>
</div>
);
}

View file

@ -0,0 +1,22 @@
// TitleCardSquare.tsx
import type { Title } from "../../api/models/Title";
export function TitleCardSquare({ title }: { title: Title }) {
return (
<div style={{
width: 160,
border: "1px solid #ddd",
padding: 8,
borderRadius: 8,
textAlign: "center"
}}>
{title.poster?.image_path && (
<img src={title.poster.image_path} width={140} />
)}
<div>
<h4>{title.title_names["en"]}</h4>
<small>{title.release_year} {title.rating}</small>
</div>
</div>
);
}

View file

@ -1,68 +1,8 @@
:root {
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
@import "tailwindcss";
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
html, body, #root {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
padding: 0;
width: 100%;
height: 100%;
}

View file

@ -0,0 +1,64 @@
// import React, { useEffect, useState } from "react";
// import { useParams } from "react-router-dom";
// import { DefaultService } from "../../api/services/DefaultService";
// import type { User } from "../../api/models/User";
// import styles from "./UserPage.module.css";
// const UserPage: React.FC = () => {
// const { id } = useParams<{ id: string }>();
// const [user, setUser] = useState<User | null>(null);
// const [loading, setLoading] = useState(true);
// const [error, setError] = useState<string | null>(null);
// useEffect(() => {
// if (!id) return;
// const getTitleInfo = async () => {
// try {
// const userInfo = await DefaultService.getTitle(id, "all");
// setUser(userInfo);
// } catch (err) {
// console.error(err);
// setError("Failed to fetch user info.");
// } finally {
// setLoading(false);
// }
// };
// getTitleInfo();
// }, [id]);
// if (loading) return <div className={styles.loader}>Loading...</div>;
// if (error) return <div className={styles.error}>{error}</div>;
// if (!user) return <div className={styles.error}>User not found.</div>;
// return (
// <div className={styles.container}>
// <div className={styles.card}>
// <div className={styles.avatar}>
// {user.avatar_id ? (
// <img
// src={`/images/${user.avatar_id}.png`}
// alt="User Avatar"
// className={styles.avatarImg}
// />
// ) : (
// <div className={styles.avatarPlaceholder}>
// {user.disp_name?.[0] || "U"}
// </div>
// )}
// </div>
// <div className={styles.info}>
// <h1 className={styles.name}>{user.disp_name || user.nickname}</h1>
// <p className={styles.nickname}>@{user.nickname}</p>
// {user.user_desc && <p className={styles.desc}>{user.user_desc}</p>}
// <p className={styles.created}>
// Joined: {new Date(user.creation_date).toLocaleDateString()}
// </p>
// </div>
// </div>
// </div>
// );
// };
// export default UserPage;

View file

@ -0,0 +1 @@
@import "tailwindcss";

View file

@ -0,0 +1,52 @@
import { ListView } from "../../components/ListView/ListView";
import { DefaultService } from "../../api/services/DefaultService";
import { TitleCardSquare } from "../../components/cards/TitleCardSquare";
import { TitleCardHorizontal } from "../../components/cards/TitleCardHorizontal";
import type { Title } from "../../api";
import { useState, useEffect } from "react";
const PAGE_SIZE = 20;
export default function TitlesPage() {
const [search, setSearch] = useState("");
const loadTitles = async (cursor: string, limit: number) => {
const result = await DefaultService.getTitles(
cursor,
undefined,
true,
search,
undefined,
undefined,
undefined,
undefined,
limit,
undefined,
'all'
);
return {
items: result.data ?? [],
cursor: result.cursor ?? null,
};
};
return (
<div className="w-full min-h-screen bg-gray-50 p-6 text-black flex flex-col items-center">
<h1 className="text-4xl font-bold mb-6 text-center">Titles</h1>
<ListView<Title>
pageSize={PAGE_SIZE}
fetchItems={loadTitles}
searchPlaceholder="Search titles..."
renderItem={(title, layout) =>
layout === "square"
? <TitleCardSquare title={title} />
: <TitleCardHorizontal title={title} />
}
setSearch={setSearch}
/>
</div>
);
}

View file

@ -0,0 +1,103 @@
body,
html {
width: 100%;
margin: 0;
background-color: #777;
color: #fff;
}
html,
body,
#root {
height: 100%;
}
.header {
width: 100vw;
padding: 30px 40px;
background: #f7f7f7;
display: flex;
align-items: center;
gap: 25px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
border-bottom: 1px solid #e5e5e5;
color: #000000;
}
.avatarWrapper {
width: 120px;
height: 120px;
min-width: 120px;
border-radius: 50%;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
background: #ddd;
}
.avatarImg {
width: 100%;
height: 100%;
object-fit: cover;
}
.avatarPlaceholder {
width: 100%;
height: 100%;
border-radius: 50%;
background: #ccc;
font-size: 42px;
font-weight: bold;
color: #555;
display: flex;
align-items: center;
justify-content: center;
}
.userInfo {
display: flex;
flex-direction: column;
}
.name {
font-size: 32px;
font-weight: 700;
margin: 0;
}
.nickname {
font-size: 18px;
color: #666;
margin-top: 6px;
}
.container {
max-width: 100vw;
width: 100%;
position: absolute;
top: 0%;
/* margin: 25px auto; */
/* padding: 0 20px; */
}
.content {
margin-top: 20px;
}
.desc {
font-size: 18px;
margin-bottom: 10px;
}
.created {
font-size: 16px;
color: #888;
}
.loader,
.error {
text-align: center;
margin-top: 40px;
font-size: 18px;
}

View file

@ -0,0 +1,67 @@
import React, { useEffect, useState } from "react";
import { useParams } from "react-router-dom"; // <-- import
import { DefaultService } from "../../api/services/DefaultService";
import type { User } from "../../api/models/User";
import styles from "./UserPage.module.css";
const UserPage: React.FC = () => {
const { id } = useParams<{ id: string }>(); // <-- get user id from URL
const [user, setUser] = useState<User | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (!id) return;
const getUserInfo = async () => {
try {
const userInfo = await DefaultService.getUsers(id, "all"); // <-- use dynamic id
setUser(userInfo);
} catch (err) {
console.error(err);
setError("Failed to fetch user info.");
} finally {
setLoading(false);
}
};
getUserInfo();
}, [id]);
if (loading) return <div className={styles.loader}>Loading...</div>;
if (error) return <div className={styles.error}>{error}</div>;
if (!user) return <div className={styles.error}>User not found.</div>;
return (
<div className={styles.container}>
<div className={styles.header}>
<div className={styles.avatarWrapper}>
{user.avatar_id ? (
<img
src={`/images/${user.avatar_id}.png`}
alt="User Avatar"
className={styles.avatarImg}
/>
) : (
<div className={styles.avatarPlaceholder}>
{user.disp_name?.[0] || "U"}
</div>
)}
</div>
<div className={styles.userInfo}>
<h1 className={styles.name}>{user.disp_name || user.nickname}</h1>
<p className={styles.nickname}>@{user.nickname}</p>
{/* <p className={styles.created}>
Joined: {new Date(user.creation_date).toLocaleDateString()}
</p> */}
</div>
<div className={styles.content}>
{user.user_desc && <p className={styles.desc}>{user.user_desc}</p>}
</div>
</div>
</div>
);
};
export default UserPage;

View file

@ -0,0 +1,12 @@
export interface PaginatedResult<TItem> {
items: TItem[];
nextCursor?: string;
}
export interface FetchParams {
search: string;
cursor?: string;
}
export type FetchFunction<TItem> =
(params: FetchParams) => Promise<PaginatedResult<TItem>>;

View file

@ -1,9 +1,13 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [
react(),
tailwindcss()
],
server: {
host: '127.0.0.1',
port: 8083,

View file

@ -1,78 +0,0 @@
package main
import (
"fmt"
"net/http"
"os"
"reflect"
"github.com/gin-gonic/gin"
"github.com/pelletier/go-toml/v2"
log "github.com/sirupsen/logrus"
)
var AppConfig Config
func main() {
if len(os.Args) != 2 {
AppConfig.Mode = "env"
} else {
AppConfig.Mode = "argv"
}
err := InitConfig()
if err != nil {
log.Fatalf("Failed to init config: %v\n", err)
}
r := gin.Default()
r.LoadHTMLGlob("templates/*")
r.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", gin.H{
"title": "Welcome Page",
"message": "Hello, Gin with HTML templates!",
})
})
r.Run(":8080")
}
func InitConfig() error {
if AppConfig.Mode == "argv" {
content, err := os.ReadFile(os.Args[1])
if err != nil {
return err
}
toml.Unmarshal(content, &AppConfig)
fmt.Printf("%+v\n", AppConfig)
return nil
} else if AppConfig.Mode == "env" {
f := reflect.ValueOf(AppConfig)
for i := 0; i < f.NumField(); i++ {
field := f.Type().Field(i)
tag := field.Tag
env_var := tag.Get("env")
fmt.Printf("Field: %v.\nEnvironment variable: %v.\n", field.Name, env_var)
if env_var != "" {
env_value, exists := os.LookupEnv(env_var)
if !exists {
return fmt.Errorf("there is no env variable %s", env_var)
}
err := setField(&AppConfig, field.Name, env_value)
if err != nil {
return fmt.Errorf("failed to set config field %s: %v", field.Name, err)
}
}
}
return nil
} else {
return fmt.Errorf("incorrect config mode")
}
}

View file

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ .title }}</title>
</head>
<body>
<h1>{{ .message }}</h1>
</body>
</html>

View file

@ -1,6 +0,0 @@
package main
type Config struct {
Mode string
LogLevel string `toml:"LogLevel" env:"LOG_LEVEL"`
}

32
sql/db.go Normal file
View file

@ -0,0 +1,32 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
package sqlc
import (
"context"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
type DBTX interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}
}

View file

@ -0,0 +1,20 @@
DROP TRIGGER IF EXISTS trg_update_title_rating ON usertitles;
DROP TRIGGER IF EXISTS trg_notify_new_signal ON signals;
DROP FUNCTION IF EXISTS update_title_rating();
DROP FUNCTION IF EXISTS notify_new_signal();
DROP TABLE IF EXISTS signals;
DROP TABLE IF EXISTS title_tags;
DROP TABLE IF EXISTS usertitles;
DROP TABLE IF EXISTS titles;
DROP TABLE IF EXISTS studios;
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS images;
DROP TABLE IF EXISTS tags;
DROP TABLE IF EXISTS providers;
DROP TYPE IF EXISTS release_season_t;
DROP TYPE IF EXISTS title_status_t;
DROP TYPE IF EXISTS storage_type_t;
DROP TYPE IF EXISTS usertitle_status_t;

View file

@ -0,0 +1,172 @@
-- TODO:
-- maybe jsonb constraints
-- clean unused images
CREATE TYPE usertitle_status_t AS ENUM ('finished', 'planned', 'dropped', 'in-progress');
CREATE TYPE storage_type_t AS ENUM ('local', 's3');
CREATE TYPE title_status_t AS ENUM ('finished', 'ongoing', 'planned');
CREATE TYPE release_season_t AS ENUM ('winter', 'spring', 'summer', 'fall');
CREATE TABLE providers (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
provider_name text NOT NULL,
credentials jsonb
);
CREATE TABLE tags (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
-- example: { "ru": "Сёдзё", "en": "Shojo", "jp": "少女"}
tag_names jsonb NOT NULL
);
CREATE TABLE images (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
storage_type storage_type_t NOT NULL,
image_path text UNIQUE NOT NULL
);
CREATE TABLE reviews (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
data text NOT NULL,
rating int CHECK (rating >= 0 AND rating <= 10),
user_id bigint REFERENCES users (id),
title_id bigint REFERENCES titles (id),
created_at timestamptz DEFAULT NOW()
);
CREATE TABLE review_images (
PRIMARY KEY (review_id, image_id),
review_id bigint NOT NULL REFERENCES reviews(id) ON DELETE CASCADE,
image_id bigint NOT NULL REFERENCES images(id) ON DELETE CASCADE
);
CREATE TABLE users (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
avatar_id bigint REFERENCES images (id),
passhash text NOT NULL,
mail text CHECK (mail ~ '^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+$'),
nickname text UNIQUE NOT NULL CHECK (nickname ~ '^[a-zA-Z0-9_-]{3,}$'),
disp_name text,
user_desc text,
creation_date timestamptz NOT NULL,
last_login timestamptz
);
CREATE TABLE studios (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
studio_name text NOT NULL UNIQUE,
illust_id bigint REFERENCES images (id),
studio_desc text
);
CREATE TABLE titles (
// TODO: anime type (film, season etc)
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
-- example {"ru": ["Атака титанов", "Атака Титанов"],"en": ["Attack on Titan", "AoT"],"ja": ["進撃の巨人", "しんげきのきょじん"]}
title_names jsonb NOT NULL,
studio_id bigint NOT NULL REFERENCES studios (id),
poster_id bigint REFERENCES images (id),
title_status title_status_t NOT NULL,
rating float CHECK (rating >= 0 AND rating <= 10),
rating_count int CHECK (rating_count >= 0),
release_year int CHECK (release_year >= 1900),
release_season release_season_t,
season int CHECK (season >= 0),
episodes_aired int CHECK (episodes_aired >= 0),
episodes_all int CHECK (episodes_all >= 0),
-- example { "1": "50.50", "2": "23.23"}
episodes_len jsonb,
CHECK ((episodes_aired IS NULL AND episodes_all IS NULL)
OR (episodes_aired IS NOT NULL AND episodes_all IS NOT NULL
AND episodes_aired <= episodes_all))
);
CREATE TABLE usertitles (
PRIMARY KEY (user_id, title_id),
user_id bigint NOT NULL REFERENCES users (id),
title_id bigint NOT NULL REFERENCES titles (id),
status usertitle_status_t NOT NULL,
rate int CHECK (rate > 0 AND rate <= 10),
review_id bigint REFERENCES reviews (id),
ctime timestamptz
-- // TODO: series status
);
CREATE TABLE title_tags (
PRIMARY KEY (title_id, tag_id),
title_id bigint NOT NULL REFERENCES titles (id),
tag_id bigint NOT NULL REFERENCES tags (id)
);
CREATE TABLE signals (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
title_id bigint REFERENCES titles (id),
raw_data jsonb NOT NULL,
provider_id bigint NOT NULL REFERENCES providers (id),
pending boolean NOT NULL
);
CREATE TABLE external_ids (
user_id bigint NOT NULL REFERENCES users (id),
service_id bigint REFERENCES external_services (id),
external_id text NOT NULL
);
CREATE TABLE external_services (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name text UNIQUE NOT NULL
);
-- Functions
CREATE OR REPLACE FUNCTION update_title_rating()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'INSERT') OR (TG_OP = 'UPDATE' AND NEW.rate IS DISTINCT FROM OLD.rate) THEN
UPDATE titles
SET
rating = sub.avg_rating,
rating_count = sub.rating_count
FROM (
SELECT
title_id,
AVG(rate)::float AS avg_rating,
COUNT(rate) AS rating_count
FROM usertitles
WHERE title_id = NEW.title_id AND rate IS NOT NULL
GROUP BY title_id
) AS sub
WHERE titles.id = sub.title_id;
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION notify_new_signal()
RETURNS TRIGGER AS $$
DECLARE
payload JSON;
BEGIN
payload := json_build_object(
'signal_id', NEW.id,
'title_id', NEW.title_id,
'provider_id', NEW.provider_id,
'pending', NEW.pending,
'timestamp', NOW()
);
PERFORM pg_notify('new_signal', payload::text);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Triggers
CREATE TRIGGER trg_update_title_rating
AFTER INSERT OR UPDATE OF rate ON usertitles
FOR EACH ROW
EXECUTE FUNCTION update_title_rating();
CREATE TRIGGER trg_notify_new_signal
AFTER INSERT ON signals
FOR EACH ROW
EXECUTE FUNCTION notify_new_signal();

286
sql/models.go Normal file
View file

@ -0,0 +1,286 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
package sqlc
import (
"database/sql/driver"
"fmt"
"time"
"github.com/jackc/pgx/v5/pgtype"
)
type ReleaseSeasonT string
const (
ReleaseSeasonTWinter ReleaseSeasonT = "winter"
ReleaseSeasonTSpring ReleaseSeasonT = "spring"
ReleaseSeasonTSummer ReleaseSeasonT = "summer"
ReleaseSeasonTFall ReleaseSeasonT = "fall"
)
func (e *ReleaseSeasonT) Scan(src interface{}) error {
switch s := src.(type) {
case []byte:
*e = ReleaseSeasonT(s)
case string:
*e = ReleaseSeasonT(s)
default:
return fmt.Errorf("unsupported scan type for ReleaseSeasonT: %T", src)
}
return nil
}
type NullReleaseSeasonT struct {
ReleaseSeasonT ReleaseSeasonT `json:"release_season_t"`
Valid bool `json:"valid"` // Valid is true if ReleaseSeasonT is not NULL
}
// Scan implements the Scanner interface.
func (ns *NullReleaseSeasonT) Scan(value interface{}) error {
if value == nil {
ns.ReleaseSeasonT, ns.Valid = "", false
return nil
}
ns.Valid = true
return ns.ReleaseSeasonT.Scan(value)
}
// Value implements the driver Valuer interface.
func (ns NullReleaseSeasonT) Value() (driver.Value, error) {
if !ns.Valid {
return nil, nil
}
return string(ns.ReleaseSeasonT), nil
}
type StorageTypeT string
const (
StorageTypeTLocal StorageTypeT = "local"
StorageTypeTS3 StorageTypeT = "s3"
)
func (e *StorageTypeT) Scan(src interface{}) error {
switch s := src.(type) {
case []byte:
*e = StorageTypeT(s)
case string:
*e = StorageTypeT(s)
default:
return fmt.Errorf("unsupported scan type for StorageTypeT: %T", src)
}
return nil
}
type NullStorageTypeT struct {
StorageTypeT StorageTypeT `json:"storage_type_t"`
Valid bool `json:"valid"` // Valid is true if StorageTypeT is not NULL
}
// Scan implements the Scanner interface.
func (ns *NullStorageTypeT) Scan(value interface{}) error {
if value == nil {
ns.StorageTypeT, ns.Valid = "", false
return nil
}
ns.Valid = true
return ns.StorageTypeT.Scan(value)
}
// Value implements the driver Valuer interface.
func (ns NullStorageTypeT) Value() (driver.Value, error) {
if !ns.Valid {
return nil, nil
}
return string(ns.StorageTypeT), nil
}
type TitleStatusT string
const (
TitleStatusTFinished TitleStatusT = "finished"
TitleStatusTOngoing TitleStatusT = "ongoing"
TitleStatusTPlanned TitleStatusT = "planned"
)
func (e *TitleStatusT) Scan(src interface{}) error {
switch s := src.(type) {
case []byte:
*e = TitleStatusT(s)
case string:
*e = TitleStatusT(s)
default:
return fmt.Errorf("unsupported scan type for TitleStatusT: %T", src)
}
return nil
}
type NullTitleStatusT struct {
TitleStatusT TitleStatusT `json:"title_status_t"`
Valid bool `json:"valid"` // Valid is true if TitleStatusT is not NULL
}
// Scan implements the Scanner interface.
func (ns *NullTitleStatusT) Scan(value interface{}) error {
if value == nil {
ns.TitleStatusT, ns.Valid = "", false
return nil
}
ns.Valid = true
return ns.TitleStatusT.Scan(value)
}
// Value implements the driver Valuer interface.
func (ns NullTitleStatusT) Value() (driver.Value, error) {
if !ns.Valid {
return nil, nil
}
return string(ns.TitleStatusT), nil
}
type UsertitleStatusT string
const (
UsertitleStatusTFinished UsertitleStatusT = "finished"
UsertitleStatusTPlanned UsertitleStatusT = "planned"
UsertitleStatusTDropped UsertitleStatusT = "dropped"
UsertitleStatusTInProgress UsertitleStatusT = "in-progress"
)
func (e *UsertitleStatusT) Scan(src interface{}) error {
switch s := src.(type) {
case []byte:
*e = UsertitleStatusT(s)
case string:
*e = UsertitleStatusT(s)
default:
return fmt.Errorf("unsupported scan type for UsertitleStatusT: %T", src)
}
return nil
}
type NullUsertitleStatusT struct {
UsertitleStatusT UsertitleStatusT `json:"usertitle_status_t"`
Valid bool `json:"valid"` // Valid is true if UsertitleStatusT is not NULL
}
// Scan implements the Scanner interface.
func (ns *NullUsertitleStatusT) Scan(value interface{}) error {
if value == nil {
ns.UsertitleStatusT, ns.Valid = "", false
return nil
}
ns.Valid = true
return ns.UsertitleStatusT.Scan(value)
}
// Value implements the driver Valuer interface.
func (ns NullUsertitleStatusT) Value() (driver.Value, error) {
if !ns.Valid {
return nil, nil
}
return string(ns.UsertitleStatusT), nil
}
type ExternalID struct {
UserID int64 `json:"user_id"`
ServiceID *int64 `json:"service_id"`
ExternalID string `json:"external_id"`
}
type ExternalService struct {
ID int64 `json:"id"`
Name string `json:"name"`
}
type Image struct {
ID int64 `json:"id"`
StorageType StorageTypeT `json:"storage_type"`
ImagePath string `json:"image_path"`
}
type Provider struct {
ID int64 `json:"id"`
ProviderName string `json:"provider_name"`
Credentials []byte `json:"credentials"`
}
type Review struct {
ID int64 `json:"id"`
Data string `json:"data"`
Rating *int32 `json:"rating"`
IllustID *int64 `json:"illust_id"`
UserID *int64 `json:"user_id"`
TitleID *int64 `json:"title_id"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
type ReviewImage struct {
ReviewID int64 `json:"review_id"`
ImageID int64 `json:"image_id"`
}
type Signal struct {
ID int64 `json:"id"`
TitleID *int64 `json:"title_id"`
RawData []byte `json:"raw_data"`
ProviderID int64 `json:"provider_id"`
Pending bool `json:"pending"`
}
type Studio struct {
ID int64 `json:"id"`
StudioName string `json:"studio_name"`
IllustID *int64 `json:"illust_id"`
StudioDesc *string `json:"studio_desc"`
}
type Tag struct {
ID int64 `json:"id"`
TagNames []byte `json:"tag_names"`
}
type Title struct {
ID int64 `json:"id"`
TitleNames []byte `json:"title_names"`
StudioID int64 `json:"studio_id"`
PosterID *int64 `json:"poster_id"`
TitleStatus TitleStatusT `json:"title_status"`
Rating *float64 `json:"rating"`
RatingCount *int32 `json:"rating_count"`
ReleaseYear *int32 `json:"release_year"`
ReleaseSeason *ReleaseSeasonT `json:"release_season"`
Season *int32 `json:"season"`
EpisodesAired *int32 `json:"episodes_aired"`
EpisodesAll *int32 `json:"episodes_all"`
EpisodesLen []byte `json:"episodes_len"`
}
type TitleTag struct {
TitleID int64 `json:"title_id"`
TagID int64 `json:"tag_id"`
}
type User struct {
ID int64 `json:"id"`
AvatarID *int64 `json:"avatar_id"`
Passhash string `json:"passhash"`
Mail *string `json:"mail"`
Nickname string `json:"nickname"`
DispName *string `json:"disp_name"`
UserDesc *string `json:"user_desc"`
CreationDate time.Time `json:"creation_date"`
LastLogin pgtype.Timestamptz `json:"last_login"`
}
type Usertitle struct {
UserID int64 `json:"user_id"`
TitleID int64 `json:"title_id"`
Status UsertitleStatusT `json:"status"`
Rate *int32 `json:"rate"`
ReviewText *string `json:"review_text"`
ReviewDate pgtype.Timestamptz `json:"review_date"`
}

370
sql/queries.sql.go Normal file
View file

@ -0,0 +1,370 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: queries.sql
package sqlc
import (
"context"
"time"
)
const createImage = `-- name: CreateImage :one
INSERT INTO images (storage_type, image_path)
VALUES ($1, $2)
RETURNING id, storage_type, image_path
`
type CreateImageParams struct {
StorageType StorageTypeT `json:"storage_type"`
ImagePath string `json:"image_path"`
}
func (q *Queries) CreateImage(ctx context.Context, arg CreateImageParams) (Image, error) {
row := q.db.QueryRow(ctx, createImage, arg.StorageType, arg.ImagePath)
var i Image
err := row.Scan(&i.ID, &i.StorageType, &i.ImagePath)
return i, err
}
const getImageByID = `-- name: GetImageByID :one
SELECT id, storage_type, image_path
FROM images
WHERE id = $1
`
func (q *Queries) GetImageByID(ctx context.Context, illustID int64) (Image, error) {
row := q.db.QueryRow(ctx, getImageByID, illustID)
var i Image
err := row.Scan(&i.ID, &i.StorageType, &i.ImagePath)
return i, err
}
const getReviewByID = `-- name: GetReviewByID :one
SELECT id, data, rating, illust_id, user_id, title_id, created_at
FROM reviews
WHERE review_id = $1::bigint
`
// -- name: ListTitles :many
// SELECT title_id, title_names, studio_id, poster_id, signal_ids,
//
// title_status, rating, rating_count, release_year, release_season,
// season, episodes_aired, episodes_all, episodes_len
//
// FROM titles
// ORDER BY title_id
// LIMIT $1 OFFSET $2;
// -- name: UpdateTitle :one
// UPDATE titles
// SET
//
// title_names = COALESCE(sqlc.narg('title_names'), title_names),
// studio_id = COALESCE(sqlc.narg('studio_id'), studio_id),
// poster_id = COALESCE(sqlc.narg('poster_id'), poster_id),
// signal_ids = COALESCE(sqlc.narg('signal_ids'), signal_ids),
// title_status = COALESCE(sqlc.narg('title_status'), title_status),
// release_year = COALESCE(sqlc.narg('release_year'), release_year),
// release_season = COALESCE(sqlc.narg('release_season'), release_season),
// episodes_aired = COALESCE(sqlc.narg('episodes_aired'), episodes_aired),
// episodes_all = COALESCE(sqlc.narg('episodes_all'), episodes_all),
// episodes_len = COALESCE(sqlc.narg('episodes_len'), episodes_len)
//
// WHERE title_id = sqlc.arg('title_id')
// RETURNING *;
func (q *Queries) GetReviewByID(ctx context.Context, reviewID int64) (Review, error) {
row := q.db.QueryRow(ctx, getReviewByID, reviewID)
var i Review
err := row.Scan(
&i.ID,
&i.Data,
&i.Rating,
&i.IllustID,
&i.UserID,
&i.TitleID,
&i.CreatedAt,
)
return i, err
}
const getStudioByID = `-- name: GetStudioByID :one
SELECT id, studio_name, illust_id, studio_desc
FROM studios
WHERE id = $1::bigint
`
func (q *Queries) GetStudioByID(ctx context.Context, studioID int64) (Studio, error) {
row := q.db.QueryRow(ctx, getStudioByID, studioID)
var i Studio
err := row.Scan(
&i.ID,
&i.StudioName,
&i.IllustID,
&i.StudioDesc,
)
return i, err
}
const getTitleByID = `-- name: GetTitleByID :one
SELECT id, title_names, studio_id, poster_id, title_status, rating, rating_count, release_year, release_season, season, episodes_aired, episodes_all, episodes_len
FROM titles
WHERE id = $1::bigint
`
// -- name: ListUsers :many
// SELECT user_id, avatar_id, passhash, mail, nickname, disp_name, user_desc, creation_date
// FROM users
// ORDER BY user_id
// LIMIT $1 OFFSET $2;
// -- name: CreateUser :one
// INSERT INTO users (avatar_id, passhash, mail, nickname, disp_name, user_desc, creation_date)
// VALUES ($1, $2, $3, $4, $5, $6, $7)
// RETURNING user_id, avatar_id, nickname, disp_name, user_desc, creation_date;
// -- name: UpdateUser :one
// UPDATE users
// SET
//
// avatar_id = COALESCE(sqlc.narg('avatar_id'), avatar_id),
// disp_name = COALESCE(sqlc.narg('disp_name'), disp_name),
// user_desc = COALESCE(sqlc.narg('user_desc'), user_desc),
// passhash = COALESCE(sqlc.narg('passhash'), passhash)
//
// WHERE user_id = sqlc.arg('user_id')
// RETURNING user_id, avatar_id, nickname, disp_name, user_desc, creation_date;
// -- name: DeleteUser :exec
// DELETE FROM users
// WHERE user_id = $1;
func (q *Queries) GetTitleByID(ctx context.Context, titleID int64) (Title, error) {
row := q.db.QueryRow(ctx, getTitleByID, titleID)
var i Title
err := row.Scan(
&i.ID,
&i.TitleNames,
&i.StudioID,
&i.PosterID,
&i.TitleStatus,
&i.Rating,
&i.RatingCount,
&i.ReleaseYear,
&i.ReleaseSeason,
&i.Season,
&i.EpisodesAired,
&i.EpisodesAll,
&i.EpisodesLen,
)
return i, err
}
const getTitleTags = `-- name: GetTitleTags :many
SELECT
tag_names
FROM tags as g
JOIN title_tags as t ON(t.tag_id = g.id)
WHERE t.title_id = $1::bigint
`
func (q *Queries) GetTitleTags(ctx context.Context, titleID int64) ([][]byte, error) {
rows, err := q.db.Query(ctx, getTitleTags, titleID)
if err != nil {
return nil, err
}
defer rows.Close()
var items [][]byte
for rows.Next() {
var tag_names []byte
if err := rows.Scan(&tag_names); err != nil {
return nil, err
}
items = append(items, tag_names)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getUserByID = `-- name: GetUserByID :one
SELECT id, avatar_id, mail, nickname, disp_name, user_desc, creation_date
FROM users
WHERE id = $1
`
type GetUserByIDRow struct {
ID int64 `json:"id"`
AvatarID *int64 `json:"avatar_id"`
Mail *string `json:"mail"`
Nickname string `json:"nickname"`
DispName *string `json:"disp_name"`
UserDesc *string `json:"user_desc"`
CreationDate time.Time `json:"creation_date"`
}
func (q *Queries) GetUserByID(ctx context.Context, id int64) (GetUserByIDRow, error) {
row := q.db.QueryRow(ctx, getUserByID, id)
var i GetUserByIDRow
err := row.Scan(
&i.ID,
&i.AvatarID,
&i.Mail,
&i.Nickname,
&i.DispName,
&i.UserDesc,
&i.CreationDate,
)
return i, err
}
const insertStudio = `-- name: InsertStudio :one
INSERT INTO studios (studio_name, illust_id, studio_desc)
VALUES (
$1::text,
$2::bigint,
$3::text)
RETURNING id, studio_name, illust_id, studio_desc
`
type InsertStudioParams struct {
StudioName string `json:"studio_name"`
IllustID *int64 `json:"illust_id"`
StudioDesc *string `json:"studio_desc"`
}
func (q *Queries) InsertStudio(ctx context.Context, arg InsertStudioParams) (Studio, error) {
row := q.db.QueryRow(ctx, insertStudio, arg.StudioName, arg.IllustID, arg.StudioDesc)
var i Studio
err := row.Scan(
&i.ID,
&i.StudioName,
&i.IllustID,
&i.StudioDesc,
)
return i, err
}
const insertTag = `-- name: InsertTag :one
INSERT INTO tags (tag_names)
VALUES (
$1::jsonb)
RETURNING id, tag_names
`
func (q *Queries) InsertTag(ctx context.Context, tagNames []byte) (Tag, error) {
row := q.db.QueryRow(ctx, insertTag, tagNames)
var i Tag
err := row.Scan(&i.ID, &i.TagNames)
return i, err
}
const insertTitleTags = `-- name: InsertTitleTags :one
INSERT INTO title_tags (title_id, tag_id)
VALUES (
$1::bigint,
$2::bigint)
RETURNING title_id, tag_id
`
type InsertTitleTagsParams struct {
TitleID int64 `json:"title_id"`
TagID int64 `json:"tag_id"`
}
func (q *Queries) InsertTitleTags(ctx context.Context, arg InsertTitleTagsParams) (TitleTag, error) {
row := q.db.QueryRow(ctx, insertTitleTags, arg.TitleID, arg.TagID)
var i TitleTag
err := row.Scan(&i.TitleID, &i.TagID)
return i, err
}
const searchTitles = `-- name: SearchTitles :many
SELECT
id, title_names, studio_id, poster_id, title_status, rating, rating_count, release_year, release_season, season, episodes_aired, episodes_all, episodes_len
FROM titles
WHERE
CASE
WHEN $1::text IS NOT NULL THEN
(
SELECT bool_and(
EXISTS (
SELECT 1
FROM jsonb_each_text(title_names) AS t(key, val)
WHERE val ILIKE pattern
)
)
FROM unnest(
ARRAY(
SELECT '%' || trim(w) || '%'
FROM unnest(string_to_array($1::text, ' ')) AS w
WHERE trim(w) <> ''
)
) AS pattern
)
ELSE true
END
AND ($2::title_status_t IS NULL OR title_status = $2::title_status_t)
AND ($3::float IS NULL OR rating >= $3::float)
AND ($4::int IS NULL OR release_year = $4::int)
AND ($5::release_season_t IS NULL OR release_season = $5::release_season_t)
LIMIT COALESCE($7::int, 100) -- 100 is default limit
OFFSET $6::int
`
type SearchTitlesParams struct {
Word *string `json:"word"`
Status *TitleStatusT `json:"status"`
Rating *float64 `json:"rating"`
ReleaseYear *int32 `json:"release_year"`
ReleaseSeason *ReleaseSeasonT `json:"release_season"`
Offset *int32 `json:"offset"`
Limit *int32 `json:"limit"`
}
func (q *Queries) SearchTitles(ctx context.Context, arg SearchTitlesParams) ([]Title, error) {
rows, err := q.db.Query(ctx, searchTitles,
arg.Word,
arg.Status,
arg.Rating,
arg.ReleaseYear,
arg.ReleaseSeason,
arg.Offset,
arg.Limit,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Title
for rows.Next() {
var i Title
if err := rows.Scan(
&i.ID,
&i.TitleNames,
&i.StudioID,
&i.PosterID,
&i.TitleStatus,
&i.Rating,
&i.RatingCount,
&i.ReleaseYear,
&i.ReleaseSeason,
&i.Season,
&i.EpisodesAired,
&i.EpisodesAll,
&i.EpisodesLen,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

37
sql/sqlc.yaml Normal file
View file

@ -0,0 +1,37 @@
version: "2"
sql:
- engine: "postgresql"
queries:
- "../modules/backend/queries.sql"
schema: "migrations"
gen:
go:
package: "sqlc"
out: "."
sql_package: "pgx/v5"
sql_driver: "github.com/jackc/pgx/v5"
emit_json_tags: true
emit_pointers_for_null_types: true
overrides:
- db_type: "uuid"
nullable: false
go_type:
import: "github.com/gofrs/uuid"
package: "gofrsuuid"
type: UUID
pointer: true
- db_type: "timestamptz"
nullable: false
go_type:
import: "time"
type: "Time"
- db_type: "title_status_t"
nullable: true
go_type:
pointer: true
type: "TitleStatusT"
- db_type: "release_season_t"
nullable: true
go_type:
pointer: true
type: "ReleaseSeasonT"