feat /users path is specified
This commit is contained in:
parent
40e341c05a
commit
fe18c0d865
4 changed files with 226 additions and 0 deletions
|
|
@ -122,6 +122,53 @@ paths:
|
||||||
description: Unknown server error
|
description: Unknown server error
|
||||||
security:
|
security:
|
||||||
- JwtAuthCookies: []
|
- JwtAuthCookies: []
|
||||||
|
/users/:
|
||||||
|
get:
|
||||||
|
summary: 'Search user by nickname or dispname (both in one param), response is always sorted by id'
|
||||||
|
parameters:
|
||||||
|
- name: word
|
||||||
|
in: query
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
- name: limit
|
||||||
|
in: query
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
default: 10
|
||||||
|
- name: cursor_id
|
||||||
|
in: query
|
||||||
|
description: pass cursor naked
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
default: 1
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: List of users with cursor
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
description: List of users
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/User'
|
||||||
|
cursor:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
default: 1
|
||||||
|
required:
|
||||||
|
- data
|
||||||
|
- cursor
|
||||||
|
'204':
|
||||||
|
description: No users found
|
||||||
|
'400':
|
||||||
|
description: Request params are not correct
|
||||||
|
'500':
|
||||||
|
description: Unknown server error
|
||||||
'/users/{user_id}':
|
'/users/{user_id}':
|
||||||
get:
|
get:
|
||||||
operationId: getUsersId
|
operationId: getUsersId
|
||||||
|
|
|
||||||
131
api/api.gen.go
131
api/api.gen.go
|
|
@ -201,6 +201,15 @@ type GetTitleParams struct {
|
||||||
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
|
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUsersParams defines parameters for GetUsers.
|
||||||
|
type GetUsersParams struct {
|
||||||
|
Word *string `form:"word,omitempty" json:"word,omitempty"`
|
||||||
|
Limit *int32 `form:"limit,omitempty" json:"limit,omitempty"`
|
||||||
|
|
||||||
|
// CursorId pass cursor naked
|
||||||
|
CursorId *int32 `form:"cursor_id,omitempty" json:"cursor_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// GetUsersIdParams defines parameters for GetUsersId.
|
// GetUsersIdParams defines parameters for GetUsersId.
|
||||||
type GetUsersIdParams struct {
|
type GetUsersIdParams struct {
|
||||||
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
|
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
|
||||||
|
|
@ -276,6 +285,9 @@ type ServerInterface interface {
|
||||||
// Get title description
|
// Get title description
|
||||||
// (GET /titles/{title_id})
|
// (GET /titles/{title_id})
|
||||||
GetTitle(c *gin.Context, titleId int64, params GetTitleParams)
|
GetTitle(c *gin.Context, titleId int64, params GetTitleParams)
|
||||||
|
// Search user by nickname or dispname (both in one param), response is always sorted by id
|
||||||
|
// (GET /users/)
|
||||||
|
GetUsers(c *gin.Context, params GetUsersParams)
|
||||||
// Get user info
|
// Get user info
|
||||||
// (GET /users/{user_id})
|
// (GET /users/{user_id})
|
||||||
GetUsersId(c *gin.Context, userId string, params GetUsersIdParams)
|
GetUsersId(c *gin.Context, userId string, params GetUsersIdParams)
|
||||||
|
|
@ -459,6 +471,48 @@ func (siw *ServerInterfaceWrapper) GetTitle(c *gin.Context) {
|
||||||
siw.Handler.GetTitle(c, titleId, params)
|
siw.Handler.GetTitle(c, titleId, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUsers operation middleware
|
||||||
|
func (siw *ServerInterfaceWrapper) GetUsers(c *gin.Context) {
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// Parameter object where we will unmarshal all parameters from the context
|
||||||
|
var params GetUsersParams
|
||||||
|
|
||||||
|
// ------------- Optional query parameter "word" -------------
|
||||||
|
|
||||||
|
err = runtime.BindQueryParameter("form", true, false, "word", c.Request.URL.Query(), ¶ms.Word)
|
||||||
|
if err != nil {
|
||||||
|
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter word: %w", err), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------- Optional query parameter "limit" -------------
|
||||||
|
|
||||||
|
err = runtime.BindQueryParameter("form", true, false, "limit", c.Request.URL.Query(), ¶ms.Limit)
|
||||||
|
if err != nil {
|
||||||
|
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter limit: %w", err), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------- Optional query parameter "cursor_id" -------------
|
||||||
|
|
||||||
|
err = runtime.BindQueryParameter("form", true, false, "cursor_id", c.Request.URL.Query(), ¶ms.CursorId)
|
||||||
|
if err != nil {
|
||||||
|
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter cursor_id: %w", err), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, middleware := range siw.HandlerMiddlewares {
|
||||||
|
middleware(c)
|
||||||
|
if c.IsAborted() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
siw.Handler.GetUsers(c, params)
|
||||||
|
}
|
||||||
|
|
||||||
// GetUsersId operation middleware
|
// GetUsersId operation middleware
|
||||||
func (siw *ServerInterfaceWrapper) GetUsersId(c *gin.Context) {
|
func (siw *ServerInterfaceWrapper) GetUsersId(c *gin.Context) {
|
||||||
|
|
||||||
|
|
@ -799,6 +853,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.GetTitle)
|
router.GET(options.BaseURL+"/titles/:title_id", wrapper.GetTitle)
|
||||||
|
router.GET(options.BaseURL+"/users/", wrapper.GetUsers)
|
||||||
router.GET(options.BaseURL+"/users/:user_id", wrapper.GetUsersId)
|
router.GET(options.BaseURL+"/users/:user_id", wrapper.GetUsersId)
|
||||||
router.PATCH(options.BaseURL+"/users/:user_id", wrapper.UpdateUser)
|
router.PATCH(options.BaseURL+"/users/:user_id", wrapper.UpdateUser)
|
||||||
router.GET(options.BaseURL+"/users/:user_id/titles", wrapper.GetUserTitles)
|
router.GET(options.BaseURL+"/users/:user_id/titles", wrapper.GetUserTitles)
|
||||||
|
|
@ -904,6 +959,52 @@ func (response GetTitle500Response) VisitGetTitleResponse(w http.ResponseWriter)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetUsersRequestObject struct {
|
||||||
|
Params GetUsersParams
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetUsersResponseObject interface {
|
||||||
|
VisitGetUsersResponse(w http.ResponseWriter) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetUsers200JSONResponse struct {
|
||||||
|
Cursor int64 `json:"cursor"`
|
||||||
|
|
||||||
|
// Data List of users
|
||||||
|
Data []User `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (response GetUsers200JSONResponse) VisitGetUsersResponse(w http.ResponseWriter) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(200)
|
||||||
|
|
||||||
|
return json.NewEncoder(w).Encode(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetUsers204Response struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (response GetUsers204Response) VisitGetUsersResponse(w http.ResponseWriter) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetUsers400Response struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (response GetUsers400Response) VisitGetUsersResponse(w http.ResponseWriter) error {
|
||||||
|
w.WriteHeader(400)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetUsers500Response struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (response GetUsers500Response) VisitGetUsersResponse(w http.ResponseWriter) error {
|
||||||
|
w.WriteHeader(500)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type GetUsersIdRequestObject struct {
|
type GetUsersIdRequestObject struct {
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
Params GetUsersIdParams
|
Params GetUsersIdParams
|
||||||
|
|
@ -1305,6 +1406,9 @@ type StrictServerInterface interface {
|
||||||
// Get title description
|
// Get title description
|
||||||
// (GET /titles/{title_id})
|
// (GET /titles/{title_id})
|
||||||
GetTitle(ctx context.Context, request GetTitleRequestObject) (GetTitleResponseObject, error)
|
GetTitle(ctx context.Context, request GetTitleRequestObject) (GetTitleResponseObject, error)
|
||||||
|
// Search user by nickname or dispname (both in one param), response is always sorted by id
|
||||||
|
// (GET /users/)
|
||||||
|
GetUsers(ctx context.Context, request GetUsersRequestObject) (GetUsersResponseObject, error)
|
||||||
// Get user info
|
// Get user info
|
||||||
// (GET /users/{user_id})
|
// (GET /users/{user_id})
|
||||||
GetUsersId(ctx context.Context, request GetUsersIdRequestObject) (GetUsersIdResponseObject, error)
|
GetUsersId(ctx context.Context, request GetUsersIdRequestObject) (GetUsersIdResponseObject, error)
|
||||||
|
|
@ -1395,6 +1499,33 @@ func (sh *strictHandler) GetTitle(ctx *gin.Context, titleId int64, params GetTit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUsers operation middleware
|
||||||
|
func (sh *strictHandler) GetUsers(ctx *gin.Context, params GetUsersParams) {
|
||||||
|
var request GetUsersRequestObject
|
||||||
|
|
||||||
|
request.Params = params
|
||||||
|
|
||||||
|
handler := func(ctx *gin.Context, request interface{}) (interface{}, error) {
|
||||||
|
return sh.ssi.GetUsers(ctx, request.(GetUsersRequestObject))
|
||||||
|
}
|
||||||
|
for _, middleware := range sh.middlewares {
|
||||||
|
handler = middleware(handler, "GetUsers")
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := handler(ctx, request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(err)
|
||||||
|
ctx.Status(http.StatusInternalServerError)
|
||||||
|
} else if validResponse, ok := response.(GetUsersResponseObject); ok {
|
||||||
|
if err := validResponse.VisitGetUsersResponse(ctx.Writer); err != nil {
|
||||||
|
ctx.Error(err)
|
||||||
|
}
|
||||||
|
} else if response != nil {
|
||||||
|
ctx.Error(fmt.Errorf("unexpected response type: %T", response))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetUsersId operation middleware
|
// GetUsersId operation middleware
|
||||||
func (sh *strictHandler) GetUsersId(ctx *gin.Context, userId string, params GetUsersIdParams) {
|
func (sh *strictHandler) GetUsersId(ctx *gin.Context, userId string, params GetUsersIdParams) {
|
||||||
var request GetUsersIdRequestObject
|
var request GetUsersIdRequestObject
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ paths:
|
||||||
$ref: "./paths/titles.yaml"
|
$ref: "./paths/titles.yaml"
|
||||||
/titles/{title_id}:
|
/titles/{title_id}:
|
||||||
$ref: "./paths/titles-id.yaml"
|
$ref: "./paths/titles-id.yaml"
|
||||||
|
/users/:
|
||||||
|
$ref: "./paths/users.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:
|
||||||
|
|
|
||||||
46
api/paths/users.yaml
Normal file
46
api/paths/users.yaml
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
get:
|
||||||
|
summary: Search user by nickname or dispname (both in one param), response is always sorted by id
|
||||||
|
parameters:
|
||||||
|
- in: query
|
||||||
|
name: word
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
- in: query
|
||||||
|
name: limit
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
default: 10
|
||||||
|
- in: query
|
||||||
|
name: cursor_id
|
||||||
|
description: pass cursor naked
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
default: 1
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: List of users with cursor
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '../schemas/User.yaml'
|
||||||
|
description: List of users
|
||||||
|
cursor:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
default: 1
|
||||||
|
required:
|
||||||
|
- data
|
||||||
|
- cursor
|
||||||
|
'204':
|
||||||
|
description: No users found
|
||||||
|
'400':
|
||||||
|
description: Request params are not correct
|
||||||
|
'500':
|
||||||
|
description: Unknown server error
|
||||||
Loading…
Add table
Add a link
Reference in a new issue