Compare commits
No commits in common. "1f5196c01521f226a11c6b0a986a36ecb744d20d" and "8d98fb0cf8a8ccb22c7f12520d5462d76100f7e2" have entirely different histories.
1f5196c015
...
8d98fb0cf8
2 changed files with 6 additions and 22 deletions
|
|
@ -38,7 +38,7 @@ func ParseCursorInto(sortBy, cursorStr string, target any) error {
|
||||||
|
|
||||||
// 3. Get reflect value of target (must be ptr to struct)
|
// 3. Get reflect value of target (must be ptr to struct)
|
||||||
v := reflect.ValueOf(target)
|
v := reflect.ValueOf(target)
|
||||||
if v.Kind() != reflect.Pointer || v.IsNil() {
|
if v.Kind() != reflect.Ptr || v.IsNil() {
|
||||||
return fmt.Errorf("target must be non-nil pointer to struct")
|
return fmt.Errorf("target must be non-nil pointer to struct")
|
||||||
}
|
}
|
||||||
v = v.Elem()
|
v = v.Elem()
|
||||||
|
|
@ -56,7 +56,7 @@ func ParseCursorInto(sortBy, cursorStr string, target any) error {
|
||||||
vv := reflect.ValueOf(value)
|
vv := reflect.ValueOf(value)
|
||||||
|
|
||||||
// Case: field is *T, value is T → wrap in pointer
|
// Case: field is *T, value is T → wrap in pointer
|
||||||
if ft.Kind() == reflect.Pointer {
|
if ft.Kind() == reflect.Ptr {
|
||||||
elemType := ft.Elem()
|
elemType := ft.Elem()
|
||||||
if vv.Type().AssignableTo(elemType) {
|
if vv.Type().AssignableTo(elemType) {
|
||||||
ptr := reflect.New(elemType)
|
ptr := reflect.New(elemType)
|
||||||
|
|
@ -143,7 +143,7 @@ func extractInt64(m map[string]any, key string) (int64, error) {
|
||||||
return 0, fmt.Errorf("%q must be integer", key)
|
return 0, fmt.Errorf("%q must be integer", key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractString(m map[string]any, key string) (string, error) {
|
func extractString(m map[string]interface{}, key string) (string, error) {
|
||||||
v, ok := m[key]
|
v, ok := m[key]
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("missing %q", key)
|
return "", fmt.Errorf("missing %q", key)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
oapi "nyanimedb/api"
|
oapi "nyanimedb/api"
|
||||||
sqlc "nyanimedb/sql"
|
sqlc "nyanimedb/sql"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
@ -250,12 +249,11 @@ func (s Server) GetTitles(ctx context.Context, request oapi.GetTitlesRequestObje
|
||||||
ReleaseYear: request.Params.ReleaseYear,
|
ReleaseYear: request.Params.ReleaseYear,
|
||||||
ReleaseSeason: season,
|
ReleaseSeason: season,
|
||||||
Forward: true,
|
Forward: true,
|
||||||
SortBy: "id",
|
// SortBy: "id",
|
||||||
Limit: request.Params.Limit,
|
Limit: request.Params.Limit,
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.Params.Sort != nil {
|
if request.Params.Sort != nil {
|
||||||
params.SortBy = string(*request.Params.Sort)
|
|
||||||
if request.Params.Cursor != nil {
|
if request.Params.Cursor != nil {
|
||||||
err := ParseCursorInto(string(*request.Params.Sort), string(*request.Params.Cursor), ¶ms)
|
err := ParseCursorInto(string(*request.Params.Sort), string(*request.Params.Cursor), ¶ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -274,8 +272,6 @@ func (s Server) GetTitles(ctx context.Context, request oapi.GetTitlesRequestObje
|
||||||
return oapi.GetTitles204Response{}, nil
|
return oapi.GetTitles204Response{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var new_cursor oapi.CursorObj
|
|
||||||
|
|
||||||
for _, title := range titles {
|
for _, title := range titles {
|
||||||
|
|
||||||
t, err := s.mapTitle(ctx, title)
|
t, err := s.mapTitle(ctx, title)
|
||||||
|
|
@ -284,19 +280,7 @@ func (s Server) GetTitles(ctx context.Context, request oapi.GetTitlesRequestObje
|
||||||
return oapi.GetTitles500Response{}, nil
|
return oapi.GetTitles500Response{}, nil
|
||||||
}
|
}
|
||||||
opai_titles = append(opai_titles, t)
|
opai_titles = append(opai_titles, t)
|
||||||
|
|
||||||
new_cursor.Id = t.Id
|
|
||||||
if request.Params.Sort != nil {
|
|
||||||
switch string(*request.Params.Sort) {
|
|
||||||
case "year":
|
|
||||||
tmp := string(*t.ReleaseYear)
|
|
||||||
new_cursor.Param = &tmp
|
|
||||||
case "rating":
|
|
||||||
tmp := strconv.FormatFloat(*t.Rating, 'f', -1, 64)
|
|
||||||
new_cursor.Param = &tmp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return oapi.GetTitles200JSONResponse{Cursor: new_cursor, Data: opai_titles}, nil
|
return oapi.GetTitles200JSONResponse{Cursor: oapi.CursorObj{}, Data: opai_titles}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue