Compare commits

..

No commits in common. "0cda5970019b455f8ae024c0e7627e49a325a596" and "354c577f7db7e6f82e2478aeb46b1e90bae74efa" have entirely different histories.

7 changed files with 52 additions and 76 deletions

View file

@ -304,8 +304,6 @@ paths:
description: No titles found
'400':
description: Request params are not correct
'404':
description: User not found
'500':
description: Unknown server error
post:

View file

@ -1275,14 +1275,6 @@ func (response GetUsersUserIdTitles400Response) VisitGetUsersUserIdTitlesRespons
return nil
}
type GetUsersUserIdTitles404Response struct {
}
func (response GetUsersUserIdTitles404Response) VisitGetUsersUserIdTitlesResponse(w http.ResponseWriter) error {
w.WriteHeader(404)
return nil
}
type GetUsersUserIdTitles500Response struct {
}

View file

@ -85,8 +85,6 @@ get:
description: No titles found
'400':
description: Request params are not correct
'404':
description: User not found
'500':
description: Unknown server error

View file

@ -125,9 +125,9 @@ func (s Server) mapTitle(ctx context.Context, title sqlc.GetTitleByIDRow) (oapi.
return oapi_title, nil
}
func parseInt64(s string) (int64, error) {
func parseInt64(s string) (int32, error) {
i, err := strconv.ParseInt(s, 10, 64)
return i, err
return int32(i), err
}
func TitleStatus2Sqlc(s *[]oapi.TitleStatus) ([]sqlc.TitleStatusT, error) {

View file

@ -53,7 +53,7 @@ func (s Server) GetUsersUserId(ctx context.Context, req oapi.GetUsersUserIdReque
if err != nil {
return oapi.GetUsersUserId404Response{}, nil
}
_user, err := s.db.GetUserByID(context.TODO(), userID)
_user, err := s.db.GetUserByID(context.TODO(), int64(userID))
if err != nil {
if err == pgx.ErrNoRows {
return oapi.GetUsersUserId404Response{}, nil
@ -243,13 +243,7 @@ func (s Server) GetUsersUserIdTitles(ctx context.Context, request oapi.GetUsersU
return oapi.GetUsersUserIdTitles400Response{}, err
}
userID, err := parseInt64(request.UserId)
if err != nil {
log.Errorf("get user titles: %v", err)
return oapi.GetUsersUserIdTitles404Response{}, err
}
params := sqlc.SearchUserTitlesParams{
UserID: userID,
Word: word,
TitleStatuses: title_statuses,
UsertitleStatuses: watch_status,

View file

@ -21,7 +21,7 @@ SELECT
i.image_path as image_path
FROM users as t
LEFT JOIN images as i ON (t.avatar_id = i.id)
WHERE t.id = sqlc.arg('id')::bigint;
WHERE id = sqlc.arg('id')::bigint;
-- name: GetStudioByID :one
@ -269,8 +269,6 @@ LEFT JOIN tags as g ON (tt.tag_id = g.id)
LEFT JOIN studios as s ON (t.studio_id = s.id)
WHERE
u.user_id = sqlc.arg('user_id')::bigint
AND
CASE
WHEN sqlc.arg('forward')::boolean THEN
-- forward: greater than cursor (next page)
@ -354,7 +352,7 @@ WHERE
AND (sqlc.narg('release_season')::release_season_t IS NULL OR t.release_season = sqlc.narg('release_season')::release_season_t)
GROUP BY
t.id, u.user_id, u.status, u.rate, u.review_id, u.ctime, i.id, s.id
t.id, i.id, s.id
ORDER BY
CASE WHEN sqlc.arg('forward')::boolean THEN

View file

@ -236,7 +236,7 @@ SELECT
i.image_path as image_path
FROM users as t
LEFT JOIN images as i ON (t.avatar_id = i.id)
WHERE t.id = $1::bigint
WHERE id = $1::bigint
`
type GetUserByIDRow struct {
@ -658,45 +658,43 @@ LEFT JOIN tags as g ON (tt.tag_id = g.id)
LEFT JOIN studios as s ON (t.studio_id = s.id)
WHERE
u.user_id = $1::bigint
AND
CASE
WHEN $2::boolean THEN
WHEN $1::boolean THEN
-- forward: greater than cursor (next page)
CASE $3::text
CASE $2::text
WHEN 'year' THEN
($4::int IS NULL) OR
(t.release_year > $4::int) OR
(t.release_year = $4::int AND t.id > $5::bigint)
($3::int IS NULL) OR
(t.release_year > $3::int) OR
(t.release_year = $3::int AND t.id > $4::bigint)
WHEN 'rating' THEN
($6::float IS NULL) OR
(t.rating > $6::float) OR
(t.rating = $6::float AND t.id > $5::bigint)
($5::float IS NULL) OR
(t.rating > $5::float) OR
(t.rating = $5::float AND t.id > $4::bigint)
WHEN 'id' THEN
($5::bigint IS NULL) OR
(t.id > $5::bigint)
($4::bigint IS NULL) OR
(t.id > $4::bigint)
ELSE true -- fallback
END
ELSE
-- backward: less than cursor (prev page)
CASE $3::text
CASE $2::text
WHEN 'year' THEN
($4::int IS NULL) OR
(t.release_year < $4::int) OR
(t.release_year = $4::int AND t.id < $5::bigint)
($3::int IS NULL) OR
(t.release_year < $3::int) OR
(t.release_year = $3::int AND t.id < $4::bigint)
WHEN 'rating' THEN
($6::float IS NULL) OR
(t.rating < $6::float) OR
(t.rating = $6::float AND t.id < $5::bigint)
($5::float IS NULL) OR
(t.rating < $5::float) OR
(t.rating = $5::float AND t.id < $4::bigint)
WHEN 'id' THEN
($5::bigint IS NULL) OR
(t.id < $5::bigint)
($4::bigint IS NULL) OR
(t.id < $4::bigint)
ELSE true
END
@ -704,7 +702,7 @@ WHERE
AND (
CASE
WHEN $7::text IS NOT NULL THEN
WHEN $6::text IS NOT NULL THEN
(
SELECT bool_and(
EXISTS (
@ -716,7 +714,7 @@ WHERE
FROM unnest(
ARRAY(
SELECT '%' || trim(w) || '%'
FROM unnest(string_to_array($7::text, ' ')) AS w
FROM unnest(string_to_array($6::text, ' ')) AS w
WHERE trim(w) <> ''
)
) AS pattern
@ -726,50 +724,49 @@ WHERE
)
AND (
$8::title_status_t[] IS NULL
OR array_length($8::title_status_t[], 1) IS NULL
OR array_length($8::title_status_t[], 1) = 0
OR t.title_status = ANY($8::title_status_t[])
$7::title_status_t[] IS NULL
OR array_length($7::title_status_t[], 1) IS NULL
OR array_length($7::title_status_t[], 1) = 0
OR t.title_status = ANY($7::title_status_t[])
)
AND (
$9::usertitle_status_t[] IS NULL
OR array_length($9::usertitle_status_t[], 1) IS NULL
OR array_length($9::usertitle_status_t[], 1) = 0
OR u.status = ANY($9::usertitle_status_t[])
$8::usertitle_status_t[] IS NULL
OR array_length($8::usertitle_status_t[], 1) IS NULL
OR array_length($8::usertitle_status_t[], 1) = 0
OR u.status = ANY($8::usertitle_status_t[])
)
AND ($10::int IS NULL OR u.rate >= $10::int)
AND ($11::float IS NULL OR t.rating >= $11::float)
AND ($12::int IS NULL OR t.release_year = $12::int)
AND ($13::release_season_t IS NULL OR t.release_season = $13::release_season_t)
AND ($9::int IS NULL OR u.rate >= $9::int)
AND ($10::float IS NULL OR t.rating >= $10::float)
AND ($11::int IS NULL OR t.release_year = $11::int)
AND ($12::release_season_t IS NULL OR t.release_season = $12::release_season_t)
GROUP BY
t.id, u.user_id, u.status, u.rate, u.review_id, u.ctime, i.id, s.id
t.id, i.id, s.id
ORDER BY
CASE WHEN $2::boolean THEN
CASE WHEN $1::boolean THEN
CASE
WHEN $3::text = 'id' THEN t.id
WHEN $3::text = 'year' THEN t.release_year
WHEN $3::text = 'rating' THEN t.rating
WHEN $3::text = 'rate' THEN u.rate
WHEN $2::text = 'id' THEN t.id
WHEN $2::text = 'year' THEN t.release_year
WHEN $2::text = 'rating' THEN t.rating
WHEN $2::text = 'rate' THEN u.rate
END
END ASC,
CASE WHEN NOT $2::boolean THEN
CASE WHEN NOT $1::boolean THEN
CASE
WHEN $3::text = 'id' THEN t.id
WHEN $3::text = 'year' THEN t.release_year
WHEN $3::text = 'rating' THEN t.rating
WHEN $3::text = 'rate' THEN u.rate
WHEN $2::text = 'id' THEN t.id
WHEN $2::text = 'year' THEN t.release_year
WHEN $2::text = 'rating' THEN t.rating
WHEN $2::text = 'rate' THEN u.rate
END
END DESC,
CASE WHEN $3::text <> 'id' THEN t.id END ASC
CASE WHEN $2::text <> 'id' THEN t.id END ASC
LIMIT COALESCE($14::int, 100)
LIMIT COALESCE($13::int, 100)
`
type SearchUserTitlesParams struct {
UserID int64 `json:"user_id"`
Forward bool `json:"forward"`
SortBy string `json:"sort_by"`
CursorYear *int32 `json:"cursor_year"`
@ -811,7 +808,6 @@ type SearchUserTitlesRow struct {
// 100 is default limit
func (q *Queries) SearchUserTitles(ctx context.Context, arg SearchUserTitlesParams) ([]SearchUserTitlesRow, error) {
rows, err := q.db.Query(ctx, searchUserTitles,
arg.UserID,
arg.Forward,
arg.SortBy,
arg.CursorYear,