feat: query for usertitles written
This commit is contained in:
parent
ba68b5ee04
commit
32566fe7a2
8 changed files with 497 additions and 250 deletions
|
|
@ -2,12 +2,15 @@ package handlers
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
oapi "nyanimedb/api"
|
||||
sqlc "nyanimedb/sql"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/oapi-codegen/runtime/types"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// type Server struct {
|
||||
|
|
@ -50,33 +53,120 @@ func (s Server) GetUsersUserId(ctx context.Context, req oapi.GetUsersUserIdReque
|
|||
return oapi.GetUsersUserId200JSONResponse(mapUser(user)), nil
|
||||
}
|
||||
|
||||
func sqlDate2oapi(p_date pgtype.Timestamptz) (time.Time, error) {
|
||||
return time.Time{}, nil
|
||||
}
|
||||
|
||||
type SqlcUserStatus struct {
|
||||
dropped string
|
||||
finished string
|
||||
planned string
|
||||
in_progress string
|
||||
}
|
||||
|
||||
func UserTitleStatus2Sqlc(s *[]oapi.UserTitleStatus) (*SqlcUserStatus, error) {
|
||||
var sqlc_status SqlcUserStatus
|
||||
if s == nil {
|
||||
return &sqlc_status, nil
|
||||
}
|
||||
for _, t := range *s {
|
||||
switch t {
|
||||
case oapi.UserTitleStatusFinished:
|
||||
sqlc_status.finished = "finished"
|
||||
case oapi.UserTitleStatusDropped:
|
||||
sqlc_status.dropped = "dropped"
|
||||
case oapi.UserTitleStatusPlanned:
|
||||
sqlc_status.planned = "planned"
|
||||
case oapi.UserTitleStatusInProgress:
|
||||
sqlc_status.in_progress = "in-progress"
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected tittle status: %s", t)
|
||||
}
|
||||
}
|
||||
return &sqlc_status, nil
|
||||
}
|
||||
|
||||
func (s Server) GetUsersUserIdTitles(ctx context.Context, request oapi.GetUsersUserIdTitlesRequestObject) (oapi.GetUsersUserIdTitlesResponseObject, error) {
|
||||
|
||||
var rate int32 = 9
|
||||
var review_id int64 = 3
|
||||
time := time.Date(2025, 1, 15, 10, 30, 0, 0, time.UTC)
|
||||
oapi_usertitles := make([]oapi.UserTitle, 0)
|
||||
|
||||
var userTitles = []oapi.UserTitle{
|
||||
{
|
||||
UserId: 101,
|
||||
TitleId: 2001,
|
||||
Status: oapi.UserTitleStatusFinished,
|
||||
Rate: &rate,
|
||||
Ctime: &time,
|
||||
},
|
||||
{
|
||||
UserId: 102,
|
||||
TitleId: 2002,
|
||||
Status: oapi.UserTitleStatusInProgress,
|
||||
ReviewId: &review_id,
|
||||
Ctime: &time,
|
||||
},
|
||||
{
|
||||
UserId: 103,
|
||||
TitleId: 2003,
|
||||
Status: oapi.UserTitleStatusDropped,
|
||||
Ctime: &time,
|
||||
},
|
||||
word := Word2Sqlc(request.Params.Word)
|
||||
status, err := TitleStatus2Sqlc(request.Params.Status)
|
||||
if err != nil {
|
||||
log.Errorf("%v", err)
|
||||
return oapi.GetUsersUserIdTitles400Response{}, err
|
||||
}
|
||||
|
||||
season, err := ReleaseSeason2sqlc(request.Params.ReleaseSeason)
|
||||
if err != nil {
|
||||
log.Errorf("%v", err)
|
||||
return oapi.GetUsersUserIdTitles400Response{}, err
|
||||
}
|
||||
|
||||
// Forward bool `json:"forward"`
|
||||
// SortBy string `json:"sort_by"`
|
||||
// CursorYear *int32 `json:"cursor_year"`
|
||||
// CursorID *int64 `json:"cursor_id"`
|
||||
// CursorRating *float64 `json:"cursor_rating"`
|
||||
// Word *string `json:"word"`
|
||||
// Ongoing string `json:"ongoing"`
|
||||
// Planned string `json:"planned"`
|
||||
// Dropped string `json:"dropped"`
|
||||
// InProgress string `json:"in-progress"`
|
||||
// Finished string `json:"finished"`
|
||||
// Rate *int32 `json:"rate"`
|
||||
// Rating *float64 `json:"rating"`
|
||||
// ReleaseYear *int32 `json:"release_year"`
|
||||
// ReleaseSeason *ReleaseSeasonT `json:"release_season"`
|
||||
// Limit *int32 `json:"limit"`
|
||||
params := sqlc.SearchTitlesParams{
|
||||
Word: word,
|
||||
Ongoing: status.ongoing,
|
||||
Finished: status.finished,
|
||||
Planned: status.planned,
|
||||
Rating: request.Params.Rating,
|
||||
ReleaseYear: request.Params.ReleaseYear,
|
||||
ReleaseSeason: season,
|
||||
Forward: true,
|
||||
SortBy: "id",
|
||||
Limit: request.Params.Limit,
|
||||
}
|
||||
|
||||
if request.Params.SortForward != nil {
|
||||
params.Forward = *request.Params.SortForward
|
||||
}
|
||||
if request.Params.Sort != nil {
|
||||
params.SortBy = string(*request.Params.Sort)
|
||||
if request.Params.Cursor != nil {
|
||||
err := ParseCursorInto(string(*request.Params.Sort), string(*request.Params.Cursor), ¶ms)
|
||||
if err != nil {
|
||||
log.Errorf("%v", err)
|
||||
return oapi.GetTitles400Response{}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_sqlc_title := sqlc.SearchTitlesRow{
|
||||
ID: sqlc_title.ID,
|
||||
StudioID: sqlc_title.StudioID,
|
||||
PosterID: sqlc_title.PosterID,
|
||||
TitleStatus: sqlc_title.TitleStatus,
|
||||
Rating: sqlc_title.Rating,
|
||||
RatingCount: sqlc_title.RatingCount,
|
||||
ReleaseYear: sqlc_title.ReleaseYear,
|
||||
ReleaseSeason: sqlc_title.ReleaseSeason,
|
||||
Season: sqlc_title.Season,
|
||||
EpisodesAired: sqlc_title.EpisodesAired,
|
||||
EpisodesAll: sqlc_title.EpisodesAll,
|
||||
EpisodesLen: sqlc_title.EpisodesLen,
|
||||
TitleStorageType: sqlc_title.TitleStorageType,
|
||||
TitleImagePath: sqlc_title.TitleImagePath,
|
||||
TagNames: sqlc_title.TitleNames,
|
||||
StudioName: sqlc_title.StudioName,
|
||||
StudioIllustID: sqlc_title.StudioIllustID,
|
||||
StudioDesc: sqlc_title.StudioDesc,
|
||||
StudioStorageType: sqlc_title.StudioStorageType,
|
||||
StudioImagePath: sqlc_title.StudioImagePath,
|
||||
}
|
||||
|
||||
return oapi.GetUsersUserIdTitles200JSONResponse(userTitles), nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue