fix: type cast fixed
This commit is contained in:
parent
d1937fcbd7
commit
b42fb34903
6 changed files with 84 additions and 65 deletions
|
|
@ -173,7 +173,11 @@ paths:
|
||||||
- in: query
|
- in: query
|
||||||
name: watch_status
|
name: watch_status
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/UserTitleStatus'
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/UserTitleStatus'
|
||||||
|
style: form
|
||||||
|
explode: false
|
||||||
- in: query
|
- in: query
|
||||||
name: rating
|
name: rating
|
||||||
schema:
|
schema:
|
||||||
|
|
|
||||||
|
|
@ -189,14 +189,14 @@ type GetUsersUserIdTitlesParams struct {
|
||||||
Word *string `form:"word,omitempty" json:"word,omitempty"`
|
Word *string `form:"word,omitempty" json:"word,omitempty"`
|
||||||
|
|
||||||
// Status List of title statuses to filter
|
// Status List of title statuses to filter
|
||||||
Status *[]TitleStatus `form:"status,omitempty" json:"status,omitempty"`
|
Status *[]TitleStatus `form:"status,omitempty" json:"status,omitempty"`
|
||||||
WatchStatus *UserTitleStatus `form:"watch_status,omitempty" json:"watch_status,omitempty"`
|
WatchStatus *[]UserTitleStatus `form:"watch_status,omitempty" json:"watch_status,omitempty"`
|
||||||
Rating *float64 `form:"rating,omitempty" json:"rating,omitempty"`
|
Rating *float64 `form:"rating,omitempty" json:"rating,omitempty"`
|
||||||
MyRate *int32 `form:"my_rate,omitempty" json:"my_rate,omitempty"`
|
MyRate *int32 `form:"my_rate,omitempty" json:"my_rate,omitempty"`
|
||||||
ReleaseYear *int32 `form:"release_year,omitempty" json:"release_year,omitempty"`
|
ReleaseYear *int32 `form:"release_year,omitempty" json:"release_year,omitempty"`
|
||||||
ReleaseSeason *ReleaseSeason `form:"release_season,omitempty" json:"release_season,omitempty"`
|
ReleaseSeason *ReleaseSeason `form:"release_season,omitempty" json:"release_season,omitempty"`
|
||||||
Limit *int32 `form:"limit,omitempty" json:"limit,omitempty"`
|
Limit *int32 `form:"limit,omitempty" json:"limit,omitempty"`
|
||||||
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
|
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getter for additional properties for Title. Returns the specified
|
// Getter for additional properties for Title. Returns the specified
|
||||||
|
|
@ -840,7 +840,7 @@ func (siw *ServerInterfaceWrapper) GetUsersUserIdTitles(c *gin.Context) {
|
||||||
|
|
||||||
// ------------- Optional query parameter "watch_status" -------------
|
// ------------- Optional query parameter "watch_status" -------------
|
||||||
|
|
||||||
err = runtime.BindQueryParameter("form", true, false, "watch_status", c.Request.URL.Query(), ¶ms.WatchStatus)
|
err = runtime.BindQueryParameter("form", false, false, "watch_status", c.Request.URL.Query(), ¶ms.WatchStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter watch_status: %w", err), http.StatusBadRequest)
|
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter watch_status: %w", err), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,11 @@ get:
|
||||||
- in: query
|
- in: query
|
||||||
name: watch_status
|
name: watch_status
|
||||||
schema:
|
schema:
|
||||||
$ref: '../schemas/enums/UserTitleStatus.yaml'
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '../schemas/enums/UserTitleStatus.yaml'
|
||||||
|
style: form
|
||||||
|
explode: false
|
||||||
- in: query
|
- in: query
|
||||||
name: rating
|
name: rating
|
||||||
schema:
|
schema:
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ func (s Server) mapTitle(ctx context.Context, title sqlc.GetTitleByIDRow) (oapi.
|
||||||
return oapi.Title{}, fmt.Errorf("unmarshal TitleNames: %v", err)
|
return oapi.Title{}, fmt.Errorf("unmarshal TitleNames: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if title.EpisodesLen != nil && len(title.EpisodesLen) > 0 {
|
if len(title.EpisodesLen) > 0 {
|
||||||
episodes_lens := make(map[string]float64, 0)
|
episodes_lens := make(map[string]float64, 0)
|
||||||
err = json.Unmarshal(title.EpisodesLen, &episodes_lens)
|
err = json.Unmarshal(title.EpisodesLen, &episodes_lens)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -99,3 +99,23 @@ func parseInt64(s string) (int32, error) {
|
||||||
i, err := strconv.ParseInt(s, 10, 64)
|
i, err := strconv.ParseInt(s, 10, 64)
|
||||||
return int32(i), err
|
return int32(i), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TitleStatus2Sqlc(s *[]oapi.TitleStatus) ([]sqlc.TitleStatusT, error) {
|
||||||
|
var sqlc_status []sqlc.TitleStatusT
|
||||||
|
if s == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
for _, t := range *s {
|
||||||
|
switch t {
|
||||||
|
case oapi.TitleStatusFinished:
|
||||||
|
sqlc_status = append(sqlc_status, sqlc.TitleStatusTFinished)
|
||||||
|
case oapi.TitleStatusOngoing:
|
||||||
|
sqlc_status = append(sqlc_status, sqlc.TitleStatusTOngoing)
|
||||||
|
case oapi.TitleStatusPlanned:
|
||||||
|
sqlc_status = append(sqlc_status, sqlc.TitleStatusTPlanned)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unexpected tittle status: %s", t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sqlc_status, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,32 +20,6 @@ func Word2Sqlc(s *string) *string {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
type SqlcStatus struct {
|
|
||||||
ongoing string
|
|
||||||
finished string
|
|
||||||
planned string
|
|
||||||
}
|
|
||||||
|
|
||||||
// func TitleStatus2Sqlc(s *[]oapi.TitleStatus) (*SqlcStatus, error) {
|
|
||||||
// var sqlc_status SqlcStatus
|
|
||||||
// if s == nil {
|
|
||||||
// return &sqlc_status, nil
|
|
||||||
// }
|
|
||||||
// for _, t := range *s {
|
|
||||||
// switch t {
|
|
||||||
// case oapi.TitleStatusFinished:
|
|
||||||
// sqlc_status.finished = "finished"
|
|
||||||
// case oapi.TitleStatusOngoing:
|
|
||||||
// sqlc_status.ongoing = "ongoing"
|
|
||||||
// case oapi.TitleStatusPlanned:
|
|
||||||
// sqlc_status.planned = "planned"
|
|
||||||
// default:
|
|
||||||
// return nil, fmt.Errorf("unexpected tittle status: %s", t)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return &sqlc_status, nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
func TitleStatus2oapi(s *sqlc.TitleStatusT) (*oapi.TitleStatus, error) {
|
func TitleStatus2oapi(s *sqlc.TitleStatusT) (*oapi.TitleStatus, error) {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
@ -190,17 +164,15 @@ func (s Server) GetTitles(ctx context.Context, request oapi.GetTitlesRequestObje
|
||||||
return oapi.GetTitles400Response{}, err
|
return oapi.GetTitles400Response{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var statuses_sort []string
|
title_statuses, err := TitleStatus2Sqlc(request.Params.Status)
|
||||||
if request.Params.Status != nil {
|
if err != nil {
|
||||||
for _, s := range *request.Params.Status {
|
log.Errorf("%v", err)
|
||||||
ss := string(s) // s type is alias for string
|
return oapi.GetTitles400Response{}, err
|
||||||
statuses_sort = append(statuses_sort, ss)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
params := sqlc.SearchTitlesParams{
|
params := sqlc.SearchTitlesParams{
|
||||||
Word: word,
|
Word: word,
|
||||||
TitleStatuses: statuses_sort,
|
TitleStatuses: title_statuses,
|
||||||
Rating: request.Params.Rating,
|
Rating: request.Params.Rating,
|
||||||
ReleaseYear: request.Params.ReleaseYear,
|
ReleaseYear: request.Params.ReleaseYear,
|
||||||
ReleaseSeason: season,
|
ReleaseSeason: season,
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,6 @@ func sqlDate2oapi(p_date pgtype.Timestamptz) *time.Time {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type SqlcUserStatus struct {
|
|
||||||
dropped string
|
|
||||||
finished string
|
|
||||||
planned string
|
|
||||||
in_progress string
|
|
||||||
}
|
|
||||||
|
|
||||||
// func UserTitleStatus2Sqlc(s *[]oapi.UserTitleStatus) (*SqlcUserStatus, error) {
|
// func UserTitleStatus2Sqlc(s *[]oapi.UserTitleStatus) (*SqlcUserStatus, error) {
|
||||||
// var sqlc_status SqlcUserStatus
|
// var sqlc_status SqlcUserStatus
|
||||||
// if s == nil {
|
// if s == nil {
|
||||||
|
|
@ -110,6 +103,28 @@ func sql2usertitlestatus(s sqlc.UsertitleStatusT) (oapi.UserTitleStatus, error)
|
||||||
return status, nil
|
return status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UserTitleStatus2Sqlc(s *[]oapi.UserTitleStatus) ([]sqlc.UsertitleStatusT, error) {
|
||||||
|
var sqlc_status []sqlc.UsertitleStatusT
|
||||||
|
if s == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
for _, t := range *s {
|
||||||
|
switch t {
|
||||||
|
case oapi.UserTitleStatusFinished:
|
||||||
|
sqlc_status = append(sqlc_status, sqlc.UsertitleStatusTFinished)
|
||||||
|
case oapi.UserTitleStatusInProgress:
|
||||||
|
sqlc_status = append(sqlc_status, sqlc.UsertitleStatusTInProgress)
|
||||||
|
case oapi.UserTitleStatusDropped:
|
||||||
|
sqlc_status = append(sqlc_status, sqlc.UsertitleStatusTDropped)
|
||||||
|
case oapi.UserTitleStatusPlanned:
|
||||||
|
sqlc_status = append(sqlc_status, sqlc.UsertitleStatusTPlanned)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unexpected tittle status: %s", t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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{
|
||||||
|
|
@ -171,25 +186,29 @@ func (s Server) GetUsersUserIdTitles(ctx context.Context, request oapi.GetUsersU
|
||||||
return oapi.GetUsersUserIdTitles400Response{}, err
|
return oapi.GetUsersUserIdTitles400Response{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var statuses_sort []string
|
// var statuses_sort []string
|
||||||
if request.Params.Status != nil {
|
// if request.Params.Status != nil {
|
||||||
for _, s := range *request.Params.Status {
|
// for _, s := range *request.Params.Status {
|
||||||
ss := string(s) // s type is alias for string
|
// ss := string(s) // s type is alias for string
|
||||||
statuses_sort = append(statuses_sort, ss)
|
// statuses_sort = append(statuses_sort, ss)
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
watch_status, err := UserTitleStatus2Sqlc(request.Params.WatchStatus)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("%v", err)
|
||||||
|
return oapi.GetUsersUserIdTitles400Response{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var watch_status []string
|
title_statuses, err := TitleStatus2Sqlc(request.Params.Status)
|
||||||
if request.Params.WatchStatus != nil {
|
if err != nil {
|
||||||
for _, s := range *request.Params.WatchStatus {
|
log.Errorf("%v", err)
|
||||||
ss := string(s) // s type is alias for string
|
return oapi.GetUsersUserIdTitles400Response{}, err
|
||||||
watch_status = append(statuses_sort, ss)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
params := sqlc.SearchUserTitlesParams{
|
params := sqlc.SearchUserTitlesParams{
|
||||||
Word: word,
|
Word: word,
|
||||||
TitleStatuses: statuses_sort,
|
TitleStatuses: title_statuses,
|
||||||
UsertitleStatuses: watch_status,
|
UsertitleStatuses: watch_status,
|
||||||
Rating: request.Params.Rating,
|
Rating: request.Params.Rating,
|
||||||
Rate: request.Params.MyRate,
|
Rate: request.Params.MyRate,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue