feat: AddUserTitle implemented
This commit is contained in:
parent
15a681c622
commit
76df4d8592
10 changed files with 749 additions and 39 deletions
|
|
@ -141,7 +141,82 @@ paths:
|
||||||
description: User not found
|
description: User not found
|
||||||
'500':
|
'500':
|
||||||
description: Unknown server error
|
description: Unknown server error
|
||||||
'/users/{user_id}/titles/':
|
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: '#/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:
|
||||||
|
|
@ -231,6 +306,70 @@ 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,6 +181,24 @@ 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"`
|
||||||
|
|
@ -199,6 +217,12 @@ 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) {
|
||||||
|
|
@ -591,9 +615,15 @@ 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.
|
||||||
|
|
@ -781,6 +811,30 @@ 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) {
|
||||||
|
|
||||||
|
|
@ -904,6 +958,30 @@ 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
|
||||||
|
|
@ -934,7 +1012,9 @@ 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.GET(options.BaseURL+"/users/:user_id/titles/", wrapper.GetUsersUserIdTitles)
|
router.PATCH(options.BaseURL+"/users/:user_id", wrapper.UpdateUser)
|
||||||
|
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 {
|
||||||
|
|
@ -1075,6 +1155,80 @@ 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
|
||||||
|
|
@ -1120,6 +1274,83 @@ 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
|
||||||
|
|
@ -1131,9 +1362,15 @@ 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
|
||||||
|
|
@ -1231,6 +1468,41 @@ 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
|
||||||
|
|
@ -1258,3 +1530,38 @@ 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,8 +13,9 @@ 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,3 +87,55 @@ 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
api/schemas/UserTitleMini.yaml
Normal file
24
api/schemas/UserTitleMini.yaml
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
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
|
||||||
26
api/schemas/updateUser.yaml
Normal file
26
api/schemas/updateUser.yaml
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
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.
|
||||||
|
|
@ -125,10 +125,32 @@ 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: sqlDate2oapi(t.UserCtime),
|
Ctime: &t.UserCtime,
|
||||||
Rate: t.UserRate,
|
Rate: t.UserRate,
|
||||||
ReviewId: t.ReviewID,
|
ReviewId: t.ReviewID,
|
||||||
// Status: ,
|
// Status: ,
|
||||||
|
|
@ -316,3 +338,51 @@ func (s Server) UpdateUser(ctx context.Context, request oapi.UpdateUserRequestOb
|
||||||
|
|
||||||
return oapi.UpdateUser200JSONResponse(oapi_user), nil
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,10 +438,16 @@ 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: CreateUserTitle :one
|
-- name: InsertUserTitle :one
|
||||||
-- INSERT INTO usertitles (user_id, title_id, status, rate, review_id)
|
INSERT INTO usertitles (user_id, title_id, status, rate, review_id)
|
||||||
-- VALUES ($1, $2, $3, $4, $5)
|
VALUES (
|
||||||
-- RETURNING usertitle_id, user_id, title_id, status, rate, review_id;
|
sqlc.arg('user_id')::bigint,
|
||||||
|
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
|
||||||
|
|
|
||||||
|
|
@ -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 pgtype.Timestamptz `json:"ctime"`
|
Ctime time.Time `json:"ctime"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ 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
|
||||||
|
|
@ -317,6 +315,93 @@ 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,
|
||||||
|
|
@ -699,7 +784,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 pgtype.Timestamptz `json:"user_ctime"`
|
UserCtime time.Time `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"`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue