Merge branch 'dev-ars' into dev
All checks were successful
Build and Deploy Go App / build (push) Successful in 5m20s
Build and Deploy Go App / deploy (push) Successful in 26s

This commit is contained in:
Iron_Felix 2025-11-25 04:43:57 +03:00
commit 0cda597001
7 changed files with 76 additions and 52 deletions

View file

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

View file

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

View file

@ -85,6 +85,8 @@ get:
description: No titles found description: No titles found
'400': '400':
description: Request params are not correct description: Request params are not correct
'404':
description: User not found
'500': '500':
description: Unknown server error 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 return oapi_title, nil
} }
func parseInt64(s string) (int32, error) { func parseInt64(s string) (int64, error) {
i, err := strconv.ParseInt(s, 10, 64) i, err := strconv.ParseInt(s, 10, 64)
return int32(i), err return i, err
} }
func TitleStatus2Sqlc(s *[]oapi.TitleStatus) ([]sqlc.TitleStatusT, error) { 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 { if err != nil {
return oapi.GetUsersUserId404Response{}, nil return oapi.GetUsersUserId404Response{}, nil
} }
_user, err := s.db.GetUserByID(context.TODO(), int64(userID)) _user, err := s.db.GetUserByID(context.TODO(), userID)
if err != nil { if err != nil {
if err == pgx.ErrNoRows { if err == pgx.ErrNoRows {
return oapi.GetUsersUserId404Response{}, nil return oapi.GetUsersUserId404Response{}, nil
@ -243,7 +243,13 @@ func (s Server) GetUsersUserIdTitles(ctx context.Context, request oapi.GetUsersU
return oapi.GetUsersUserIdTitles400Response{}, err 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{ params := sqlc.SearchUserTitlesParams{
UserID: userID,
Word: word, Word: word,
TitleStatuses: title_statuses, TitleStatuses: title_statuses,
UsertitleStatuses: watch_status, UsertitleStatuses: watch_status,

View file

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

View file

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