feat: patch usertitle described
This commit is contained in:
parent
759679990a
commit
cb9fba6fbc
4 changed files with 133 additions and 214 deletions
|
|
@ -328,13 +328,9 @@ paths:
|
|||
schema:
|
||||
type: object
|
||||
required:
|
||||
- user_id
|
||||
- title_id
|
||||
- status
|
||||
properties:
|
||||
user_id:
|
||||
type: integer
|
||||
format: int64
|
||||
title_id:
|
||||
type: integer
|
||||
format: int64
|
||||
|
|
@ -343,12 +339,6 @@ paths:
|
|||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
review_id:
|
||||
type: integer
|
||||
format: int64
|
||||
ctime:
|
||||
type: string
|
||||
format: date-time
|
||||
responses:
|
||||
'200':
|
||||
description: Title successfully added to user
|
||||
|
|
@ -356,32 +346,29 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required:
|
||||
- user_id
|
||||
- title_id
|
||||
- status
|
||||
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
|
||||
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':
|
||||
|
|
@ -394,6 +381,53 @@ paths:
|
|||
description: Conflict — title already assigned to user (if applicable)
|
||||
'500':
|
||||
description: Internal server error
|
||||
patch:
|
||||
summary: Update a usertitle
|
||||
description: User updating title list of watched
|
||||
operationId: updateUserTitle
|
||||
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:
|
||||
type: object
|
||||
required:
|
||||
- title_id
|
||||
properties:
|
||||
title_id:
|
||||
type: integer
|
||||
format: int64
|
||||
status:
|
||||
$ref: '#/components/schemas/UserTitleStatus'
|
||||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
'200':
|
||||
description: Title successfully updated
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/paths/~1users~1%7Buser_id%7D~1titles/post/responses/200/content/application~1json/schema'
|
||||
'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 update title
|
||||
'404':
|
||||
description: User or Title not found
|
||||
'500':
|
||||
description: Internal server error
|
||||
components:
|
||||
parameters:
|
||||
cursor:
|
||||
|
|
@ -629,4 +663,3 @@ components:
|
|||
ctime:
|
||||
type: string
|
||||
format: date-time
|
||||
additionalProperties: true
|
||||
|
|
|
|||
162
api/api.gen.go
162
api/api.gen.go
|
|
@ -151,10 +151,9 @@ type UserTitle struct {
|
|||
ReviewId *int64 `json:"review_id,omitempty"`
|
||||
|
||||
// Status User's title status
|
||||
Status UserTitleStatus `json:"status"`
|
||||
Title *Title `json:"title,omitempty"`
|
||||
UserId int64 `json:"user_id"`
|
||||
AdditionalProperties map[string]interface{} `json:"-"`
|
||||
Status UserTitleStatus `json:"status"`
|
||||
Title *Title `json:"title,omitempty"`
|
||||
UserId int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
// UserTitleStatus User's title status
|
||||
|
|
@ -486,145 +485,6 @@ func (a Title) MarshalJSON() ([]byte, error) {
|
|||
return json.Marshal(object)
|
||||
}
|
||||
|
||||
// Getter for additional properties for UserTitle. Returns the specified
|
||||
// element and whether it was found
|
||||
func (a UserTitle) Get(fieldName string) (value interface{}, found bool) {
|
||||
if a.AdditionalProperties != nil {
|
||||
value, found = a.AdditionalProperties[fieldName]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Setter for additional properties for UserTitle
|
||||
func (a *UserTitle) Set(fieldName string, value interface{}) {
|
||||
if a.AdditionalProperties == nil {
|
||||
a.AdditionalProperties = make(map[string]interface{})
|
||||
}
|
||||
a.AdditionalProperties[fieldName] = value
|
||||
}
|
||||
|
||||
// Override default JSON handling for UserTitle to handle AdditionalProperties
|
||||
func (a *UserTitle) UnmarshalJSON(b []byte) error {
|
||||
object := make(map[string]json.RawMessage)
|
||||
err := json.Unmarshal(b, &object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if raw, found := object["ctime"]; found {
|
||||
err = json.Unmarshal(raw, &a.Ctime)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading 'ctime': %w", err)
|
||||
}
|
||||
delete(object, "ctime")
|
||||
}
|
||||
|
||||
if raw, found := object["rate"]; found {
|
||||
err = json.Unmarshal(raw, &a.Rate)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading 'rate': %w", err)
|
||||
}
|
||||
delete(object, "rate")
|
||||
}
|
||||
|
||||
if raw, found := object["review_id"]; found {
|
||||
err = json.Unmarshal(raw, &a.ReviewId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading 'review_id': %w", err)
|
||||
}
|
||||
delete(object, "review_id")
|
||||
}
|
||||
|
||||
if raw, found := object["status"]; found {
|
||||
err = json.Unmarshal(raw, &a.Status)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading 'status': %w", err)
|
||||
}
|
||||
delete(object, "status")
|
||||
}
|
||||
|
||||
if raw, found := object["title"]; found {
|
||||
err = json.Unmarshal(raw, &a.Title)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading 'title': %w", err)
|
||||
}
|
||||
delete(object, "title")
|
||||
}
|
||||
|
||||
if raw, found := object["user_id"]; found {
|
||||
err = json.Unmarshal(raw, &a.UserId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading 'user_id': %w", err)
|
||||
}
|
||||
delete(object, "user_id")
|
||||
}
|
||||
|
||||
if len(object) != 0 {
|
||||
a.AdditionalProperties = make(map[string]interface{})
|
||||
for fieldName, fieldBuf := range object {
|
||||
var fieldVal interface{}
|
||||
err := json.Unmarshal(fieldBuf, &fieldVal)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error unmarshaling field %s: %w", fieldName, err)
|
||||
}
|
||||
a.AdditionalProperties[fieldName] = fieldVal
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Override default JSON handling for UserTitle to handle AdditionalProperties
|
||||
func (a UserTitle) MarshalJSON() ([]byte, error) {
|
||||
var err error
|
||||
object := make(map[string]json.RawMessage)
|
||||
|
||||
if a.Ctime != nil {
|
||||
object["ctime"], err = json.Marshal(a.Ctime)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling 'ctime': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if a.Rate != nil {
|
||||
object["rate"], err = json.Marshal(a.Rate)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling 'rate': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if a.ReviewId != nil {
|
||||
object["review_id"], err = json.Marshal(a.ReviewId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling 'review_id': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
object["status"], err = json.Marshal(a.Status)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling 'status': %w", err)
|
||||
}
|
||||
|
||||
if a.Title != nil {
|
||||
object["title"], err = json.Marshal(a.Title)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling 'title': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
object["user_id"], err = json.Marshal(a.UserId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling 'user_id': %w", err)
|
||||
}
|
||||
|
||||
for fieldName, field := range a.AdditionalProperties {
|
||||
object[fieldName], err = json.Marshal(field)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling '%s': %w", fieldName, err)
|
||||
}
|
||||
}
|
||||
return json.Marshal(object)
|
||||
}
|
||||
|
||||
// ServerInterface represents all server handlers.
|
||||
type ServerInterface interface {
|
||||
// Get titles
|
||||
|
|
@ -1313,16 +1173,14 @@ type AddUserTitleResponseObject interface {
|
|||
}
|
||||
|
||||
type AddUserTitle200JSONResponse struct {
|
||||
Data *struct {
|
||||
Ctime *time.Time `json:"ctime,omitempty"`
|
||||
Rate *int32 `json:"rate,omitempty"`
|
||||
ReviewId *int64 `json:"review_id,omitempty"`
|
||||
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"`
|
||||
// Status User's title status
|
||||
Status UserTitleStatus `json:"status"`
|
||||
TitleId int64 `json:"title_id"`
|
||||
UserId int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
func (response AddUserTitle200JSONResponse) VisitAddUserTitleResponse(w http.ResponseWriter) error {
|
||||
|
|
|
|||
|
|
@ -110,13 +110,9 @@ post:
|
|||
schema:
|
||||
type: object
|
||||
required:
|
||||
- user_id
|
||||
- title_id
|
||||
- status
|
||||
properties:
|
||||
user_id:
|
||||
type: integer
|
||||
format: int64
|
||||
title_id:
|
||||
type: integer
|
||||
format: int64
|
||||
|
|
@ -125,12 +121,6 @@ post:
|
|||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
review_id:
|
||||
type: integer
|
||||
format: int64
|
||||
ctime:
|
||||
type: string
|
||||
format: date-time
|
||||
|
||||
responses:
|
||||
'200':
|
||||
|
|
@ -138,20 +128,8 @@ post:
|
|||
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
|
||||
$ref: '../schemas/UserTitleMini.yaml'
|
||||
|
||||
'400':
|
||||
description: Invalid request body (missing fields, invalid types, etc.)
|
||||
'401':
|
||||
|
|
@ -162,5 +140,55 @@ post:
|
|||
description: User or Title not found
|
||||
'409':
|
||||
description: Conflict — title already assigned to user (if applicable)
|
||||
'500':
|
||||
description: Internal server error
|
||||
|
||||
patch:
|
||||
summary: Update a usertitle
|
||||
description: User updating title list of watched
|
||||
operationId: updateUserTitle
|
||||
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:
|
||||
type: object
|
||||
required:
|
||||
- title_id
|
||||
properties:
|
||||
title_id:
|
||||
type: integer
|
||||
format: int64
|
||||
status:
|
||||
$ref: ../schemas/enums/UserTitleStatus.yaml
|
||||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
|
||||
responses:
|
||||
'200':
|
||||
description: Title successfully updated
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '../schemas/UserTitleMini.yaml'
|
||||
|
||||
'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 update title
|
||||
'404':
|
||||
description: User or Title not found
|
||||
'500':
|
||||
description: Internal server error
|
||||
|
|
@ -360,7 +360,7 @@ func (s Server) UpdateUser(ctx context.Context, request oapi.UpdateUserRequestOb
|
|||
}
|
||||
|
||||
func (s Server) AddUserTitle(ctx context.Context, request oapi.AddUserTitleRequestObject) (oapi.AddUserTitleResponseObject, error) {
|
||||
|
||||
//TODO: add review if exists
|
||||
status, err := UserTitleStatus2Sqlc1(&request.Body.Status)
|
||||
if err != nil {
|
||||
log.Errorf("%v", err)
|
||||
|
|
@ -404,5 +404,5 @@ func (s Server) AddUserTitle(ctx context.Context, request oapi.AddUserTitleReque
|
|||
UserId: user_title.UserID,
|
||||
}
|
||||
|
||||
return oapi.AddUserTitle200JSONResponse{Data: &oapi_usertitle}, nil
|
||||
return oapi.AddUserTitle200JSONResponse(oapi_usertitle), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue