Compare commits
No commits in common. "76df4d859295666041239d4766332dc87cc50194" and "cfb2523cfd4ab9fae9c5aade394856d90e70088a" have entirely different histories.
76df4d8592
...
cfb2523cfd
12 changed files with 74 additions and 957 deletions
|
|
@ -141,82 +141,7 @@ paths:
|
||||||
description: User not found
|
description: User not found
|
||||||
'500':
|
'500':
|
||||||
description: Unknown server error
|
description: Unknown server error
|
||||||
patch:
|
'/users/{user_id}/titles/':
|
||||||
summary: Partially update a user account
|
|
||||||
description: |
|
|
||||||
Update selected user profile fields (excluding password).
|
|
||||||
Password updates must be done via the dedicated auth-service (`/auth/`).
|
|
||||||
Fields not provided in the request body remain unchanged.
|
|
||||||
operationId: updateUser
|
|
||||||
parameters:
|
|
||||||
- name: user_id
|
|
||||||
in: path
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
description: User ID (primary key)
|
|
||||||
example: 123
|
|
||||||
requestBody:
|
|
||||||
required: true
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
avatar_id:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
nullable: true
|
|
||||||
description: ID of the user avatar (references `images.id`); set to `null` to remove avatar
|
|
||||||
example: 42
|
|
||||||
mail:
|
|
||||||
type: string
|
|
||||||
format: email
|
|
||||||
pattern: '^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+$'
|
|
||||||
description: User email (must be unique and valid)
|
|
||||||
example: john.doe.updated@example.com
|
|
||||||
nickname:
|
|
||||||
type: string
|
|
||||||
pattern: '^[a-zA-Z0-9_-]{3,16}$'
|
|
||||||
description: 'Username (alphanumeric + `_` or `-`, 3–16 chars)'
|
|
||||||
maxLength: 16
|
|
||||||
minLength: 3
|
|
||||||
example: john_doe_43
|
|
||||||
disp_name:
|
|
||||||
type: string
|
|
||||||
description: Display name
|
|
||||||
maxLength: 32
|
|
||||||
example: John Smith
|
|
||||||
user_desc:
|
|
||||||
type: string
|
|
||||||
description: User description / bio
|
|
||||||
maxLength: 512
|
|
||||||
example: Just a curious developer.
|
|
||||||
additionalProperties: false
|
|
||||||
description: Only provided fields are updated. Omitted fields remain unchanged.
|
|
||||||
responses:
|
|
||||||
'200':
|
|
||||||
description: User updated successfully. Returns updated user representation (excluding sensitive fields).
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
$ref: '#/components/schemas/User'
|
|
||||||
'400':
|
|
||||||
description: 'Invalid input (e.g., validation failed, nickname/email conflict, malformed JSON)'
|
|
||||||
'401':
|
|
||||||
description: Unauthorized — missing or invalid authentication token
|
|
||||||
'403':
|
|
||||||
description: 'Forbidden — user is not allowed to modify this resource (e.g., not own profile & no admin rights)'
|
|
||||||
'404':
|
|
||||||
description: User not found
|
|
||||||
'409':
|
|
||||||
description: 'Conflict — e.g., requested `nickname` or `mail` already taken by another user'
|
|
||||||
'422':
|
|
||||||
description: 'Unprocessable Entity — semantic errors not caught by schema (e.g., invalid `avatar_id`)'
|
|
||||||
'500':
|
|
||||||
description: Unknown server error
|
|
||||||
'/users/{user_id}/titles':
|
|
||||||
get:
|
get:
|
||||||
summary: Get user titles
|
summary: Get user titles
|
||||||
parameters:
|
parameters:
|
||||||
|
|
@ -306,70 +231,6 @@ paths:
|
||||||
description: Request params are not correct
|
description: Request params are not correct
|
||||||
'500':
|
'500':
|
||||||
description: Unknown server error
|
description: Unknown server error
|
||||||
post:
|
|
||||||
summary: Add a title to a user
|
|
||||||
description: 'User adding title to list af watched, status required'
|
|
||||||
operationId: addUserTitle
|
|
||||||
parameters:
|
|
||||||
- name: user_id
|
|
||||||
in: path
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
description: ID of the user to assign the title to
|
|
||||||
example: 123
|
|
||||||
requestBody:
|
|
||||||
required: true
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
$ref: '#/components/schemas/UserTitle'
|
|
||||||
responses:
|
|
||||||
'200':
|
|
||||||
description: Title successfully added to user
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
data:
|
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- user_id
|
|
||||||
- title_id
|
|
||||||
- status
|
|
||||||
properties:
|
|
||||||
user_id:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
title_id:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
status:
|
|
||||||
$ref: '#/components/schemas/UserTitleStatus'
|
|
||||||
rate:
|
|
||||||
type: integer
|
|
||||||
format: int32
|
|
||||||
review_id:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
ctime:
|
|
||||||
type: string
|
|
||||||
format: date-time
|
|
||||||
additionalProperties: false
|
|
||||||
'400':
|
|
||||||
description: 'Invalid request body (missing fields, invalid types, etc.)'
|
|
||||||
'401':
|
|
||||||
description: Unauthorized — missing or invalid auth token
|
|
||||||
'403':
|
|
||||||
description: Forbidden — user not allowed to assign titles to this user
|
|
||||||
'404':
|
|
||||||
description: User or Title not found
|
|
||||||
'409':
|
|
||||||
description: Conflict — title already assigned to user (if applicable)
|
|
||||||
'500':
|
|
||||||
description: Internal server error
|
|
||||||
components:
|
components:
|
||||||
parameters:
|
parameters:
|
||||||
cursor:
|
cursor:
|
||||||
|
|
|
||||||
313
api/api.gen.go
313
api/api.gen.go
|
|
@ -181,24 +181,6 @@ type GetUsersUserIdParams struct {
|
||||||
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
|
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUserJSONBody defines parameters for UpdateUser.
|
|
||||||
type UpdateUserJSONBody struct {
|
|
||||||
// AvatarId ID of the user avatar (references `images.id`); set to `null` to remove avatar
|
|
||||||
AvatarId *int64 `json:"avatar_id"`
|
|
||||||
|
|
||||||
// DispName Display name
|
|
||||||
DispName *string `json:"disp_name,omitempty"`
|
|
||||||
|
|
||||||
// Mail User email (must be unique and valid)
|
|
||||||
Mail *openapi_types.Email `json:"mail,omitempty"`
|
|
||||||
|
|
||||||
// Nickname Username (alphanumeric + `_` or `-`, 3–16 chars)
|
|
||||||
Nickname *string `json:"nickname,omitempty"`
|
|
||||||
|
|
||||||
// UserDesc User description / bio
|
|
||||||
UserDesc *string `json:"user_desc,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetUsersUserIdTitlesParams defines parameters for GetUsersUserIdTitles.
|
// GetUsersUserIdTitlesParams defines parameters for GetUsersUserIdTitles.
|
||||||
type GetUsersUserIdTitlesParams struct {
|
type GetUsersUserIdTitlesParams struct {
|
||||||
Cursor *Cursor `form:"cursor,omitempty" json:"cursor,omitempty"`
|
Cursor *Cursor `form:"cursor,omitempty" json:"cursor,omitempty"`
|
||||||
|
|
@ -217,12 +199,6 @@ type GetUsersUserIdTitlesParams struct {
|
||||||
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
|
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUserJSONRequestBody defines body for UpdateUser for application/json ContentType.
|
|
||||||
type UpdateUserJSONRequestBody UpdateUserJSONBody
|
|
||||||
|
|
||||||
// AddUserTitleJSONRequestBody defines body for AddUserTitle for application/json ContentType.
|
|
||||||
type AddUserTitleJSONRequestBody = UserTitle
|
|
||||||
|
|
||||||
// Getter for additional properties for Title. Returns the specified
|
// Getter for additional properties for Title. Returns the specified
|
||||||
// element and whether it was found
|
// element and whether it was found
|
||||||
func (a Title) Get(fieldName string) (value interface{}, found bool) {
|
func (a Title) Get(fieldName string) (value interface{}, found bool) {
|
||||||
|
|
@ -615,15 +591,9 @@ type ServerInterface interface {
|
||||||
// Get user info
|
// Get user info
|
||||||
// (GET /users/{user_id})
|
// (GET /users/{user_id})
|
||||||
GetUsersUserId(c *gin.Context, userId string, params GetUsersUserIdParams)
|
GetUsersUserId(c *gin.Context, userId string, params GetUsersUserIdParams)
|
||||||
// Partially update a user account
|
|
||||||
// (PATCH /users/{user_id})
|
|
||||||
UpdateUser(c *gin.Context, userId int64)
|
|
||||||
// Get user titles
|
// Get user titles
|
||||||
// (GET /users/{user_id}/titles)
|
// (GET /users/{user_id}/titles/)
|
||||||
GetUsersUserIdTitles(c *gin.Context, userId string, params GetUsersUserIdTitlesParams)
|
GetUsersUserIdTitles(c *gin.Context, userId string, params GetUsersUserIdTitlesParams)
|
||||||
// Add a title to a user
|
|
||||||
// (POST /users/{user_id}/titles)
|
|
||||||
AddUserTitle(c *gin.Context, userId int64)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerInterfaceWrapper converts contexts to parameters.
|
// ServerInterfaceWrapper converts contexts to parameters.
|
||||||
|
|
@ -811,30 +781,6 @@ func (siw *ServerInterfaceWrapper) GetUsersUserId(c *gin.Context) {
|
||||||
siw.Handler.GetUsersUserId(c, userId, params)
|
siw.Handler.GetUsersUserId(c, userId, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUser operation middleware
|
|
||||||
func (siw *ServerInterfaceWrapper) UpdateUser(c *gin.Context) {
|
|
||||||
|
|
||||||
var err error
|
|
||||||
|
|
||||||
// ------------- Path parameter "user_id" -------------
|
|
||||||
var userId int64
|
|
||||||
|
|
||||||
err = runtime.BindStyledParameterWithOptions("simple", "user_id", c.Param("user_id"), &userId, runtime.BindStyledParameterOptions{Explode: false, Required: true})
|
|
||||||
if err != nil {
|
|
||||||
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter user_id: %w", err), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, middleware := range siw.HandlerMiddlewares {
|
|
||||||
middleware(c)
|
|
||||||
if c.IsAborted() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
siw.Handler.UpdateUser(c, userId)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetUsersUserIdTitles operation middleware
|
// GetUsersUserIdTitles operation middleware
|
||||||
func (siw *ServerInterfaceWrapper) GetUsersUserIdTitles(c *gin.Context) {
|
func (siw *ServerInterfaceWrapper) GetUsersUserIdTitles(c *gin.Context) {
|
||||||
|
|
||||||
|
|
@ -958,30 +904,6 @@ func (siw *ServerInterfaceWrapper) GetUsersUserIdTitles(c *gin.Context) {
|
||||||
siw.Handler.GetUsersUserIdTitles(c, userId, params)
|
siw.Handler.GetUsersUserIdTitles(c, userId, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUserTitle operation middleware
|
|
||||||
func (siw *ServerInterfaceWrapper) AddUserTitle(c *gin.Context) {
|
|
||||||
|
|
||||||
var err error
|
|
||||||
|
|
||||||
// ------------- Path parameter "user_id" -------------
|
|
||||||
var userId int64
|
|
||||||
|
|
||||||
err = runtime.BindStyledParameterWithOptions("simple", "user_id", c.Param("user_id"), &userId, runtime.BindStyledParameterOptions{Explode: false, Required: true})
|
|
||||||
if err != nil {
|
|
||||||
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter user_id: %w", err), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, middleware := range siw.HandlerMiddlewares {
|
|
||||||
middleware(c)
|
|
||||||
if c.IsAborted() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
siw.Handler.AddUserTitle(c, userId)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GinServerOptions provides options for the Gin server.
|
// GinServerOptions provides options for the Gin server.
|
||||||
type GinServerOptions struct {
|
type GinServerOptions struct {
|
||||||
BaseURL string
|
BaseURL string
|
||||||
|
|
@ -1012,9 +934,7 @@ func RegisterHandlersWithOptions(router gin.IRouter, si ServerInterface, options
|
||||||
router.GET(options.BaseURL+"/titles", wrapper.GetTitles)
|
router.GET(options.BaseURL+"/titles", wrapper.GetTitles)
|
||||||
router.GET(options.BaseURL+"/titles/:title_id", wrapper.GetTitlesTitleId)
|
router.GET(options.BaseURL+"/titles/:title_id", wrapper.GetTitlesTitleId)
|
||||||
router.GET(options.BaseURL+"/users/:user_id", wrapper.GetUsersUserId)
|
router.GET(options.BaseURL+"/users/:user_id", wrapper.GetUsersUserId)
|
||||||
router.PATCH(options.BaseURL+"/users/:user_id", wrapper.UpdateUser)
|
router.GET(options.BaseURL+"/users/:user_id/titles/", wrapper.GetUsersUserIdTitles)
|
||||||
router.GET(options.BaseURL+"/users/:user_id/titles", wrapper.GetUsersUserIdTitles)
|
|
||||||
router.POST(options.BaseURL+"/users/:user_id/titles", wrapper.AddUserTitle)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetTitlesRequestObject struct {
|
type GetTitlesRequestObject struct {
|
||||||
|
|
@ -1155,80 +1075,6 @@ func (response GetUsersUserId500Response) VisitGetUsersUserIdResponse(w http.Res
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateUserRequestObject struct {
|
|
||||||
UserId int64 `json:"user_id"`
|
|
||||||
Body *UpdateUserJSONRequestBody
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateUserResponseObject interface {
|
|
||||||
VisitUpdateUserResponse(w http.ResponseWriter) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateUser200JSONResponse User
|
|
||||||
|
|
||||||
func (response UpdateUser200JSONResponse) VisitUpdateUserResponse(w http.ResponseWriter) error {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(200)
|
|
||||||
|
|
||||||
return json.NewEncoder(w).Encode(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateUser400Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response UpdateUser400Response) VisitUpdateUserResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(400)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateUser401Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response UpdateUser401Response) VisitUpdateUserResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(401)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateUser403Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response UpdateUser403Response) VisitUpdateUserResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(403)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateUser404Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response UpdateUser404Response) VisitUpdateUserResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(404)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateUser409Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response UpdateUser409Response) VisitUpdateUserResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(409)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateUser422Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response UpdateUser422Response) VisitUpdateUserResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(422)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateUser500Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response UpdateUser500Response) VisitUpdateUserResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(500)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetUsersUserIdTitlesRequestObject struct {
|
type GetUsersUserIdTitlesRequestObject struct {
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
Params GetUsersUserIdTitlesParams
|
Params GetUsersUserIdTitlesParams
|
||||||
|
|
@ -1274,83 +1120,6 @@ func (response GetUsersUserIdTitles500Response) VisitGetUsersUserIdTitlesRespons
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddUserTitleRequestObject struct {
|
|
||||||
UserId int64 `json:"user_id"`
|
|
||||||
Body *AddUserTitleJSONRequestBody
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddUserTitleResponseObject interface {
|
|
||||||
VisitAddUserTitleResponse(w http.ResponseWriter) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddUserTitle200JSONResponse struct {
|
|
||||||
Data *struct {
|
|
||||||
Ctime *time.Time `json:"ctime,omitempty"`
|
|
||||||
Rate *int32 `json:"rate,omitempty"`
|
|
||||||
ReviewId *int64 `json:"review_id,omitempty"`
|
|
||||||
|
|
||||||
// Status User's title status
|
|
||||||
Status UserTitleStatus `json:"status"`
|
|
||||||
TitleId int64 `json:"title_id"`
|
|
||||||
UserId int64 `json:"user_id"`
|
|
||||||
} `json:"data,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response AddUserTitle200JSONResponse) VisitAddUserTitleResponse(w http.ResponseWriter) error {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(200)
|
|
||||||
|
|
||||||
return json.NewEncoder(w).Encode(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddUserTitle400Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response AddUserTitle400Response) VisitAddUserTitleResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(400)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddUserTitle401Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response AddUserTitle401Response) VisitAddUserTitleResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(401)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddUserTitle403Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response AddUserTitle403Response) VisitAddUserTitleResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(403)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddUserTitle404Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response AddUserTitle404Response) VisitAddUserTitleResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(404)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddUserTitle409Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response AddUserTitle409Response) VisitAddUserTitleResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(409)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddUserTitle500Response struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (response AddUserTitle500Response) VisitAddUserTitleResponse(w http.ResponseWriter) error {
|
|
||||||
w.WriteHeader(500)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// StrictServerInterface represents all server handlers.
|
// StrictServerInterface represents all server handlers.
|
||||||
type StrictServerInterface interface {
|
type StrictServerInterface interface {
|
||||||
// Get titles
|
// Get titles
|
||||||
|
|
@ -1362,15 +1131,9 @@ type StrictServerInterface interface {
|
||||||
// Get user info
|
// Get user info
|
||||||
// (GET /users/{user_id})
|
// (GET /users/{user_id})
|
||||||
GetUsersUserId(ctx context.Context, request GetUsersUserIdRequestObject) (GetUsersUserIdResponseObject, error)
|
GetUsersUserId(ctx context.Context, request GetUsersUserIdRequestObject) (GetUsersUserIdResponseObject, error)
|
||||||
// Partially update a user account
|
|
||||||
// (PATCH /users/{user_id})
|
|
||||||
UpdateUser(ctx context.Context, request UpdateUserRequestObject) (UpdateUserResponseObject, error)
|
|
||||||
// Get user titles
|
// Get user titles
|
||||||
// (GET /users/{user_id}/titles)
|
// (GET /users/{user_id}/titles/)
|
||||||
GetUsersUserIdTitles(ctx context.Context, request GetUsersUserIdTitlesRequestObject) (GetUsersUserIdTitlesResponseObject, error)
|
GetUsersUserIdTitles(ctx context.Context, request GetUsersUserIdTitlesRequestObject) (GetUsersUserIdTitlesResponseObject, error)
|
||||||
// Add a title to a user
|
|
||||||
// (POST /users/{user_id}/titles)
|
|
||||||
AddUserTitle(ctx context.Context, request AddUserTitleRequestObject) (AddUserTitleResponseObject, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type StrictHandlerFunc = strictgin.StrictGinHandlerFunc
|
type StrictHandlerFunc = strictgin.StrictGinHandlerFunc
|
||||||
|
|
@ -1468,41 +1231,6 @@ func (sh *strictHandler) GetUsersUserId(ctx *gin.Context, userId string, params
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUser operation middleware
|
|
||||||
func (sh *strictHandler) UpdateUser(ctx *gin.Context, userId int64) {
|
|
||||||
var request UpdateUserRequestObject
|
|
||||||
|
|
||||||
request.UserId = userId
|
|
||||||
|
|
||||||
var body UpdateUserJSONRequestBody
|
|
||||||
if err := ctx.ShouldBindJSON(&body); err != nil {
|
|
||||||
ctx.Status(http.StatusBadRequest)
|
|
||||||
ctx.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
request.Body = &body
|
|
||||||
|
|
||||||
handler := func(ctx *gin.Context, request interface{}) (interface{}, error) {
|
|
||||||
return sh.ssi.UpdateUser(ctx, request.(UpdateUserRequestObject))
|
|
||||||
}
|
|
||||||
for _, middleware := range sh.middlewares {
|
|
||||||
handler = middleware(handler, "UpdateUser")
|
|
||||||
}
|
|
||||||
|
|
||||||
response, err := handler(ctx, request)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
ctx.Error(err)
|
|
||||||
ctx.Status(http.StatusInternalServerError)
|
|
||||||
} else if validResponse, ok := response.(UpdateUserResponseObject); ok {
|
|
||||||
if err := validResponse.VisitUpdateUserResponse(ctx.Writer); err != nil {
|
|
||||||
ctx.Error(err)
|
|
||||||
}
|
|
||||||
} else if response != nil {
|
|
||||||
ctx.Error(fmt.Errorf("unexpected response type: %T", response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetUsersUserIdTitles operation middleware
|
// GetUsersUserIdTitles operation middleware
|
||||||
func (sh *strictHandler) GetUsersUserIdTitles(ctx *gin.Context, userId string, params GetUsersUserIdTitlesParams) {
|
func (sh *strictHandler) GetUsersUserIdTitles(ctx *gin.Context, userId string, params GetUsersUserIdTitlesParams) {
|
||||||
var request GetUsersUserIdTitlesRequestObject
|
var request GetUsersUserIdTitlesRequestObject
|
||||||
|
|
@ -1530,38 +1258,3 @@ func (sh *strictHandler) GetUsersUserIdTitles(ctx *gin.Context, userId string, p
|
||||||
ctx.Error(fmt.Errorf("unexpected response type: %T", response))
|
ctx.Error(fmt.Errorf("unexpected response type: %T", response))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUserTitle operation middleware
|
|
||||||
func (sh *strictHandler) AddUserTitle(ctx *gin.Context, userId int64) {
|
|
||||||
var request AddUserTitleRequestObject
|
|
||||||
|
|
||||||
request.UserId = userId
|
|
||||||
|
|
||||||
var body AddUserTitleJSONRequestBody
|
|
||||||
if err := ctx.ShouldBindJSON(&body); err != nil {
|
|
||||||
ctx.Status(http.StatusBadRequest)
|
|
||||||
ctx.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
request.Body = &body
|
|
||||||
|
|
||||||
handler := func(ctx *gin.Context, request interface{}) (interface{}, error) {
|
|
||||||
return sh.ssi.AddUserTitle(ctx, request.(AddUserTitleRequestObject))
|
|
||||||
}
|
|
||||||
for _, middleware := range sh.middlewares {
|
|
||||||
handler = middleware(handler, "AddUserTitle")
|
|
||||||
}
|
|
||||||
|
|
||||||
response, err := handler(ctx, request)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
ctx.Error(err)
|
|
||||||
ctx.Status(http.StatusInternalServerError)
|
|
||||||
} else if validResponse, ok := response.(AddUserTitleResponseObject); ok {
|
|
||||||
if err := validResponse.VisitAddUserTitleResponse(ctx.Writer); err != nil {
|
|
||||||
ctx.Error(err)
|
|
||||||
}
|
|
||||||
} else if response != nil {
|
|
||||||
ctx.Error(fmt.Errorf("unexpected response type: %T", response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,8 @@ paths:
|
||||||
$ref: "./paths/titles-id.yaml"
|
$ref: "./paths/titles-id.yaml"
|
||||||
/users/{user_id}:
|
/users/{user_id}:
|
||||||
$ref: "./paths/users-id.yaml"
|
$ref: "./paths/users-id.yaml"
|
||||||
/users/{user_id}/titles:
|
/users/{user_id}/titles/:
|
||||||
$ref: "./paths/users-id-titles.yaml"
|
$ref: "./paths/users-id-titles.yaml"
|
||||||
|
|
||||||
components:
|
components:
|
||||||
parameters:
|
parameters:
|
||||||
$ref: "./parameters/_index.yaml"
|
$ref: "./parameters/_index.yaml"
|
||||||
|
|
|
||||||
|
|
@ -87,55 +87,3 @@ get:
|
||||||
description: Request params are not correct
|
description: Request params are not correct
|
||||||
'500':
|
'500':
|
||||||
description: Unknown server error
|
description: Unknown server error
|
||||||
|
|
||||||
post:
|
|
||||||
summary: Add a title to a user
|
|
||||||
description: User adding title to list af watched, status required
|
|
||||||
operationId: addUserTitle
|
|
||||||
parameters:
|
|
||||||
- name: user_id
|
|
||||||
in: path
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
description: ID of the user to assign the title to
|
|
||||||
example: 123
|
|
||||||
requestBody:
|
|
||||||
required: true
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
$ref: '../schemas/UserTitle.yaml'
|
|
||||||
responses:
|
|
||||||
'200':
|
|
||||||
description: Title successfully added to user
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
# success:
|
|
||||||
# type: boolean
|
|
||||||
# example: true
|
|
||||||
# error:
|
|
||||||
# type: string
|
|
||||||
# nullable: true
|
|
||||||
# example: null
|
|
||||||
data:
|
|
||||||
$ref: '../schemas/UserTitleMini.yaml'
|
|
||||||
# required:
|
|
||||||
# - success
|
|
||||||
# - error
|
|
||||||
'400':
|
|
||||||
description: Invalid request body (missing fields, invalid types, etc.)
|
|
||||||
'401':
|
|
||||||
description: Unauthorized — missing or invalid auth token
|
|
||||||
'403':
|
|
||||||
description: Forbidden — user not allowed to assign titles to this user
|
|
||||||
'404':
|
|
||||||
description: User or Title not found
|
|
||||||
'409':
|
|
||||||
description: Conflict — title already assigned to user (if applicable)
|
|
||||||
'500':
|
|
||||||
description: Internal server error
|
|
||||||
|
|
@ -24,79 +24,3 @@ get:
|
||||||
description: Request params are not correct
|
description: Request params are not correct
|
||||||
'500':
|
'500':
|
||||||
description: Unknown server error
|
description: Unknown server error
|
||||||
|
|
||||||
patch:
|
|
||||||
summary: Partially update a user account
|
|
||||||
description: |
|
|
||||||
Update selected user profile fields (excluding password).
|
|
||||||
Password updates must be done via the dedicated auth-service (`/auth/`).
|
|
||||||
Fields not provided in the request body remain unchanged.
|
|
||||||
operationId: updateUser
|
|
||||||
parameters:
|
|
||||||
- name: user_id
|
|
||||||
in: path
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
description: User ID (primary key)
|
|
||||||
example: 123
|
|
||||||
requestBody:
|
|
||||||
required: true
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
avatar_id:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
nullable: true
|
|
||||||
description: ID of the user avatar (references `images.id`); set to `null` to remove avatar
|
|
||||||
example: 42
|
|
||||||
mail:
|
|
||||||
type: string
|
|
||||||
format: email
|
|
||||||
pattern: '^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+$'
|
|
||||||
description: User email (must be unique and valid)
|
|
||||||
example: john.doe.updated@example.com
|
|
||||||
nickname:
|
|
||||||
type: string
|
|
||||||
pattern: '^[a-zA-Z0-9_-]{3,16}$'
|
|
||||||
description: Username (alphanumeric + `_` or `-`, 3–16 chars)
|
|
||||||
maxLength: 16
|
|
||||||
minLength: 3
|
|
||||||
example: john_doe_43
|
|
||||||
disp_name:
|
|
||||||
type: string
|
|
||||||
description: Display name
|
|
||||||
maxLength: 32
|
|
||||||
example: John Smith
|
|
||||||
user_desc:
|
|
||||||
type: string
|
|
||||||
description: User description / bio
|
|
||||||
maxLength: 512
|
|
||||||
example: Just a curious developer.
|
|
||||||
additionalProperties: false
|
|
||||||
description: Only provided fields are updated. Omitted fields remain unchanged.
|
|
||||||
responses:
|
|
||||||
'200':
|
|
||||||
description: User updated successfully. Returns updated user representation (excluding sensitive fields).
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
$ref: '../schemas/User.yaml'
|
|
||||||
'400':
|
|
||||||
description: Invalid input (e.g., validation failed, nickname/email conflict, malformed JSON)
|
|
||||||
'401':
|
|
||||||
description: Unauthorized — missing or invalid authentication token
|
|
||||||
'403':
|
|
||||||
description: Forbidden — user is not allowed to modify this resource (e.g., not own profile & no admin rights)
|
|
||||||
'404':
|
|
||||||
description: User not found
|
|
||||||
'409':
|
|
||||||
description: Conflict — e.g., requested `nickname` or `mail` already taken by another user
|
|
||||||
'422':
|
|
||||||
description: Unprocessable Entity — semantic errors not caught by schema (e.g., invalid `avatar_id`)
|
|
||||||
'500':
|
|
||||||
description: Unknown server error
|
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- user_id
|
|
||||||
- title_id
|
|
||||||
- status
|
|
||||||
properties:
|
|
||||||
user_id:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
title_id:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
status:
|
|
||||||
$ref: ./enums/UserTitleStatus.yaml
|
|
||||||
rate:
|
|
||||||
type: integer
|
|
||||||
format: int32
|
|
||||||
review_id:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
ctime:
|
|
||||||
type: string
|
|
||||||
format: date-time
|
|
||||||
additionalProperties: false
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
avatar_id:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
nullable: true
|
|
||||||
description: ID of the user avatar (references `images.id`); set to `null` to remove avatar
|
|
||||||
example: 42
|
|
||||||
mail:
|
|
||||||
type: string
|
|
||||||
format: email
|
|
||||||
pattern: '^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+$'
|
|
||||||
description: User email (must be unique and valid)
|
|
||||||
example: john.doe.updated@example.com
|
|
||||||
disp_name:
|
|
||||||
type: string
|
|
||||||
description: Display name
|
|
||||||
maxLength: 32
|
|
||||||
example: John Smith
|
|
||||||
user_desc:
|
|
||||||
type: string
|
|
||||||
description: User description / bio
|
|
||||||
maxLength: 512
|
|
||||||
example: Just a curious developer.
|
|
||||||
additionalProperties: false
|
|
||||||
description: Only provided fields are updated. Omitted fields remain unchanged.
|
|
||||||
|
|
@ -33,7 +33,7 @@ func mapUser(u sqlc.GetUserByIDRow) oapi.User {
|
||||||
CreationDate: &u.CreationDate,
|
CreationDate: &u.CreationDate,
|
||||||
DispName: u.DispName,
|
DispName: u.DispName,
|
||||||
Id: &u.ID,
|
Id: &u.ID,
|
||||||
Mail: StringToEmail(u.Mail),
|
Mail: (*types.Email)(u.Mail),
|
||||||
Nickname: u.Nickname,
|
Nickname: u.Nickname,
|
||||||
UserDesc: u.UserDesc,
|
UserDesc: u.UserDesc,
|
||||||
}
|
}
|
||||||
|
|
@ -125,32 +125,10 @@ func UserTitleStatus2Sqlc(s *[]oapi.UserTitleStatus) ([]sqlc.UsertitleStatusT, e
|
||||||
return sqlc_status, nil
|
return sqlc_status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserTitleStatus2Sqlc1(s *oapi.UserTitleStatus) (*sqlc.UsertitleStatusT, error) {
|
|
||||||
var sqlc_status sqlc.UsertitleStatusT
|
|
||||||
if s == nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
switch *s {
|
|
||||||
case oapi.UserTitleStatusFinished:
|
|
||||||
sqlc_status = sqlc.UsertitleStatusTFinished
|
|
||||||
case oapi.UserTitleStatusInProgress:
|
|
||||||
sqlc_status = sqlc.UsertitleStatusTInProgress
|
|
||||||
case oapi.UserTitleStatusDropped:
|
|
||||||
sqlc_status = sqlc.UsertitleStatusTDropped
|
|
||||||
case oapi.UserTitleStatusPlanned:
|
|
||||||
sqlc_status = sqlc.UsertitleStatusTPlanned
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("unexpected tittle status: %s", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &sqlc_status, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s Server) mapUsertitle(ctx context.Context, t sqlc.SearchUserTitlesRow) (oapi.UserTitle, error) {
|
func (s Server) mapUsertitle(ctx context.Context, t sqlc.SearchUserTitlesRow) (oapi.UserTitle, error) {
|
||||||
|
|
||||||
oapi_usertitle := oapi.UserTitle{
|
oapi_usertitle := oapi.UserTitle{
|
||||||
Ctime: &t.UserCtime,
|
Ctime: sqlDate2oapi(t.UserCtime),
|
||||||
Rate: t.UserRate,
|
Rate: t.UserRate,
|
||||||
ReviewId: t.ReviewID,
|
ReviewId: t.ReviewID,
|
||||||
// Status: ,
|
// Status: ,
|
||||||
|
|
@ -292,97 +270,3 @@ func (s Server) GetUsersUserIdTitles(ctx context.Context, request oapi.GetUsersU
|
||||||
|
|
||||||
return oapi.GetUsersUserIdTitles200JSONResponse{Cursor: new_cursor, Data: oapi_usertitles}, nil
|
return oapi.GetUsersUserIdTitles200JSONResponse{Cursor: new_cursor, Data: oapi_usertitles}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func EmailToStringPtr(e *types.Email) *string {
|
|
||||||
if e == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
s := string(*e)
|
|
||||||
return &s
|
|
||||||
}
|
|
||||||
|
|
||||||
func StringToEmail(e *string) *types.Email {
|
|
||||||
if e == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
s := types.Email(*e)
|
|
||||||
return &s
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateUser implements oapi.StrictServerInterface.
|
|
||||||
func (s Server) UpdateUser(ctx context.Context, request oapi.UpdateUserRequestObject) (oapi.UpdateUserResponseObject, error) {
|
|
||||||
|
|
||||||
params := sqlc.UpdateUserParams{
|
|
||||||
AvatarID: request.Body.AvatarId,
|
|
||||||
DispName: request.Body.DispName,
|
|
||||||
UserDesc: request.Body.UserDesc,
|
|
||||||
Mail: EmailToStringPtr(request.Body.Mail),
|
|
||||||
UserID: request.UserId,
|
|
||||||
}
|
|
||||||
|
|
||||||
user, err := s.db.UpdateUser(ctx, params)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("%v", err)
|
|
||||||
return oapi.UpdateUser500Response{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
oapi_user := oapi.User{ // maybe its possible to make one sqlc type and use one map func iinstead of this shit
|
|
||||||
AvatarId: user.AvatarID,
|
|
||||||
CreationDate: &user.CreationDate,
|
|
||||||
DispName: user.DispName,
|
|
||||||
Id: &user.ID,
|
|
||||||
Mail: StringToEmail(user.Mail),
|
|
||||||
Nickname: user.Nickname,
|
|
||||||
UserDesc: user.UserDesc,
|
|
||||||
}
|
|
||||||
|
|
||||||
return oapi.UpdateUser200JSONResponse(oapi_user), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s Server) AddUserTitle(ctx context.Context, request oapi.AddUserTitleRequestObject) (oapi.AddUserTitleResponseObject, error) {
|
|
||||||
|
|
||||||
status, err := UserTitleStatus2Sqlc1(&request.Body.Status)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("%v", err)
|
|
||||||
return oapi.AddUserTitle400Response{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
params := sqlc.InsertUserTitleParams{
|
|
||||||
UserID: request.UserId,
|
|
||||||
TitleID: request.Body.Title.Id,
|
|
||||||
Status: *status,
|
|
||||||
Rate: request.Body.Rate,
|
|
||||||
ReviewID: request.Body.ReviewId,
|
|
||||||
}
|
|
||||||
|
|
||||||
user_title, err := s.db.InsertUserTitle(ctx, params)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("%v", err)
|
|
||||||
return oapi.AddUserTitle500Response{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
oapi_status, err := sql2usertitlestatus(user_title.Status)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("%v", err)
|
|
||||||
return oapi.AddUserTitle500Response{}, nil
|
|
||||||
}
|
|
||||||
oapi_usertitle := struct {
|
|
||||||
Ctime *time.Time `json:"ctime,omitempty"`
|
|
||||||
Rate *int32 `json:"rate,omitempty"`
|
|
||||||
ReviewId *int64 `json:"review_id,omitempty"`
|
|
||||||
|
|
||||||
// Status User's title status
|
|
||||||
Status oapi.UserTitleStatus `json:"status"`
|
|
||||||
TitleId int64 `json:"title_id"`
|
|
||||||
UserId int64 `json:"user_id"`
|
|
||||||
}{
|
|
||||||
Ctime: &user_title.Ctime,
|
|
||||||
Rate: user_title.Rate,
|
|
||||||
ReviewId: user_title.ReviewID,
|
|
||||||
Status: oapi_status,
|
|
||||||
TitleId: user_title.TitleID,
|
|
||||||
UserId: user_title.UserID,
|
|
||||||
}
|
|
||||||
|
|
||||||
return oapi.AddUserTitle200JSONResponse{Data: &oapi_usertitle}, nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -58,15 +58,15 @@ RETURNING id, tag_names;
|
||||||
-- VALUES ($1, $2, $3, $4, $5, $6, $7)
|
-- VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
-- RETURNING user_id, avatar_id, nickname, disp_name, user_desc, creation_date;
|
-- RETURNING user_id, avatar_id, nickname, disp_name, user_desc, creation_date;
|
||||||
|
|
||||||
-- name: UpdateUser :one
|
-- -- name: UpdateUser :one
|
||||||
UPDATE users
|
-- UPDATE users
|
||||||
SET
|
-- SET
|
||||||
avatar_id = COALESCE(sqlc.narg('avatar_id'), avatar_id),
|
-- avatar_id = COALESCE(sqlc.narg('avatar_id'), avatar_id),
|
||||||
disp_name = COALESCE(sqlc.narg('disp_name'), disp_name),
|
-- disp_name = COALESCE(sqlc.narg('disp_name'), disp_name),
|
||||||
user_desc = COALESCE(sqlc.narg('user_desc'), user_desc),
|
-- user_desc = COALESCE(sqlc.narg('user_desc'), user_desc),
|
||||||
mail = COALESCE(sqlc.narg('mail'), mail)
|
-- passhash = COALESCE(sqlc.narg('passhash'), passhash)
|
||||||
WHERE id = sqlc.arg('user_id')
|
-- WHERE user_id = sqlc.arg('user_id')
|
||||||
RETURNING id, avatar_id, nickname, disp_name, user_desc, creation_date, mail;
|
-- RETURNING user_id, avatar_id, nickname, disp_name, user_desc, creation_date;
|
||||||
|
|
||||||
-- -- name: DeleteUser :exec
|
-- -- name: DeleteUser :exec
|
||||||
-- DELETE FROM users
|
-- DELETE FROM users
|
||||||
|
|
@ -412,7 +412,7 @@ WHERE review_id = sqlc.arg('review_id')::bigint;
|
||||||
-- DELETE FROM reviews
|
-- DELETE FROM reviews
|
||||||
-- WHERE review_id = $1;
|
-- WHERE review_id = $1;
|
||||||
|
|
||||||
-- -- name: ListReviewsByTitle :many
|
-- name: ListReviewsByTitle :many
|
||||||
-- SELECT review_id, user_id, title_id, image_ids, review_text, creation_date
|
-- SELECT review_id, user_id, title_id, image_ids, review_text, creation_date
|
||||||
-- FROM reviews
|
-- FROM reviews
|
||||||
-- WHERE title_id = $1
|
-- WHERE title_id = $1
|
||||||
|
|
@ -438,16 +438,10 @@ WHERE review_id = sqlc.arg('review_id')::bigint;
|
||||||
-- ORDER BY usertitle_id
|
-- ORDER BY usertitle_id
|
||||||
-- LIMIT $2 OFFSET $3;
|
-- LIMIT $2 OFFSET $3;
|
||||||
|
|
||||||
-- name: InsertUserTitle :one
|
-- -- name: CreateUserTitle :one
|
||||||
INSERT INTO usertitles (user_id, title_id, status, rate, review_id)
|
-- INSERT INTO usertitles (user_id, title_id, status, rate, review_id)
|
||||||
VALUES (
|
-- VALUES ($1, $2, $3, $4, $5)
|
||||||
sqlc.arg('user_id')::bigint,
|
-- RETURNING usertitle_id, user_id, title_id, status, rate, review_id;
|
||||||
sqlc.arg('title_id')::bigint,
|
|
||||||
sqlc.arg('status')::usertitle_status_t,
|
|
||||||
sqlc.narg('rate')::int,
|
|
||||||
sqlc.narg('review_id')::bigint
|
|
||||||
)
|
|
||||||
RETURNING user_id, title_id, status, rate, review_id, ctime;
|
|
||||||
|
|
||||||
-- -- name: UpdateUserTitle :one
|
-- -- name: UpdateUserTitle :one
|
||||||
-- UPDATE usertitles
|
-- UPDATE usertitles
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ CREATE TABLE usertitles (
|
||||||
status usertitle_status_t NOT NULL,
|
status usertitle_status_t NOT NULL,
|
||||||
rate int CHECK (rate > 0 AND rate <= 10),
|
rate int CHECK (rate > 0 AND rate <= 10),
|
||||||
review_id bigint REFERENCES reviews (id),
|
review_id bigint REFERENCES reviews (id),
|
||||||
ctime timestamptz NOT NULL DEFAULT now()
|
ctime timestamptz
|
||||||
-- // TODO: series status
|
-- // TODO: series status
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -170,16 +170,3 @@ CREATE TRIGGER trg_notify_new_signal
|
||||||
AFTER INSERT ON signals
|
AFTER INSERT ON signals
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE FUNCTION notify_new_signal();
|
EXECUTE FUNCTION notify_new_signal();
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION set_ctime()
|
|
||||||
RETURNS TRIGGER AS $$
|
|
||||||
BEGIN
|
|
||||||
NEW.ctime = now();
|
|
||||||
RETURN NEW;
|
|
||||||
END;
|
|
||||||
$$ LANGUAGE plpgsql;
|
|
||||||
|
|
||||||
CREATE TRIGGER set_ctime_on_update
|
|
||||||
BEFORE UPDATE ON usertitles
|
|
||||||
FOR EACH ROW
|
|
||||||
EXECUTE FUNCTION set_ctime();
|
|
||||||
|
|
@ -282,5 +282,5 @@ type Usertitle struct {
|
||||||
Status UsertitleStatusT `json:"status"`
|
Status UsertitleStatusT `json:"status"`
|
||||||
Rate *int32 `json:"rate"`
|
Rate *int32 `json:"rate"`
|
||||||
ReviewID *int64 `json:"review_id"`
|
ReviewID *int64 `json:"review_id"`
|
||||||
Ctime time.Time `json:"ctime"`
|
Ctime pgtype.Timestamptz `json:"ctime"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
)
|
)
|
||||||
|
|
||||||
const createImage = `-- name: CreateImage :one
|
const createImage = `-- name: CreateImage :one
|
||||||
|
|
@ -112,6 +114,9 @@ func (q *Queries) GetStudioByID(ctx context.Context, studioID int64) (Studio, er
|
||||||
|
|
||||||
const getTitleByID = `-- name: GetTitleByID :one
|
const getTitleByID = `-- name: GetTitleByID :one
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
t.id, t.title_names, t.studio_id, t.poster_id, t.title_status, t.rating, t.rating_count, t.release_year, t.release_season, t.season, t.episodes_aired, t.episodes_all, t.episodes_len,
|
t.id, t.title_names, t.studio_id, t.poster_id, t.title_status, t.rating, t.rating_count, t.release_year, t.release_season, t.season, t.episodes_aired, t.episodes_all, t.episodes_len,
|
||||||
i.storage_type::text as title_storage_type,
|
i.storage_type::text as title_storage_type,
|
||||||
|
|
@ -162,6 +167,26 @@ type GetTitleByIDRow struct {
|
||||||
StudioImagePath *string `json:"studio_image_path"`
|
StudioImagePath *string `json:"studio_image_path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- 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
|
// -- name: DeleteUser :exec
|
||||||
// DELETE FROM users
|
// DELETE FROM users
|
||||||
// WHERE user_id = $1;
|
// WHERE user_id = $1;
|
||||||
|
|
@ -315,93 +340,6 @@ func (q *Queries) InsertTitleTags(ctx context.Context, arg InsertTitleTagsParams
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
const insertUserTitle = `-- name: InsertUserTitle :one
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO usertitles (user_id, title_id, status, rate, review_id)
|
|
||||||
VALUES (
|
|
||||||
$1::bigint,
|
|
||||||
$2::bigint,
|
|
||||||
$3::usertitle_status_t,
|
|
||||||
$4::int,
|
|
||||||
$5::bigint
|
|
||||||
)
|
|
||||||
RETURNING user_id, title_id, status, rate, review_id, ctime
|
|
||||||
`
|
|
||||||
|
|
||||||
type InsertUserTitleParams struct {
|
|
||||||
UserID int64 `json:"user_id"`
|
|
||||||
TitleID int64 `json:"title_id"`
|
|
||||||
Status UsertitleStatusT `json:"status"`
|
|
||||||
Rate *int32 `json:"rate"`
|
|
||||||
ReviewID *int64 `json:"review_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// -- 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;
|
|
||||||
func (q *Queries) InsertUserTitle(ctx context.Context, arg InsertUserTitleParams) (Usertitle, error) {
|
|
||||||
row := q.db.QueryRow(ctx, insertUserTitle,
|
|
||||||
arg.UserID,
|
|
||||||
arg.TitleID,
|
|
||||||
arg.Status,
|
|
||||||
arg.Rate,
|
|
||||||
arg.ReviewID,
|
|
||||||
)
|
|
||||||
var i Usertitle
|
|
||||||
err := row.Scan(
|
|
||||||
&i.UserID,
|
|
||||||
&i.TitleID,
|
|
||||||
&i.Status,
|
|
||||||
&i.Rate,
|
|
||||||
&i.ReviewID,
|
|
||||||
&i.Ctime,
|
|
||||||
)
|
|
||||||
return i, err
|
|
||||||
}
|
|
||||||
|
|
||||||
const searchTitles = `-- name: SearchTitles :many
|
const searchTitles = `-- name: SearchTitles :many
|
||||||
SELECT
|
SELECT
|
||||||
t.id as id,
|
t.id as id,
|
||||||
|
|
@ -784,7 +722,7 @@ type SearchUserTitlesRow struct {
|
||||||
UsertitleStatus UsertitleStatusT `json:"usertitle_status"`
|
UsertitleStatus UsertitleStatusT `json:"usertitle_status"`
|
||||||
UserRate *int32 `json:"user_rate"`
|
UserRate *int32 `json:"user_rate"`
|
||||||
ReviewID *int64 `json:"review_id"`
|
ReviewID *int64 `json:"review_id"`
|
||||||
UserCtime time.Time `json:"user_ctime"`
|
UserCtime pgtype.Timestamptz `json:"user_ctime"`
|
||||||
TitleStorageType string `json:"title_storage_type"`
|
TitleStorageType string `json:"title_storage_type"`
|
||||||
TitleImagePath *string `json:"title_image_path"`
|
TitleImagePath *string `json:"title_image_path"`
|
||||||
TagNames json.RawMessage `json:"tag_names"`
|
TagNames json.RawMessage `json:"tag_names"`
|
||||||
|
|
@ -846,64 +784,3 @@ func (q *Queries) SearchUserTitles(ctx context.Context, arg SearchUserTitlesPara
|
||||||
}
|
}
|
||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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),
|
|
||||||
mail = COALESCE($4, mail)
|
|
||||||
WHERE id = $5
|
|
||||||
RETURNING id, avatar_id, nickname, disp_name, user_desc, creation_date, mail
|
|
||||||
`
|
|
||||||
|
|
||||||
type UpdateUserParams struct {
|
|
||||||
AvatarID *int64 `json:"avatar_id"`
|
|
||||||
DispName *string `json:"disp_name"`
|
|
||||||
UserDesc *string `json:"user_desc"`
|
|
||||||
Mail *string `json:"mail"`
|
|
||||||
UserID int64 `json:"user_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateUserRow struct {
|
|
||||||
ID int64 `json:"id"`
|
|
||||||
AvatarID *int64 `json:"avatar_id"`
|
|
||||||
Nickname string `json:"nickname"`
|
|
||||||
DispName *string `json:"disp_name"`
|
|
||||||
UserDesc *string `json:"user_desc"`
|
|
||||||
CreationDate time.Time `json:"creation_date"`
|
|
||||||
Mail *string `json:"mail"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// -- 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;
|
|
||||||
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (UpdateUserRow, error) {
|
|
||||||
row := q.db.QueryRow(ctx, updateUser,
|
|
||||||
arg.AvatarID,
|
|
||||||
arg.DispName,
|
|
||||||
arg.UserDesc,
|
|
||||||
arg.Mail,
|
|
||||||
arg.UserID,
|
|
||||||
)
|
|
||||||
var i UpdateUserRow
|
|
||||||
err := row.Scan(
|
|
||||||
&i.ID,
|
|
||||||
&i.AvatarID,
|
|
||||||
&i.Nickname,
|
|
||||||
&i.DispName,
|
|
||||||
&i.UserDesc,
|
|
||||||
&i.CreationDate,
|
|
||||||
&i.Mail,
|
|
||||||
)
|
|
||||||
return i, err
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue