Merge branch 'dev-ars' into dev
This commit is contained in:
commit
0cda597001
7 changed files with 76 additions and 52 deletions
|
|
@ -304,6 +304,8 @@ paths:
|
|||
description: No titles found
|
||||
'400':
|
||||
description: Request params are not correct
|
||||
'404':
|
||||
description: User not found
|
||||
'500':
|
||||
description: Unknown server error
|
||||
post:
|
||||
|
|
|
|||
|
|
@ -1275,6 +1275,14 @@ 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 {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,6 +85,8 @@ get:
|
|||
description: No titles found
|
||||
'400':
|
||||
description: Request params are not correct
|
||||
'404':
|
||||
description: User not found
|
||||
'500':
|
||||
description: Unknown server error
|
||||
|
||||
|
|
|
|||
|
|
@ -125,9 +125,9 @@ func (s Server) mapTitle(ctx context.Context, title sqlc.GetTitleByIDRow) (oapi.
|
|||
return oapi_title, nil
|
||||
}
|
||||
|
||||
func parseInt64(s string) (int32, error) {
|
||||
func parseInt64(s string) (int64, error) {
|
||||
i, err := strconv.ParseInt(s, 10, 64)
|
||||
return int32(i), err
|
||||
return i, err
|
||||
}
|
||||
|
||||
func TitleStatus2Sqlc(s *[]oapi.TitleStatus) ([]sqlc.TitleStatusT, error) {
|
||||
|
|
|
|||
|
|
@ -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(), int64(userID))
|
||||
_user, err := s.db.GetUserByID(context.TODO(), userID)
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
return oapi.GetUsersUserId404Response{}, nil
|
||||
|
|
@ -243,7 +243,13 @@ 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,
|
||||
|
|
|
|||
|
|
@ -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 id = sqlc.arg('id')::bigint;
|
||||
WHERE t.id = sqlc.arg('id')::bigint;
|
||||
|
||||
|
||||
-- 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)
|
||||
|
||||
WHERE
|
||||
u.user_id = sqlc.arg('user_id')::bigint
|
||||
AND
|
||||
CASE
|
||||
WHEN sqlc.arg('forward')::boolean THEN
|
||||
-- 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)
|
||||
|
||||
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
|
||||
CASE WHEN sqlc.arg('forward')::boolean THEN
|
||||
|
|
|
|||
|
|
@ -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 id = $1::bigint
|
||||
WHERE t.id = $1::bigint
|
||||
`
|
||||
|
||||
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)
|
||||
|
||||
WHERE
|
||||
u.user_id = $1::bigint
|
||||
AND
|
||||
CASE
|
||||
WHEN $1::boolean THEN
|
||||
WHEN $2::boolean THEN
|
||||
-- forward: greater than cursor (next page)
|
||||
CASE $2::text
|
||||
CASE $3::text
|
||||
WHEN 'year' THEN
|
||||
($3::int IS NULL) OR
|
||||
(t.release_year > $3::int) OR
|
||||
(t.release_year = $3::int AND t.id > $4::bigint)
|
||||
($4::int IS NULL) OR
|
||||
(t.release_year > $4::int) OR
|
||||
(t.release_year = $4::int AND t.id > $5::bigint)
|
||||
|
||||
WHEN 'rating' THEN
|
||||
($5::float IS NULL) OR
|
||||
(t.rating > $5::float) OR
|
||||
(t.rating = $5::float AND t.id > $4::bigint)
|
||||
($6::float IS NULL) OR
|
||||
(t.rating > $6::float) OR
|
||||
(t.rating = $6::float AND t.id > $5::bigint)
|
||||
|
||||
WHEN 'id' THEN
|
||||
($4::bigint IS NULL) OR
|
||||
(t.id > $4::bigint)
|
||||
($5::bigint IS NULL) OR
|
||||
(t.id > $5::bigint)
|
||||
|
||||
ELSE true -- fallback
|
||||
END
|
||||
|
||||
ELSE
|
||||
-- backward: less than cursor (prev page)
|
||||
CASE $2::text
|
||||
CASE $3::text
|
||||
WHEN 'year' THEN
|
||||
($3::int IS NULL) OR
|
||||
(t.release_year < $3::int) OR
|
||||
(t.release_year = $3::int AND t.id < $4::bigint)
|
||||
($4::int IS NULL) OR
|
||||
(t.release_year < $4::int) OR
|
||||
(t.release_year = $4::int AND t.id < $5::bigint)
|
||||
|
||||
WHEN 'rating' THEN
|
||||
($5::float IS NULL) OR
|
||||
(t.rating < $5::float) OR
|
||||
(t.rating = $5::float AND t.id < $4::bigint)
|
||||
($6::float IS NULL) OR
|
||||
(t.rating < $6::float) OR
|
||||
(t.rating = $6::float AND t.id < $5::bigint)
|
||||
|
||||
WHEN 'id' THEN
|
||||
($4::bigint IS NULL) OR
|
||||
(t.id < $4::bigint)
|
||||
($5::bigint IS NULL) OR
|
||||
(t.id < $5::bigint)
|
||||
|
||||
ELSE true
|
||||
END
|
||||
|
|
@ -702,7 +704,7 @@ WHERE
|
|||
|
||||
AND (
|
||||
CASE
|
||||
WHEN $6::text IS NOT NULL THEN
|
||||
WHEN $7::text IS NOT NULL THEN
|
||||
(
|
||||
SELECT bool_and(
|
||||
EXISTS (
|
||||
|
|
@ -714,7 +716,7 @@ WHERE
|
|||
FROM unnest(
|
||||
ARRAY(
|
||||
SELECT '%' || trim(w) || '%'
|
||||
FROM unnest(string_to_array($6::text, ' ')) AS w
|
||||
FROM unnest(string_to_array($7::text, ' ')) AS w
|
||||
WHERE trim(w) <> ''
|
||||
)
|
||||
) AS pattern
|
||||
|
|
@ -724,49 +726,50 @@ WHERE
|
|||
)
|
||||
|
||||
AND (
|
||||
$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[])
|
||||
$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[])
|
||||
)
|
||||
AND (
|
||||
$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[])
|
||||
$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[])
|
||||
)
|
||||
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)
|
||||
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)
|
||||
|
||||
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
|
||||
CASE WHEN $1::boolean THEN
|
||||
CASE WHEN $2::boolean THEN
|
||||
CASE
|
||||
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
|
||||
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
|
||||
END
|
||||
END ASC,
|
||||
CASE WHEN NOT $1::boolean THEN
|
||||
CASE WHEN NOT $2::boolean THEN
|
||||
CASE
|
||||
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
|
||||
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
|
||||
END
|
||||
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 {
|
||||
UserID int64 `json:"user_id"`
|
||||
Forward bool `json:"forward"`
|
||||
SortBy string `json:"sort_by"`
|
||||
CursorYear *int32 `json:"cursor_year"`
|
||||
|
|
@ -808,6 +811,7 @@ 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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue