feat: field studio_name added to title in openapi

This commit is contained in:
Iron_Felix 2025-11-15 18:20:27 +03:00
parent 5cc6757900
commit 2edf96571b
3 changed files with 41 additions and 100 deletions

View file

@ -50,6 +50,7 @@ type Title struct {
ReleaseSeason *ReleaseSeason `json:"release_season,omitempty"`
ReleaseYear *int32 `json:"release_year,omitempty"`
StudioId *int64 `json:"studio_id,omitempty"`
StudioName *string `json:"studio_name,omitempty"`
// TitleNames Localized titles. Key = language (ISO 639-1), value = list of names
TitleNames *map[string][]string `json:"title_names,omitempty"`
@ -103,9 +104,6 @@ type GetUsersUserIdParams struct {
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
}
// PostUsersJSONRequestBody defines body for PostUsers for application/json ContentType.
type PostUsersJSONRequestBody = User
// Getter for additional properties for Title. Returns the specified
// element and whether it was found
func (a Title) Get(fieldName string) (value interface{}, found bool) {
@ -211,6 +209,14 @@ func (a *Title) UnmarshalJSON(b []byte) error {
delete(object, "studio_id")
}
if raw, found := object["studio_name"]; found {
err = json.Unmarshal(raw, &a.StudioName)
if err != nil {
return fmt.Errorf("error reading 'studio_name': %w", err)
}
delete(object, "studio_name")
}
if raw, found := object["title_names"]; found {
err = json.Unmarshal(raw, &a.TitleNames)
if err != nil {
@ -316,6 +322,13 @@ func (a Title) MarshalJSON() ([]byte, error) {
}
}
if a.StudioName != nil {
object["studio_name"], err = json.Marshal(a.StudioName)
if err != nil {
return nil, fmt.Errorf("error marshaling 'studio_name': %w", err)
}
}
if a.TitleNames != nil {
object["title_names"], err = json.Marshal(a.TitleNames)
if err != nil {
@ -344,9 +357,6 @@ type ServerInterface interface {
// Get titles
// (GET /title)
GetTitle(c *gin.Context, params GetTitleParams)
// Add new user
// (POST /users)
PostUsers(c *gin.Context)
// Get user info
// (GET /users/{user_id})
GetUsersUserId(c *gin.Context, userId string, params GetUsersUserIdParams)
@ -443,19 +453,6 @@ func (siw *ServerInterfaceWrapper) GetTitle(c *gin.Context) {
siw.Handler.GetTitle(c, params)
}
// PostUsers operation middleware
func (siw *ServerInterfaceWrapper) PostUsers(c *gin.Context) {
for _, middleware := range siw.HandlerMiddlewares {
middleware(c)
if c.IsAborted() {
return
}
}
siw.Handler.PostUsers(c)
}
// GetUsersUserId operation middleware
func (siw *ServerInterfaceWrapper) GetUsersUserId(c *gin.Context) {
@ -519,7 +516,6 @@ func RegisterHandlersWithOptions(router gin.IRouter, si ServerInterface, options
}
router.GET(options.BaseURL+"/title", wrapper.GetTitle)
router.POST(options.BaseURL+"/users", wrapper.PostUsers)
router.GET(options.BaseURL+"/users/:user_id", wrapper.GetUsersUserId)
}
@ -564,27 +560,6 @@ func (response GetTitle500Response) VisitGetTitleResponse(w http.ResponseWriter)
return nil
}
type PostUsersRequestObject struct {
Body *PostUsersJSONRequestBody
}
type PostUsersResponseObject interface {
VisitPostUsersResponse(w http.ResponseWriter) error
}
type PostUsers200JSONResponse struct {
Error *string `json:"error,omitempty"`
Success *bool `json:"success,omitempty"`
UserJson *User `json:"user_json,omitempty"`
}
func (response PostUsers200JSONResponse) VisitPostUsersResponse(w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
return json.NewEncoder(w).Encode(response)
}
type GetUsersUserIdRequestObject struct {
UserId string `json:"user_id"`
Params GetUsersUserIdParams
@ -632,9 +607,6 @@ type StrictServerInterface interface {
// Get titles
// (GET /title)
GetTitle(ctx context.Context, request GetTitleRequestObject) (GetTitleResponseObject, error)
// Add new user
// (POST /users)
PostUsers(ctx context.Context, request PostUsersRequestObject) (PostUsersResponseObject, error)
// Get user info
// (GET /users/{user_id})
GetUsersUserId(ctx context.Context, request GetUsersUserIdRequestObject) (GetUsersUserIdResponseObject, error)
@ -679,39 +651,6 @@ func (sh *strictHandler) GetTitle(ctx *gin.Context, params GetTitleParams) {
}
}
// PostUsers operation middleware
func (sh *strictHandler) PostUsers(ctx *gin.Context) {
var request PostUsersRequestObject
var body PostUsersJSONRequestBody
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.PostUsers(ctx, request.(PostUsersRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "PostUsers")
}
response, err := handler(ctx, request)
if err != nil {
ctx.Error(err)
ctx.Status(http.StatusInternalServerError)
} else if validResponse, ok := response.(PostUsersResponseObject); ok {
if err := validResponse.VisitPostUsersResponse(ctx.Writer); err != nil {
ctx.Error(err)
}
} else if response != nil {
ctx.Error(fmt.Errorf("unexpected response type: %T", response))
}
}
// GetUsersUserId operation middleware
func (sh *strictHandler) GetUsersUserId(ctx *gin.Context, userId string, params GetUsersUserIdParams) {
var request GetUsersUserIdRequestObject

View file

@ -243,28 +243,28 @@ paths:
# items:
# $ref: '#/components/schemas/User'
post:
summary: Add new user
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
'200':
description: Add result
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
error:
type: string
user_json:
$ref: '#/components/schemas/User'
# post:
# summary: Add new user
# requestBody:
# required: true
# content:
# application/json:
# schema:
# $ref: '#/components/schemas/User'
# responses:
# '200':
# description: Add result
# content:
# application/json:
# schema:
# type: object
# properties:
# success:
# type: boolean
# error:
# type: string
# user_json:
# $ref: '#/components/schemas/User'
# /users/{user_id}/titles:
# get:
@ -608,6 +608,8 @@ components:
studio_id:
type: integer
format: int64
studio_name:
type: string
poster_id:
type: integer
format: int64

View file

@ -25,7 +25,7 @@ import (
func mapUser(u sqlc.GetUserByIDRow) oapi.User {
return oapi.User{
AvatarId: u.AvatarID,
CreationDate: u.CreationDate,
CreationDate: &u.CreationDate,
DispName: u.DispName,
Id: &u.ID,
Mail: (*types.Email)(u.Mail),