feat: now back sendind real new cursor
This commit is contained in:
parent
af0492cdf1
commit
e16adcf6cd
2 changed files with 22 additions and 6 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
oapi "nyanimedb/api"
|
||||
sqlc "nyanimedb/sql"
|
||||
"strconv"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
|
@ -249,11 +250,12 @@ func (s Server) GetTitles(ctx context.Context, request oapi.GetTitlesRequestObje
|
|||
ReleaseYear: request.Params.ReleaseYear,
|
||||
ReleaseSeason: season,
|
||||
Forward: true,
|
||||
// SortBy: "id",
|
||||
Limit: request.Params.Limit,
|
||||
SortBy: "id",
|
||||
Limit: request.Params.Limit,
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
@ -272,6 +274,8 @@ func (s Server) GetTitles(ctx context.Context, request oapi.GetTitlesRequestObje
|
|||
return oapi.GetTitles204Response{}, nil
|
||||
}
|
||||
|
||||
var new_cursor oapi.CursorObj
|
||||
|
||||
for _, title := range titles {
|
||||
|
||||
t, err := s.mapTitle(ctx, title)
|
||||
|
|
@ -280,7 +284,19 @@ func (s Server) GetTitles(ctx context.Context, request oapi.GetTitlesRequestObje
|
|||
return oapi.GetTitles500Response{}, nil
|
||||
}
|
||||
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: oapi.CursorObj{}, Data: opai_titles}, nil
|
||||
return oapi.GetTitles200JSONResponse{Cursor: new_cursor, Data: opai_titles}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue