refact!: project structure
This commit is contained in:
parent
fd0ca4411b
commit
db53ae04e3
26 changed files with 971 additions and 6395 deletions
193
api/api.gen.go
Normal file
193
api/api.gen.go
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
// Package oapi provides primitives to interact with the openapi HTTP API.
|
||||
//
|
||||
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.0 DO NOT EDIT.
|
||||
package oapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/oapi-codegen/runtime"
|
||||
strictgin "github.com/oapi-codegen/runtime/strictmiddleware/gin"
|
||||
)
|
||||
|
||||
// Title defines model for Title.
|
||||
type Title map[string]interface{}
|
||||
|
||||
// GetTitleParams defines parameters for GetTitle.
|
||||
type GetTitleParams struct {
|
||||
Query *string `form:"query,omitempty" json:"query,omitempty"`
|
||||
Limit *int `form:"limit,omitempty" json:"limit,omitempty"`
|
||||
Offset *int `form:"offset,omitempty" json:"offset,omitempty"`
|
||||
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
|
||||
}
|
||||
|
||||
// ServerInterface represents all server handlers.
|
||||
type ServerInterface interface {
|
||||
// Get titles
|
||||
// (GET /title)
|
||||
GetTitle(c *gin.Context, params GetTitleParams)
|
||||
}
|
||||
|
||||
// ServerInterfaceWrapper converts contexts to parameters.
|
||||
type ServerInterfaceWrapper struct {
|
||||
Handler ServerInterface
|
||||
HandlerMiddlewares []MiddlewareFunc
|
||||
ErrorHandler func(*gin.Context, error, int)
|
||||
}
|
||||
|
||||
type MiddlewareFunc func(c *gin.Context)
|
||||
|
||||
// GetTitle operation middleware
|
||||
func (siw *ServerInterfaceWrapper) GetTitle(c *gin.Context) {
|
||||
|
||||
var err error
|
||||
|
||||
// Parameter object where we will unmarshal all parameters from the context
|
||||
var params GetTitleParams
|
||||
|
||||
// ------------- Optional query parameter "query" -------------
|
||||
|
||||
err = runtime.BindQueryParameter("form", true, false, "query", c.Request.URL.Query(), ¶ms.Query)
|
||||
if err != nil {
|
||||
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter query: %w", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// ------------- Optional query parameter "limit" -------------
|
||||
|
||||
err = runtime.BindQueryParameter("form", true, false, "limit", c.Request.URL.Query(), ¶ms.Limit)
|
||||
if err != nil {
|
||||
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter limit: %w", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// ------------- Optional query parameter "offset" -------------
|
||||
|
||||
err = runtime.BindQueryParameter("form", true, false, "offset", c.Request.URL.Query(), ¶ms.Offset)
|
||||
if err != nil {
|
||||
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter offset: %w", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// ------------- Optional query parameter "fields" -------------
|
||||
|
||||
err = runtime.BindQueryParameter("form", true, false, "fields", c.Request.URL.Query(), ¶ms.Fields)
|
||||
if err != nil {
|
||||
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter fields: %w", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
for _, middleware := range siw.HandlerMiddlewares {
|
||||
middleware(c)
|
||||
if c.IsAborted() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
siw.Handler.GetTitle(c, params)
|
||||
}
|
||||
|
||||
// GinServerOptions provides options for the Gin server.
|
||||
type GinServerOptions struct {
|
||||
BaseURL string
|
||||
Middlewares []MiddlewareFunc
|
||||
ErrorHandler func(*gin.Context, error, int)
|
||||
}
|
||||
|
||||
// RegisterHandlers creates http.Handler with routing matching OpenAPI spec.
|
||||
func RegisterHandlers(router gin.IRouter, si ServerInterface) {
|
||||
RegisterHandlersWithOptions(router, si, GinServerOptions{})
|
||||
}
|
||||
|
||||
// RegisterHandlersWithOptions creates http.Handler with additional options
|
||||
func RegisterHandlersWithOptions(router gin.IRouter, si ServerInterface, options GinServerOptions) {
|
||||
errorHandler := options.ErrorHandler
|
||||
if errorHandler == nil {
|
||||
errorHandler = func(c *gin.Context, err error, statusCode int) {
|
||||
c.JSON(statusCode, gin.H{"msg": err.Error()})
|
||||
}
|
||||
}
|
||||
|
||||
wrapper := ServerInterfaceWrapper{
|
||||
Handler: si,
|
||||
HandlerMiddlewares: options.Middlewares,
|
||||
ErrorHandler: errorHandler,
|
||||
}
|
||||
|
||||
router.GET(options.BaseURL+"/title", wrapper.GetTitle)
|
||||
}
|
||||
|
||||
type GetTitleRequestObject struct {
|
||||
Params GetTitleParams
|
||||
}
|
||||
|
||||
type GetTitleResponseObject interface {
|
||||
VisitGetTitleResponse(w http.ResponseWriter) error
|
||||
}
|
||||
|
||||
type GetTitle200JSONResponse []Title
|
||||
|
||||
func (response GetTitle200JSONResponse) VisitGetTitleResponse(w http.ResponseWriter) error {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(200)
|
||||
|
||||
return json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
|
||||
type GetTitle204Response struct {
|
||||
}
|
||||
|
||||
func (response GetTitle204Response) VisitGetTitleResponse(w http.ResponseWriter) error {
|
||||
w.WriteHeader(204)
|
||||
return nil
|
||||
}
|
||||
|
||||
// StrictServerInterface represents all server handlers.
|
||||
type StrictServerInterface interface {
|
||||
// Get titles
|
||||
// (GET /title)
|
||||
GetTitle(ctx context.Context, request GetTitleRequestObject) (GetTitleResponseObject, error)
|
||||
}
|
||||
|
||||
type StrictHandlerFunc = strictgin.StrictGinHandlerFunc
|
||||
type StrictMiddlewareFunc = strictgin.StrictGinMiddlewareFunc
|
||||
|
||||
func NewStrictHandler(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc) ServerInterface {
|
||||
return &strictHandler{ssi: ssi, middlewares: middlewares}
|
||||
}
|
||||
|
||||
type strictHandler struct {
|
||||
ssi StrictServerInterface
|
||||
middlewares []StrictMiddlewareFunc
|
||||
}
|
||||
|
||||
// GetTitle operation middleware
|
||||
func (sh *strictHandler) GetTitle(ctx *gin.Context, params GetTitleParams) {
|
||||
var request GetTitleRequestObject
|
||||
|
||||
request.Params = params
|
||||
|
||||
handler := func(ctx *gin.Context, request interface{}) (interface{}, error) {
|
||||
return sh.ssi.GetTitle(ctx, request.(GetTitleRequestObject))
|
||||
}
|
||||
for _, middleware := range sh.middlewares {
|
||||
handler = middleware(handler, "GetTitle")
|
||||
}
|
||||
|
||||
response, err := handler(ctx, request)
|
||||
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
ctx.Status(http.StatusInternalServerError)
|
||||
} else if validResponse, ok := response.(GetTitleResponseObject); ok {
|
||||
if err := validResponse.VisitGetTitleResponse(ctx.Writer); err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
} else if response != nil {
|
||||
ctx.Error(fmt.Errorf("unexpected response type: %T", response))
|
||||
}
|
||||
}
|
||||
1958
api/gen.go
1958
api/gen.go
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
package: api
|
||||
package: oapi
|
||||
generate:
|
||||
strict-server: true
|
||||
gin-server: true
|
||||
models: true
|
||||
output: gen.go
|
||||
output: api/api.gen.go
|
||||
950
api/openapi.yaml
950
api/openapi.yaml
|
|
@ -40,498 +40,498 @@ paths:
|
|||
'204':
|
||||
description: No titles found
|
||||
|
||||
/title/{title_id}:
|
||||
get:
|
||||
summary: Get title description
|
||||
parameters:
|
||||
- in: path
|
||||
name: title_id
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- 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
|
||||
# /title/{title_id}:
|
||||
# get:
|
||||
# summary: Get title description
|
||||
# parameters:
|
||||
# - in: path
|
||||
# name: title_id
|
||||
# required: true
|
||||
# schema:
|
||||
# type: string
|
||||
# - 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
|
||||
|
||||
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'
|
||||
# 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'
|
||||
|
||||
/title/{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
|
||||
# /title/{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
|
||||
# /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
|
||||
|
||||
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
|
||||
# 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
|
||||
# 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'
|
||||
# /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'
|
||||
# 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:
|
||||
- in: path
|
||||
name: user_id
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- in: query
|
||||
name: query
|
||||
schema:
|
||||
type: string
|
||||
- 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
|
||||
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
|
||||
# /users/{user_id}/titles:
|
||||
# get:
|
||||
# summary: Get user titles
|
||||
# parameters:
|
||||
# - in: path
|
||||
# name: user_id
|
||||
# required: true
|
||||
# schema:
|
||||
# type: string
|
||||
# - in: query
|
||||
# name: query
|
||||
# schema:
|
||||
# type: string
|
||||
# - 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
|
||||
# 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
|
||||
|
||||
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
|
||||
# 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
|
||||
# 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
|
||||
# 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'
|
||||
# /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:
|
||||
# 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
|
||||
# /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'
|
||||
# /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
|
||||
# /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
|
||||
# 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:
|
||||
schemas:
|
||||
|
|
|
|||
3
deploy/generate.sh
Normal file
3
deploy/generate.sh
Normal 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
|
||||
|
|
@ -1,16 +1,23 @@
|
|||
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.9 // indirect
|
||||
github.com/gin-contrib/cors v1.7.6 // 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
|
||||
|
|
@ -19,23 +26,18 @@ require (
|
|||
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/jackc/pgx/v5 v5.7.6 // 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-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/oapi-codegen/runtime v1.1.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
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
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
|
||||
|
|
@ -9,9 +9,8 @@ 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=
|
||||
|
|
@ -20,18 +19,20 @@ 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=
|
||||
|
|
@ -41,6 +42,8 @@ github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7Ulw
|
|||
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=
|
||||
|
|
@ -50,7 +53,6 @@ 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=
|
||||
|
|
@ -60,13 +62,12 @@ github.com/oapi-codegen/runtime v1.1.2 h1:P2+CubHq8fO4Q6fV1tqDBZHCwpVpvPg7oKiYzQ
|
|||
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=
|
||||
github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=
|
||||
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=
|
||||
|
|
@ -76,6 +77,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=
|
||||
|
|
@ -92,8 +95,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=
|
||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
|
|
@ -105,4 +106,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=
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,712 +0,0 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: query.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createImage = `-- name: CreateImage :one
|
||||
INSERT INTO images (storage_type, image_path)
|
||||
VALUES ($1, $2)
|
||||
RETURNING image_id, storage_type, image_path
|
||||
`
|
||||
|
||||
type CreateImageParams struct {
|
||||
StorageType StorageTypeT `db:"storage_type" json:"storage_type"`
|
||||
ImagePath string `db:"image_path" json:"image_path"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateImage(ctx context.Context, arg CreateImageParams) (Images, error) {
|
||||
row := q.db.QueryRow(ctx, createImage, arg.StorageType, arg.ImagePath)
|
||||
var i Images
|
||||
err := row.Scan(&i.ImageID, &i.StorageType, &i.ImagePath)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createReview = `-- 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
|
||||
`
|
||||
|
||||
type CreateReviewParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
ImageIds []int32 `db:"image_ids" json:"image_ids"`
|
||||
ReviewText string `db:"review_text" json:"review_text"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateReview(ctx context.Context, arg CreateReviewParams) (Reviews, error) {
|
||||
row := q.db.QueryRow(ctx, createReview,
|
||||
arg.UserID,
|
||||
arg.TitleID,
|
||||
arg.ImageIds,
|
||||
arg.ReviewText,
|
||||
arg.CreationDate,
|
||||
)
|
||||
var i Reviews
|
||||
err := row.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createUser = `-- 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
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
Passhash string `db:"passhash" json:"passhash"`
|
||||
Mail pgtype.Text `db:"mail" json:"mail"`
|
||||
Nickname string `db:"nickname" json:"nickname"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
type CreateUserRow struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
Nickname string `db:"nickname" json:"nickname"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, createUser,
|
||||
arg.AvatarID,
|
||||
arg.Passhash,
|
||||
arg.Mail,
|
||||
arg.Nickname,
|
||||
arg.DispName,
|
||||
arg.UserDesc,
|
||||
arg.CreationDate,
|
||||
)
|
||||
var i CreateUserRow
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.AvatarID,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createUserTitle = `-- 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
|
||||
`
|
||||
|
||||
type CreateUserTitleParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
Status UsertitleStatusT `db:"status" json:"status"`
|
||||
Rate pgtype.Int4 `db:"rate" json:"rate"`
|
||||
ReviewID pgtype.Int4 `db:"review_id" json:"review_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUserTitle(ctx context.Context, arg CreateUserTitleParams) (Usertitles, error) {
|
||||
row := q.db.QueryRow(ctx, createUserTitle,
|
||||
arg.UserID,
|
||||
arg.TitleID,
|
||||
arg.Status,
|
||||
arg.Rate,
|
||||
arg.ReviewID,
|
||||
)
|
||||
var i Usertitles
|
||||
err := row.Scan(
|
||||
&i.UsertitleID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.Status,
|
||||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteReview = `-- name: DeleteReview :exec
|
||||
DELETE FROM reviews
|
||||
WHERE review_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteReview(ctx context.Context, reviewID int32) error {
|
||||
_, err := q.db.Exec(ctx, deleteReview, reviewID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteUser = `-- name: DeleteUser :exec
|
||||
DELETE FROM users
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteUser(ctx context.Context, userID int32) error {
|
||||
_, err := q.db.Exec(ctx, deleteUser, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteUserTitle = `-- name: DeleteUserTitle :exec
|
||||
DELETE FROM usertitles
|
||||
WHERE user_id = $1 AND ($2::int IS NULL OR title_id = $2)
|
||||
`
|
||||
|
||||
type DeleteUserTitleParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
Column2 int32 `db:"column_2" json:"column_2"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteUserTitle(ctx context.Context, arg DeleteUserTitleParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteUserTitle, arg.UserID, arg.Column2)
|
||||
return err
|
||||
}
|
||||
|
||||
const getImageByID = `-- name: GetImageByID :one
|
||||
SELECT image_id, storage_type, image_path
|
||||
FROM images
|
||||
WHERE image_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetImageByID(ctx context.Context, imageID int32) (Images, error) {
|
||||
row := q.db.QueryRow(ctx, getImageByID, imageID)
|
||||
var i Images
|
||||
err := row.Scan(&i.ImageID, &i.StorageType, &i.ImagePath)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getReviewByID = `-- name: GetReviewByID :one
|
||||
SELECT review_id, user_id, title_id, image_ids, review_text, creation_date
|
||||
FROM reviews
|
||||
WHERE review_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetReviewByID(ctx context.Context, reviewID int32) (Reviews, error) {
|
||||
row := q.db.QueryRow(ctx, getReviewByID, reviewID)
|
||||
var i Reviews
|
||||
err := row.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getTitleByID = `-- name: GetTitleByID :one
|
||||
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
|
||||
WHERE title_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetTitleByID(ctx context.Context, titleID int32) (Titles, error) {
|
||||
row := q.db.QueryRow(ctx, getTitleByID, titleID)
|
||||
var i Titles
|
||||
err := row.Scan(
|
||||
&i.TitleID,
|
||||
&i.TitleNames,
|
||||
&i.StudioID,
|
||||
&i.PosterID,
|
||||
&i.SignalIds,
|
||||
&i.TitleStatus,
|
||||
&i.Rating,
|
||||
&i.RatingCount,
|
||||
&i.ReleaseYear,
|
||||
&i.ReleaseSeason,
|
||||
&i.Season,
|
||||
&i.EpisodesAired,
|
||||
&i.EpisodesAll,
|
||||
&i.EpisodesLen,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT user_id, avatar_id, passhash, mail, nickname, disp_name, user_desc, creation_date
|
||||
FROM users
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, userID int32) (Users, error) {
|
||||
row := q.db.QueryRow(ctx, getUserByID, userID)
|
||||
var i Users
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.AvatarID,
|
||||
&i.Passhash,
|
||||
&i.Mail,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserTitle = `-- name: GetUserTitle :one
|
||||
SELECT usertitle_id, user_id, title_id, status, rate, review_id
|
||||
FROM usertitles
|
||||
WHERE user_id = $1 AND title_id = $2
|
||||
`
|
||||
|
||||
type GetUserTitleParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserTitle(ctx context.Context, arg GetUserTitleParams) (Usertitles, error) {
|
||||
row := q.db.QueryRow(ctx, getUserTitle, arg.UserID, arg.TitleID)
|
||||
var i Usertitles
|
||||
err := row.Scan(
|
||||
&i.UsertitleID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.Status,
|
||||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listReviewsByTitle = `-- 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
|
||||
`
|
||||
|
||||
type ListReviewsByTitleParams struct {
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListReviewsByTitle(ctx context.Context, arg ListReviewsByTitleParams) ([]Reviews, error) {
|
||||
rows, err := q.db.Query(ctx, listReviewsByTitle, arg.TitleID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Reviews
|
||||
for rows.Next() {
|
||||
var i Reviews
|
||||
if err := rows.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listReviewsByUser = `-- 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
|
||||
`
|
||||
|
||||
type ListReviewsByUserParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListReviewsByUser(ctx context.Context, arg ListReviewsByUserParams) ([]Reviews, error) {
|
||||
rows, err := q.db.Query(ctx, listReviewsByUser, arg.UserID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Reviews
|
||||
for rows.Next() {
|
||||
var i Reviews
|
||||
if err := rows.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTags = `-- name: ListTags :many
|
||||
SELECT tag_id, tag_names
|
||||
FROM tags
|
||||
ORDER BY tag_id
|
||||
LIMIT $1 OFFSET $2
|
||||
`
|
||||
|
||||
type ListTagsParams struct {
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListTags(ctx context.Context, arg ListTagsParams) ([]Tags, error) {
|
||||
rows, err := q.db.Query(ctx, listTags, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Tags
|
||||
for rows.Next() {
|
||||
var i Tags
|
||||
if err := rows.Scan(&i.TagID, &i.TagNames); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTitles = `-- 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
|
||||
`
|
||||
|
||||
type ListTitlesParams struct {
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListTitles(ctx context.Context, arg ListTitlesParams) ([]Titles, error) {
|
||||
rows, err := q.db.Query(ctx, listTitles, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Titles
|
||||
for rows.Next() {
|
||||
var i Titles
|
||||
if err := rows.Scan(
|
||||
&i.TitleID,
|
||||
&i.TitleNames,
|
||||
&i.StudioID,
|
||||
&i.PosterID,
|
||||
&i.SignalIds,
|
||||
&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
|
||||
}
|
||||
|
||||
const listUserTitles = `-- 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
|
||||
`
|
||||
|
||||
type ListUserTitlesParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListUserTitles(ctx context.Context, arg ListUserTitlesParams) ([]Usertitles, error) {
|
||||
rows, err := q.db.Query(ctx, listUserTitles, arg.UserID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Usertitles
|
||||
for rows.Next() {
|
||||
var i Usertitles
|
||||
if err := rows.Scan(
|
||||
&i.UsertitleID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.Status,
|
||||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listUsers = `-- 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
|
||||
`
|
||||
|
||||
type ListUsersParams struct {
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListUsers(ctx context.Context, arg ListUsersParams) ([]Users, error) {
|
||||
rows, err := q.db.Query(ctx, listUsers, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Users
|
||||
for rows.Next() {
|
||||
var i Users
|
||||
if err := rows.Scan(
|
||||
&i.UserID,
|
||||
&i.AvatarID,
|
||||
&i.Passhash,
|
||||
&i.Mail,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateReview = `-- name: UpdateReview :one
|
||||
UPDATE reviews
|
||||
SET
|
||||
image_ids = COALESCE($1, image_ids),
|
||||
review_text = COALESCE($2, review_text)
|
||||
WHERE review_id = $3
|
||||
RETURNING review_id, user_id, title_id, image_ids, review_text, creation_date
|
||||
`
|
||||
|
||||
type UpdateReviewParams struct {
|
||||
ImageIds []int32 `db:"image_ids" json:"image_ids"`
|
||||
ReviewText pgtype.Text `db:"review_text" json:"review_text"`
|
||||
ReviewID int32 `db:"review_id" json:"review_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateReview(ctx context.Context, arg UpdateReviewParams) (Reviews, error) {
|
||||
row := q.db.QueryRow(ctx, updateReview, arg.ImageIds, arg.ReviewText, arg.ReviewID)
|
||||
var i Reviews
|
||||
err := row.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateTitle = `-- name: UpdateTitle :one
|
||||
UPDATE titles
|
||||
SET
|
||||
title_names = COALESCE($1, title_names),
|
||||
studio_id = COALESCE($2, studio_id),
|
||||
poster_id = COALESCE($3, poster_id),
|
||||
signal_ids = COALESCE($4, signal_ids),
|
||||
title_status = COALESCE($5, title_status),
|
||||
release_year = COALESCE($6, release_year),
|
||||
release_season = COALESCE($7, release_season),
|
||||
episodes_aired = COALESCE($8, episodes_aired),
|
||||
episodes_all = COALESCE($9, episodes_all),
|
||||
episodes_len = COALESCE($10, episodes_len)
|
||||
WHERE title_id = $11
|
||||
RETURNING 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
|
||||
`
|
||||
|
||||
type UpdateTitleParams struct {
|
||||
TitleNames []byte `db:"title_names" json:"title_names"`
|
||||
StudioID pgtype.Int4 `db:"studio_id" json:"studio_id"`
|
||||
PosterID pgtype.Int4 `db:"poster_id" json:"poster_id"`
|
||||
SignalIds []int32 `db:"signal_ids" json:"signal_ids"`
|
||||
TitleStatus NullTitleStatusT `db:"title_status" json:"title_status"`
|
||||
ReleaseYear pgtype.Int4 `db:"release_year" json:"release_year"`
|
||||
ReleaseSeason NullReleaseSeasonT `db:"release_season" json:"release_season"`
|
||||
EpisodesAired pgtype.Int4 `db:"episodes_aired" json:"episodes_aired"`
|
||||
EpisodesAll pgtype.Int4 `db:"episodes_all" json:"episodes_all"`
|
||||
EpisodesLen []byte `db:"episodes_len" json:"episodes_len"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateTitle(ctx context.Context, arg UpdateTitleParams) (Titles, error) {
|
||||
row := q.db.QueryRow(ctx, updateTitle,
|
||||
arg.TitleNames,
|
||||
arg.StudioID,
|
||||
arg.PosterID,
|
||||
arg.SignalIds,
|
||||
arg.TitleStatus,
|
||||
arg.ReleaseYear,
|
||||
arg.ReleaseSeason,
|
||||
arg.EpisodesAired,
|
||||
arg.EpisodesAll,
|
||||
arg.EpisodesLen,
|
||||
arg.TitleID,
|
||||
)
|
||||
var i Titles
|
||||
err := row.Scan(
|
||||
&i.TitleID,
|
||||
&i.TitleNames,
|
||||
&i.StudioID,
|
||||
&i.PosterID,
|
||||
&i.SignalIds,
|
||||
&i.TitleStatus,
|
||||
&i.Rating,
|
||||
&i.RatingCount,
|
||||
&i.ReleaseYear,
|
||||
&i.ReleaseSeason,
|
||||
&i.Season,
|
||||
&i.EpisodesAired,
|
||||
&i.EpisodesAll,
|
||||
&i.EpisodesLen,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUser = `-- name: UpdateUser :one
|
||||
UPDATE users
|
||||
SET
|
||||
avatar_id = COALESCE($1, avatar_id),
|
||||
disp_name = COALESCE($2, disp_name),
|
||||
user_desc = COALESCE($3, user_desc)
|
||||
WHERE user_id = $4
|
||||
RETURNING user_id, avatar_id, nickname, disp_name, user_desc, creation_date
|
||||
`
|
||||
|
||||
type UpdateUserParams struct {
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
}
|
||||
|
||||
type UpdateUserRow struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
Nickname string `db:"nickname" json:"nickname"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (UpdateUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, updateUser,
|
||||
arg.AvatarID,
|
||||
arg.DispName,
|
||||
arg.UserDesc,
|
||||
arg.UserID,
|
||||
)
|
||||
var i UpdateUserRow
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.AvatarID,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUserTitle = `-- name: UpdateUserTitle :one
|
||||
UPDATE usertitles
|
||||
SET
|
||||
status = COALESCE($3, status),
|
||||
rate = COALESCE($4, rate),
|
||||
review_id = COALESCE($5, review_id)
|
||||
WHERE user_id = $1 AND title_id = $2
|
||||
RETURNING usertitle_id, user_id, title_id, status, rate, review_id
|
||||
`
|
||||
|
||||
type UpdateUserTitleParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
Status NullUsertitleStatusT `db:"status" json:"status"`
|
||||
Rate pgtype.Int4 `db:"rate" json:"rate"`
|
||||
ReviewID pgtype.Int4 `db:"review_id" json:"review_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserTitle(ctx context.Context, arg UpdateUserTitleParams) (Usertitles, error) {
|
||||
row := q.db.QueryRow(ctx, updateUserTitle,
|
||||
arg.UserID,
|
||||
arg.TitleID,
|
||||
arg.Status,
|
||||
arg.Rate,
|
||||
arg.ReviewID,
|
||||
)
|
||||
var i Usertitles
|
||||
err := row.Scan(
|
||||
&i.UsertitleID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.Status,
|
||||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
package api
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"nyanimedb-server/db"
|
||||
"nyanimedb/modules/backend/db"
|
||||
sqlc "nyanimedb/sql"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
|
@ -13,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
type Server struct {
|
||||
db *db.Queries
|
||||
db *sqlc.Queries
|
||||
}
|
||||
|
||||
func NewServer(db *db.Queries) Server {
|
||||
|
|
@ -3,12 +3,13 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"nyanimedb-server/api"
|
||||
"nyanimedb-server/db"
|
||||
sqlc "nyanimedb/sql"
|
||||
"os"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
oapi "nyanimedb/api"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
|
@ -39,9 +40,9 @@ func main() {
|
|||
|
||||
r := gin.Default()
|
||||
|
||||
queries := db.New(conn)
|
||||
queries := sqlc.New(conn)
|
||||
|
||||
server := api.NewServer(queries)
|
||||
server := NewServer(queries)
|
||||
// r.LoadHTMLGlob("templates/*")
|
||||
|
||||
r.Use(cors.New(cors.Config{
|
||||
|
|
@ -53,10 +54,10 @@ func main() {
|
|||
MaxAge: 12 * time.Hour,
|
||||
}))
|
||||
|
||||
api.RegisterHandlers(r, api.NewStrictHandler(
|
||||
oapi.RegisterHandlers(r, oapi.NewStrictHandler(
|
||||
server,
|
||||
// сюда можно добавить middlewares, если нужно
|
||||
[]api.StrictMiddlewareFunc{},
|
||||
[]oapi.StrictMiddlewareFunc{},
|
||||
))
|
||||
// r.GET("/", func(c *gin.Context) {
|
||||
// c.HTML(http.StatusOK, "index.html", gin.H{
|
||||
|
|
|
|||
142
modules/backend/queries.sql
Normal file
142
modules/backend/queries.sql
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
-- name: GetImageByID :one
|
||||
SELECT image_id, storage_type, image_path
|
||||
FROM images
|
||||
WHERE image_id = $1;
|
||||
|
||||
-- -- name: CreateImage :one
|
||||
-- INSERT INTO images (storage_type, image_path)
|
||||
-- VALUES ($1, $2)
|
||||
-- RETURNING image_id, storage_type, image_path;
|
||||
|
||||
-- -- name: GetUserByID :one
|
||||
-- SELECT user_id, avatar_id, passhash, mail, nickname, disp_name, user_desc, creation_date
|
||||
-- FROM users
|
||||
-- WHERE user_id = $1;
|
||||
|
||||
-- -- 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 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
|
||||
-- WHERE title_id = $1;
|
||||
|
||||
-- -- 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 review_id, user_id, title_id, image_ids, review_text, creation_date
|
||||
-- FROM reviews
|
||||
-- WHERE review_id = $1;
|
||||
|
||||
-- -- 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;
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{{ .title }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ .message }}</h1>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
module tutorial.sqlc.dev/app
|
||||
|
||||
go 1.25.2
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
-- name: GetImageByID :one
|
||||
SELECT image_id, storage_type, image_path
|
||||
FROM images
|
||||
WHERE image_id = $1;
|
||||
|
||||
-- name: CreateImage :one
|
||||
INSERT INTO images (storage_type, image_path)
|
||||
VALUES ($1, $2)
|
||||
RETURNING image_id, storage_type, image_path;
|
||||
|
||||
-- name: GetUserByID :one
|
||||
SELECT user_id, avatar_id, passhash, mail, nickname, disp_name, user_desc, creation_date
|
||||
FROM users
|
||||
WHERE user_id = $1;
|
||||
|
||||
-- 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 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
|
||||
WHERE title_id = $1;
|
||||
|
||||
-- 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 review_id, user_id, title_id, image_ids, review_text, creation_date
|
||||
FROM reviews
|
||||
WHERE review_id = $1;
|
||||
|
||||
-- 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;
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
version: "2"
|
||||
sql:
|
||||
- engine: "postgresql"
|
||||
queries: "query.sql"
|
||||
schema: "scheme.sql"
|
||||
gen:
|
||||
go:
|
||||
package: "nyanimedb.backend"
|
||||
out: "sqlc"
|
||||
sql_package: "pgx/v5"
|
||||
sql_driver: "github.com/lib/pq"
|
||||
emit_db_tags: true
|
||||
emit_exact_table_names: true
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
version: "2"
|
||||
sql:
|
||||
- engine: "postgresql"
|
||||
queries: "query.sql"
|
||||
schema: "scheme.sql"
|
||||
gen:
|
||||
go:
|
||||
package: "nyanimedb_backend"
|
||||
out: "sqlc"
|
||||
sql_package: "pgx/v5"
|
||||
sql_driver: "github.com/lib/pq"
|
||||
emit_db_tags: true
|
||||
emit_exact_table_names: true
|
||||
emit_json_tags: true
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package nyanimedb_backend
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
|
@ -1,266 +0,0 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package nyanimedb_backend
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
|
||||
"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 Images struct {
|
||||
ImageID int32 `db:"image_id" json:"image_id"`
|
||||
StorageType StorageTypeT `db:"storage_type" json:"storage_type"`
|
||||
ImagePath string `db:"image_path" json:"image_path"`
|
||||
}
|
||||
|
||||
type Providers struct {
|
||||
ProviderID int32 `db:"provider_id" json:"provider_id"`
|
||||
ProviderName string `db:"provider_name" json:"provider_name"`
|
||||
}
|
||||
|
||||
type Reviews struct {
|
||||
ReviewID int32 `db:"review_id" json:"review_id"`
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
ImageIds []int32 `db:"image_ids" json:"image_ids"`
|
||||
ReviewText string `db:"review_text" json:"review_text"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
type Signals struct {
|
||||
SignalID int32 `db:"signal_id" json:"signal_id"`
|
||||
RawData []byte `db:"raw_data" json:"raw_data"`
|
||||
ProviderID int32 `db:"provider_id" json:"provider_id"`
|
||||
Dirty bool `db:"dirty" json:"dirty"`
|
||||
}
|
||||
|
||||
type Studios struct {
|
||||
StudioID int32 `db:"studio_id" json:"studio_id"`
|
||||
StudioName pgtype.Text `db:"studio_name" json:"studio_name"`
|
||||
IllustID pgtype.Int4 `db:"illust_id" json:"illust_id"`
|
||||
StudioDesc pgtype.Text `db:"studio_desc" json:"studio_desc"`
|
||||
}
|
||||
|
||||
type Tags struct {
|
||||
TagID int32 `db:"tag_id" json:"tag_id"`
|
||||
TagNames []byte `db:"tag_names" json:"tag_names"`
|
||||
}
|
||||
|
||||
type TitleTags struct {
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
TagID int32 `db:"tag_id" json:"tag_id"`
|
||||
}
|
||||
|
||||
type Titles struct {
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
TitleNames []byte `db:"title_names" json:"title_names"`
|
||||
StudioID int32 `db:"studio_id" json:"studio_id"`
|
||||
PosterID pgtype.Int4 `db:"poster_id" json:"poster_id"`
|
||||
SignalIds []int32 `db:"signal_ids" json:"signal_ids"`
|
||||
TitleStatus TitleStatusT `db:"title_status" json:"title_status"`
|
||||
Rating pgtype.Float8 `db:"rating" json:"rating"`
|
||||
RatingCount pgtype.Int4 `db:"rating_count" json:"rating_count"`
|
||||
ReleaseYear pgtype.Int4 `db:"release_year" json:"release_year"`
|
||||
ReleaseSeason NullReleaseSeasonT `db:"release_season" json:"release_season"`
|
||||
Season pgtype.Int4 `db:"season" json:"season"`
|
||||
EpisodesAired pgtype.Int4 `db:"episodes_aired" json:"episodes_aired"`
|
||||
EpisodesAll pgtype.Int4 `db:"episodes_all" json:"episodes_all"`
|
||||
EpisodesLen []byte `db:"episodes_len" json:"episodes_len"`
|
||||
}
|
||||
|
||||
type Users struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
Passhash string `db:"passhash" json:"passhash"`
|
||||
Mail pgtype.Text `db:"mail" json:"mail"`
|
||||
Nickname string `db:"nickname" json:"nickname"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
type Usertitles struct {
|
||||
UsertitleID int32 `db:"usertitle_id" json:"usertitle_id"`
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
Status UsertitleStatusT `db:"status" json:"status"`
|
||||
Rate pgtype.Int4 `db:"rate" json:"rate"`
|
||||
ReviewID pgtype.Int4 `db:"review_id" json:"review_id"`
|
||||
}
|
||||
|
|
@ -1,712 +0,0 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: query.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createImage = `-- name: CreateImage :one
|
||||
INSERT INTO images (storage_type, image_path)
|
||||
VALUES ($1, $2)
|
||||
RETURNING image_id, storage_type, image_path
|
||||
`
|
||||
|
||||
type CreateImageParams struct {
|
||||
StorageType StorageTypeT `db:"storage_type" json:"storage_type"`
|
||||
ImagePath string `db:"image_path" json:"image_path"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateImage(ctx context.Context, arg CreateImageParams) (Images, error) {
|
||||
row := q.db.QueryRow(ctx, createImage, arg.StorageType, arg.ImagePath)
|
||||
var i Images
|
||||
err := row.Scan(&i.ImageID, &i.StorageType, &i.ImagePath)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createReview = `-- 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
|
||||
`
|
||||
|
||||
type CreateReviewParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
ImageIds []int32 `db:"image_ids" json:"image_ids"`
|
||||
ReviewText string `db:"review_text" json:"review_text"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateReview(ctx context.Context, arg CreateReviewParams) (Reviews, error) {
|
||||
row := q.db.QueryRow(ctx, createReview,
|
||||
arg.UserID,
|
||||
arg.TitleID,
|
||||
arg.ImageIds,
|
||||
arg.ReviewText,
|
||||
arg.CreationDate,
|
||||
)
|
||||
var i Reviews
|
||||
err := row.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createUser = `-- 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
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
Passhash string `db:"passhash" json:"passhash"`
|
||||
Mail pgtype.Text `db:"mail" json:"mail"`
|
||||
Nickname string `db:"nickname" json:"nickname"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
type CreateUserRow struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
Nickname string `db:"nickname" json:"nickname"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, createUser,
|
||||
arg.AvatarID,
|
||||
arg.Passhash,
|
||||
arg.Mail,
|
||||
arg.Nickname,
|
||||
arg.DispName,
|
||||
arg.UserDesc,
|
||||
arg.CreationDate,
|
||||
)
|
||||
var i CreateUserRow
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.AvatarID,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createUserTitle = `-- 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
|
||||
`
|
||||
|
||||
type CreateUserTitleParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
Status UsertitleStatusT `db:"status" json:"status"`
|
||||
Rate pgtype.Int4 `db:"rate" json:"rate"`
|
||||
ReviewID pgtype.Int4 `db:"review_id" json:"review_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUserTitle(ctx context.Context, arg CreateUserTitleParams) (Usertitles, error) {
|
||||
row := q.db.QueryRow(ctx, createUserTitle,
|
||||
arg.UserID,
|
||||
arg.TitleID,
|
||||
arg.Status,
|
||||
arg.Rate,
|
||||
arg.ReviewID,
|
||||
)
|
||||
var i Usertitles
|
||||
err := row.Scan(
|
||||
&i.UsertitleID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.Status,
|
||||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteReview = `-- name: DeleteReview :exec
|
||||
DELETE FROM reviews
|
||||
WHERE review_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteReview(ctx context.Context, reviewID int32) error {
|
||||
_, err := q.db.Exec(ctx, deleteReview, reviewID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteUser = `-- name: DeleteUser :exec
|
||||
DELETE FROM users
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteUser(ctx context.Context, userID int32) error {
|
||||
_, err := q.db.Exec(ctx, deleteUser, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteUserTitle = `-- name: DeleteUserTitle :exec
|
||||
DELETE FROM usertitles
|
||||
WHERE user_id = $1 AND ($2::int IS NULL OR title_id = $2)
|
||||
`
|
||||
|
||||
type DeleteUserTitleParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
Column2 int32 `db:"column_2" json:"column_2"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteUserTitle(ctx context.Context, arg DeleteUserTitleParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteUserTitle, arg.UserID, arg.Column2)
|
||||
return err
|
||||
}
|
||||
|
||||
const getImageByID = `-- name: GetImageByID :one
|
||||
SELECT image_id, storage_type, image_path
|
||||
FROM images
|
||||
WHERE image_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetImageByID(ctx context.Context, imageID int32) (Images, error) {
|
||||
row := q.db.QueryRow(ctx, getImageByID, imageID)
|
||||
var i Images
|
||||
err := row.Scan(&i.ImageID, &i.StorageType, &i.ImagePath)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getReviewByID = `-- name: GetReviewByID :one
|
||||
SELECT review_id, user_id, title_id, image_ids, review_text, creation_date
|
||||
FROM reviews
|
||||
WHERE review_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetReviewByID(ctx context.Context, reviewID int32) (Reviews, error) {
|
||||
row := q.db.QueryRow(ctx, getReviewByID, reviewID)
|
||||
var i Reviews
|
||||
err := row.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getTitleByID = `-- name: GetTitleByID :one
|
||||
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
|
||||
WHERE title_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetTitleByID(ctx context.Context, titleID int32) (Titles, error) {
|
||||
row := q.db.QueryRow(ctx, getTitleByID, titleID)
|
||||
var i Titles
|
||||
err := row.Scan(
|
||||
&i.TitleID,
|
||||
&i.TitleNames,
|
||||
&i.StudioID,
|
||||
&i.PosterID,
|
||||
&i.SignalIds,
|
||||
&i.TitleStatus,
|
||||
&i.Rating,
|
||||
&i.RatingCount,
|
||||
&i.ReleaseYear,
|
||||
&i.ReleaseSeason,
|
||||
&i.Season,
|
||||
&i.EpisodesAired,
|
||||
&i.EpisodesAll,
|
||||
&i.EpisodesLen,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT user_id, avatar_id, passhash, mail, nickname, disp_name, user_desc, creation_date
|
||||
FROM users
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, userID int32) (Users, error) {
|
||||
row := q.db.QueryRow(ctx, getUserByID, userID)
|
||||
var i Users
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.AvatarID,
|
||||
&i.Passhash,
|
||||
&i.Mail,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserTitle = `-- name: GetUserTitle :one
|
||||
SELECT usertitle_id, user_id, title_id, status, rate, review_id
|
||||
FROM usertitles
|
||||
WHERE user_id = $1 AND title_id = $2
|
||||
`
|
||||
|
||||
type GetUserTitleParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserTitle(ctx context.Context, arg GetUserTitleParams) (Usertitles, error) {
|
||||
row := q.db.QueryRow(ctx, getUserTitle, arg.UserID, arg.TitleID)
|
||||
var i Usertitles
|
||||
err := row.Scan(
|
||||
&i.UsertitleID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.Status,
|
||||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listReviewsByTitle = `-- 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
|
||||
`
|
||||
|
||||
type ListReviewsByTitleParams struct {
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListReviewsByTitle(ctx context.Context, arg ListReviewsByTitleParams) ([]Reviews, error) {
|
||||
rows, err := q.db.Query(ctx, listReviewsByTitle, arg.TitleID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Reviews
|
||||
for rows.Next() {
|
||||
var i Reviews
|
||||
if err := rows.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listReviewsByUser = `-- 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
|
||||
`
|
||||
|
||||
type ListReviewsByUserParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListReviewsByUser(ctx context.Context, arg ListReviewsByUserParams) ([]Reviews, error) {
|
||||
rows, err := q.db.Query(ctx, listReviewsByUser, arg.UserID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Reviews
|
||||
for rows.Next() {
|
||||
var i Reviews
|
||||
if err := rows.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTags = `-- name: ListTags :many
|
||||
SELECT tag_id, tag_names
|
||||
FROM tags
|
||||
ORDER BY tag_id
|
||||
LIMIT $1 OFFSET $2
|
||||
`
|
||||
|
||||
type ListTagsParams struct {
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListTags(ctx context.Context, arg ListTagsParams) ([]Tags, error) {
|
||||
rows, err := q.db.Query(ctx, listTags, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Tags
|
||||
for rows.Next() {
|
||||
var i Tags
|
||||
if err := rows.Scan(&i.TagID, &i.TagNames); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTitles = `-- 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
|
||||
`
|
||||
|
||||
type ListTitlesParams struct {
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListTitles(ctx context.Context, arg ListTitlesParams) ([]Titles, error) {
|
||||
rows, err := q.db.Query(ctx, listTitles, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Titles
|
||||
for rows.Next() {
|
||||
var i Titles
|
||||
if err := rows.Scan(
|
||||
&i.TitleID,
|
||||
&i.TitleNames,
|
||||
&i.StudioID,
|
||||
&i.PosterID,
|
||||
&i.SignalIds,
|
||||
&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
|
||||
}
|
||||
|
||||
const listUserTitles = `-- 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
|
||||
`
|
||||
|
||||
type ListUserTitlesParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListUserTitles(ctx context.Context, arg ListUserTitlesParams) ([]Usertitles, error) {
|
||||
rows, err := q.db.Query(ctx, listUserTitles, arg.UserID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Usertitles
|
||||
for rows.Next() {
|
||||
var i Usertitles
|
||||
if err := rows.Scan(
|
||||
&i.UsertitleID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.Status,
|
||||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listUsers = `-- 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
|
||||
`
|
||||
|
||||
type ListUsersParams struct {
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListUsers(ctx context.Context, arg ListUsersParams) ([]Users, error) {
|
||||
rows, err := q.db.Query(ctx, listUsers, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Users
|
||||
for rows.Next() {
|
||||
var i Users
|
||||
if err := rows.Scan(
|
||||
&i.UserID,
|
||||
&i.AvatarID,
|
||||
&i.Passhash,
|
||||
&i.Mail,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateReview = `-- name: UpdateReview :one
|
||||
UPDATE reviews
|
||||
SET
|
||||
image_ids = COALESCE($1, image_ids),
|
||||
review_text = COALESCE($2, review_text)
|
||||
WHERE review_id = $3
|
||||
RETURNING review_id, user_id, title_id, image_ids, review_text, creation_date
|
||||
`
|
||||
|
||||
type UpdateReviewParams struct {
|
||||
ImageIds []int32 `db:"image_ids" json:"image_ids"`
|
||||
ReviewText pgtype.Text `db:"review_text" json:"review_text"`
|
||||
ReviewID int32 `db:"review_id" json:"review_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateReview(ctx context.Context, arg UpdateReviewParams) (Reviews, error) {
|
||||
row := q.db.QueryRow(ctx, updateReview, arg.ImageIds, arg.ReviewText, arg.ReviewID)
|
||||
var i Reviews
|
||||
err := row.Scan(
|
||||
&i.ReviewID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.ImageIds,
|
||||
&i.ReviewText,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateTitle = `-- name: UpdateTitle :one
|
||||
UPDATE titles
|
||||
SET
|
||||
title_names = COALESCE($1, title_names),
|
||||
studio_id = COALESCE($2, studio_id),
|
||||
poster_id = COALESCE($3, poster_id),
|
||||
signal_ids = COALESCE($4, signal_ids),
|
||||
title_status = COALESCE($5, title_status),
|
||||
release_year = COALESCE($6, release_year),
|
||||
release_season = COALESCE($7, release_season),
|
||||
episodes_aired = COALESCE($8, episodes_aired),
|
||||
episodes_all = COALESCE($9, episodes_all),
|
||||
episodes_len = COALESCE($10, episodes_len)
|
||||
WHERE title_id = $11
|
||||
RETURNING 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
|
||||
`
|
||||
|
||||
type UpdateTitleParams struct {
|
||||
TitleNames []byte `db:"title_names" json:"title_names"`
|
||||
StudioID pgtype.Int4 `db:"studio_id" json:"studio_id"`
|
||||
PosterID pgtype.Int4 `db:"poster_id" json:"poster_id"`
|
||||
SignalIds []int32 `db:"signal_ids" json:"signal_ids"`
|
||||
TitleStatus NullTitleStatusT `db:"title_status" json:"title_status"`
|
||||
ReleaseYear pgtype.Int4 `db:"release_year" json:"release_year"`
|
||||
ReleaseSeason NullReleaseSeasonT `db:"release_season" json:"release_season"`
|
||||
EpisodesAired pgtype.Int4 `db:"episodes_aired" json:"episodes_aired"`
|
||||
EpisodesAll pgtype.Int4 `db:"episodes_all" json:"episodes_all"`
|
||||
EpisodesLen []byte `db:"episodes_len" json:"episodes_len"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateTitle(ctx context.Context, arg UpdateTitleParams) (Titles, error) {
|
||||
row := q.db.QueryRow(ctx, updateTitle,
|
||||
arg.TitleNames,
|
||||
arg.StudioID,
|
||||
arg.PosterID,
|
||||
arg.SignalIds,
|
||||
arg.TitleStatus,
|
||||
arg.ReleaseYear,
|
||||
arg.ReleaseSeason,
|
||||
arg.EpisodesAired,
|
||||
arg.EpisodesAll,
|
||||
arg.EpisodesLen,
|
||||
arg.TitleID,
|
||||
)
|
||||
var i Titles
|
||||
err := row.Scan(
|
||||
&i.TitleID,
|
||||
&i.TitleNames,
|
||||
&i.StudioID,
|
||||
&i.PosterID,
|
||||
&i.SignalIds,
|
||||
&i.TitleStatus,
|
||||
&i.Rating,
|
||||
&i.RatingCount,
|
||||
&i.ReleaseYear,
|
||||
&i.ReleaseSeason,
|
||||
&i.Season,
|
||||
&i.EpisodesAired,
|
||||
&i.EpisodesAll,
|
||||
&i.EpisodesLen,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUser = `-- name: UpdateUser :one
|
||||
UPDATE users
|
||||
SET
|
||||
avatar_id = COALESCE($1, avatar_id),
|
||||
disp_name = COALESCE($2, disp_name),
|
||||
user_desc = COALESCE($3, user_desc)
|
||||
WHERE user_id = $4
|
||||
RETURNING user_id, avatar_id, nickname, disp_name, user_desc, creation_date
|
||||
`
|
||||
|
||||
type UpdateUserParams struct {
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
}
|
||||
|
||||
type UpdateUserRow struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
Nickname string `db:"nickname" json:"nickname"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (UpdateUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, updateUser,
|
||||
arg.AvatarID,
|
||||
arg.DispName,
|
||||
arg.UserDesc,
|
||||
arg.UserID,
|
||||
)
|
||||
var i UpdateUserRow
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.AvatarID,
|
||||
&i.Nickname,
|
||||
&i.DispName,
|
||||
&i.UserDesc,
|
||||
&i.CreationDate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUserTitle = `-- name: UpdateUserTitle :one
|
||||
UPDATE usertitles
|
||||
SET
|
||||
status = COALESCE($3, status),
|
||||
rate = COALESCE($4, rate),
|
||||
review_id = COALESCE($5, review_id)
|
||||
WHERE user_id = $1 AND title_id = $2
|
||||
RETURNING usertitle_id, user_id, title_id, status, rate, review_id
|
||||
`
|
||||
|
||||
type UpdateUserTitleParams struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
Status NullUsertitleStatusT `db:"status" json:"status"`
|
||||
Rate pgtype.Int4 `db:"rate" json:"rate"`
|
||||
ReviewID pgtype.Int4 `db:"review_id" json:"review_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserTitle(ctx context.Context, arg UpdateUserTitleParams) (Usertitles, error) {
|
||||
row := q.db.QueryRow(ctx, updateUserTitle,
|
||||
arg.UserID,
|
||||
arg.TitleID,
|
||||
arg.Status,
|
||||
arg.Rate,
|
||||
arg.ReviewID,
|
||||
)
|
||||
var i Usertitles
|
||||
err := row.Scan(
|
||||
&i.UsertitleID,
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
&i.Status,
|
||||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package db
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
15
sql/migrations/000001_init.down.sql
Normal file
15
sql/migrations/000001_init.down.sql
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
DROP TABLE IF EXISTS signals;
|
||||
DROP TABLE IF EXISTS title_tags;
|
||||
DROP TABLE IF EXISTS usertitles;
|
||||
DROP TABLE IF EXISTS reviews;
|
||||
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;
|
||||
|
|
@ -2,8 +2,6 @@
|
|||
-- title table triggers
|
||||
-- maybe jsonb constraints
|
||||
-- actions (delete)
|
||||
BEGIN;
|
||||
|
||||
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');
|
||||
|
|
@ -12,6 +10,7 @@ CREATE TYPE release_season_t AS ENUM ('winter', 'spring', 'summer', 'fall');
|
|||
CREATE TABLE providers (
|
||||
provider_id serial PRIMARY KEY,
|
||||
provider_name varchar(64) NOT NULL
|
||||
-- token
|
||||
);
|
||||
|
||||
CREATE TABLE tags (
|
||||
|
|
@ -19,6 +18,8 @@ CREATE TABLE tags (
|
|||
tag_names jsonb NOT NULL --mb constraints
|
||||
);
|
||||
|
||||
|
||||
-- clean unused images
|
||||
CREATE TABLE images (
|
||||
image_id serial PRIMARY KEY,
|
||||
storage_type storage_type_t NOT NULL,
|
||||
|
|
@ -33,6 +34,7 @@ CREATE TABLE users (
|
|||
nickname varchar(16) NOT NULL CHECK (nickname ~ '^[a-zA-Z0-9_-]+$'),
|
||||
disp_name varchar(32),
|
||||
user_desc varchar(512),
|
||||
-- timestamp tl dr, also add access ts
|
||||
creation_date timestamp NOT NULL
|
||||
);
|
||||
|
||||
|
|
@ -48,7 +50,7 @@ CREATE TABLE titles (
|
|||
title_names jsonb NOT NULL,
|
||||
studio_id int NOT NULL REFERENCES studios,
|
||||
poster_id int REFERENCES images (image_id),
|
||||
signal_ids int[] NOT NULL,
|
||||
--signal_ids int[] NOT NULL,
|
||||
title_status title_status_t NOT NULL,
|
||||
rating float CHECK (rating > 0 AND rating <= 10), --by trigger
|
||||
rating_count int CHECK (rating_count >= 0), --by trigger
|
||||
|
|
@ -64,16 +66,17 @@ CREATE TABLE titles (
|
|||
);
|
||||
|
||||
CREATE TABLE reviews (
|
||||
review_id serial PRIMARY KEY,
|
||||
review_id serial PRIMARY KEY, --???
|
||||
user_id int NOT NULL REFERENCES users,
|
||||
title_id int NOT NULL REFERENCES titles,
|
||||
image_ids int[],
|
||||
--image_ids int[], move somewhere
|
||||
review_text text NOT NULL,
|
||||
creation_date timestamp NOT NULL
|
||||
-- constrai (title, user)
|
||||
);
|
||||
|
||||
CREATE TABLE usertitles (
|
||||
usertitle_id serial PRIMARY KEY,
|
||||
usertitle_id serial PRIMARY KEY, -- bigserial, replace by (,)
|
||||
user_id int NOT NULL REFERENCES users,
|
||||
title_id int NOT NULL REFERENCES titles,
|
||||
status usertitle_status_t NOT NULL,
|
||||
|
|
@ -89,9 +92,8 @@ CREATE TABLE title_tags (
|
|||
|
||||
CREATE TABLE signals (
|
||||
signal_id serial PRIMARY KEY,
|
||||
-- title_id
|
||||
raw_data jsonb NOT NULL,
|
||||
provider_id int NOT NULL REFERENCES providers,
|
||||
dirty bool NOT NULL
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
);
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package db
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
|
|
@ -184,83 +184,81 @@ func (ns NullUsertitleStatusT) Value() (driver.Value, error) {
|
|||
return string(ns.UsertitleStatusT), nil
|
||||
}
|
||||
|
||||
type Images struct {
|
||||
ImageID int32 `db:"image_id" json:"image_id"`
|
||||
StorageType StorageTypeT `db:"storage_type" json:"storage_type"`
|
||||
ImagePath string `db:"image_path" json:"image_path"`
|
||||
type Image struct {
|
||||
ImageID int32 `json:"image_id"`
|
||||
StorageType StorageTypeT `json:"storage_type"`
|
||||
ImagePath string `json:"image_path"`
|
||||
}
|
||||
|
||||
type Providers struct {
|
||||
ProviderID int32 `db:"provider_id" json:"provider_id"`
|
||||
ProviderName string `db:"provider_name" json:"provider_name"`
|
||||
type Provider struct {
|
||||
ProviderID int32 `json:"provider_id"`
|
||||
ProviderName string `json:"provider_name"`
|
||||
}
|
||||
|
||||
type Reviews struct {
|
||||
ReviewID int32 `db:"review_id" json:"review_id"`
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
ImageIds []int32 `db:"image_ids" json:"image_ids"`
|
||||
ReviewText string `db:"review_text" json:"review_text"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
type Review struct {
|
||||
ReviewID int32 `json:"review_id"`
|
||||
UserID int32 `json:"user_id"`
|
||||
TitleID int32 `json:"title_id"`
|
||||
ReviewText string `json:"review_text"`
|
||||
CreationDate pgtype.Timestamp `json:"creation_date"`
|
||||
}
|
||||
|
||||
type Signals struct {
|
||||
SignalID int32 `db:"signal_id" json:"signal_id"`
|
||||
RawData []byte `db:"raw_data" json:"raw_data"`
|
||||
ProviderID int32 `db:"provider_id" json:"provider_id"`
|
||||
Dirty bool `db:"dirty" json:"dirty"`
|
||||
type Signal struct {
|
||||
SignalID int32 `json:"signal_id"`
|
||||
RawData []byte `json:"raw_data"`
|
||||
ProviderID int32 `json:"provider_id"`
|
||||
Dirty bool `json:"dirty"`
|
||||
}
|
||||
|
||||
type Studios struct {
|
||||
StudioID int32 `db:"studio_id" json:"studio_id"`
|
||||
StudioName pgtype.Text `db:"studio_name" json:"studio_name"`
|
||||
IllustID pgtype.Int4 `db:"illust_id" json:"illust_id"`
|
||||
StudioDesc pgtype.Text `db:"studio_desc" json:"studio_desc"`
|
||||
type Studio struct {
|
||||
StudioID int32 `json:"studio_id"`
|
||||
StudioName *string `json:"studio_name"`
|
||||
IllustID *int32 `json:"illust_id"`
|
||||
StudioDesc *string `json:"studio_desc"`
|
||||
}
|
||||
|
||||
type Tags struct {
|
||||
TagID int32 `db:"tag_id" json:"tag_id"`
|
||||
TagNames []byte `db:"tag_names" json:"tag_names"`
|
||||
type Tag struct {
|
||||
TagID int32 `json:"tag_id"`
|
||||
TagNames []byte `json:"tag_names"`
|
||||
}
|
||||
|
||||
type TitleTags struct {
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
TagID int32 `db:"tag_id" json:"tag_id"`
|
||||
type Title struct {
|
||||
TitleID int32 `json:"title_id"`
|
||||
TitleNames []byte `json:"title_names"`
|
||||
StudioID int32 `json:"studio_id"`
|
||||
PosterID *int32 `json:"poster_id"`
|
||||
TitleStatus TitleStatusT `json:"title_status"`
|
||||
Rating *float64 `json:"rating"`
|
||||
RatingCount *int32 `json:"rating_count"`
|
||||
ReleaseYear *int32 `json:"release_year"`
|
||||
ReleaseSeason NullReleaseSeasonT `json:"release_season"`
|
||||
Season *int32 `json:"season"`
|
||||
EpisodesAired *int32 `json:"episodes_aired"`
|
||||
EpisodesAll *int32 `json:"episodes_all"`
|
||||
EpisodesLen []byte `json:"episodes_len"`
|
||||
}
|
||||
|
||||
type Titles struct {
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
TitleNames []byte `db:"title_names" json:"title_names"`
|
||||
StudioID int32 `db:"studio_id" json:"studio_id"`
|
||||
PosterID pgtype.Int4 `db:"poster_id" json:"poster_id"`
|
||||
SignalIds []int32 `db:"signal_ids" json:"signal_ids"`
|
||||
TitleStatus TitleStatusT `db:"title_status" json:"title_status"`
|
||||
Rating pgtype.Float8 `db:"rating" json:"rating"`
|
||||
RatingCount pgtype.Int4 `db:"rating_count" json:"rating_count"`
|
||||
ReleaseYear pgtype.Int4 `db:"release_year" json:"release_year"`
|
||||
ReleaseSeason NullReleaseSeasonT `db:"release_season" json:"release_season"`
|
||||
Season pgtype.Int4 `db:"season" json:"season"`
|
||||
EpisodesAired pgtype.Int4 `db:"episodes_aired" json:"episodes_aired"`
|
||||
EpisodesAll pgtype.Int4 `db:"episodes_all" json:"episodes_all"`
|
||||
EpisodesLen []byte `db:"episodes_len" json:"episodes_len"`
|
||||
type TitleTag struct {
|
||||
TitleID int32 `json:"title_id"`
|
||||
TagID int32 `json:"tag_id"`
|
||||
}
|
||||
|
||||
type Users struct {
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
AvatarID pgtype.Int4 `db:"avatar_id" json:"avatar_id"`
|
||||
Passhash string `db:"passhash" json:"passhash"`
|
||||
Mail pgtype.Text `db:"mail" json:"mail"`
|
||||
Nickname string `db:"nickname" json:"nickname"`
|
||||
DispName pgtype.Text `db:"disp_name" json:"disp_name"`
|
||||
UserDesc pgtype.Text `db:"user_desc" json:"user_desc"`
|
||||
CreationDate pgtype.Timestamp `db:"creation_date" json:"creation_date"`
|
||||
type User struct {
|
||||
UserID int32 `json:"user_id"`
|
||||
AvatarID *int32 `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 pgtype.Timestamp `json:"creation_date"`
|
||||
}
|
||||
|
||||
type Usertitles struct {
|
||||
UsertitleID int32 `db:"usertitle_id" json:"usertitle_id"`
|
||||
UserID int32 `db:"user_id" json:"user_id"`
|
||||
TitleID int32 `db:"title_id" json:"title_id"`
|
||||
Status UsertitleStatusT `db:"status" json:"status"`
|
||||
Rate pgtype.Int4 `db:"rate" json:"rate"`
|
||||
ReviewID pgtype.Int4 `db:"review_id" json:"review_id"`
|
||||
type Usertitle struct {
|
||||
UsertitleID int32 `json:"usertitle_id"`
|
||||
UserID int32 `json:"user_id"`
|
||||
TitleID int32 `json:"title_id"`
|
||||
Status UsertitleStatusT `json:"status"`
|
||||
Rate *int32 `json:"rate"`
|
||||
ReviewID *int32 `json:"review_id"`
|
||||
}
|
||||
23
sql/queries.sql.go
Normal file
23
sql/queries.sql.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: queries.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const getImageByID = `-- name: GetImageByID :one
|
||||
SELECT image_id, storage_type, image_path
|
||||
FROM images
|
||||
WHERE image_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetImageByID(ctx context.Context, imageID int32) (Image, error) {
|
||||
row := q.db.QueryRow(ctx, getImageByID, imageID)
|
||||
var i Image
|
||||
err := row.Scan(&i.ImageID, &i.StorageType, &i.ImagePath)
|
||||
return i, err
|
||||
}
|
||||
14
sql/sqlc.yaml
Normal file
14
sql/sqlc.yaml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue