fix: fix GetUserTitleByID
This commit is contained in:
parent
3f0456ba01
commit
37cdc32d5d
4 changed files with 8 additions and 105 deletions
|
|
@ -479,7 +479,7 @@ func (s Server) GetUserTitle(ctx context.Context, request oapi.GetUserTitleReque
|
|||
Rate: user_title.Rate,
|
||||
ReviewId: user_title.ReviewID,
|
||||
Status: oapi_status,
|
||||
TitleId: *user_title.ID,
|
||||
TitleId: user_title.TitleID,
|
||||
UserId: user_title.UserID,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func main() {
|
|||
|
||||
r.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"*"}, // allow all origins, change to specific domains in production
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH"},
|
||||
AllowHeaders: []string{"Origin", "Content-Type", "Accept"},
|
||||
ExposeHeaders: []string{"Content-Length"},
|
||||
AllowCredentials: true,
|
||||
|
|
|
|||
|
|
@ -398,29 +398,6 @@ RETURNING *;
|
|||
|
||||
-- name: GetUserTitleByID :one
|
||||
SELECT
|
||||
ut.*,
|
||||
t.*,
|
||||
i.storage_type as title_storage_type,
|
||||
i.image_path as title_image_path,
|
||||
COALESCE(
|
||||
jsonb_agg(g.tag_names) FILTER (WHERE g.tag_names IS NOT NULL),
|
||||
'[]'::jsonb
|
||||
)::jsonb as tag_names,
|
||||
s.studio_name as studio_name,
|
||||
s.illust_id as studio_illust_id,
|
||||
s.studio_desc as studio_desc,
|
||||
si.storage_type as studio_storage_type,
|
||||
si.image_path as studio_image_path
|
||||
|
||||
ut.*
|
||||
FROM usertitles as ut
|
||||
LEFT JOIN users as u ON (ut.user_id = u.id)
|
||||
LEFT JOIN titles as t ON (ut.title_id = t.id)
|
||||
LEFT JOIN images as i ON (t.poster_id = i.id)
|
||||
LEFT JOIN title_tags as tt ON (t.id = tt.title_id)
|
||||
LEFT JOIN tags as g ON (tt.tag_id = g.id)
|
||||
LEFT JOIN studios as s ON (t.studio_id = s.id)
|
||||
LEFT JOIN images as si ON (s.illust_id = si.id)
|
||||
|
||||
WHERE t.id = sqlc.arg('title_id')::bigint AND u.id = sqlc.arg('user_id')::bigint
|
||||
GROUP BY
|
||||
t.id, i.id, s.id, si.id;
|
||||
WHERE ut.title_id = sqlc.arg('title_id')::bigint AND ut.user_id = sqlc.arg('user_id')::bigint;
|
||||
|
|
@ -306,32 +306,9 @@ func (q *Queries) GetUserByNickname(ctx context.Context, nickname string) (User,
|
|||
|
||||
const getUserTitleByID = `-- name: GetUserTitleByID :one
|
||||
SELECT
|
||||
ut.user_id, ut.title_id, ut.status, ut.rate, ut.review_id, ut.ctime,
|
||||
t.id, t.title_names, t.studio_id, t.poster_id, t.title_status, t.rating, t.rating_count, t.release_year, t.release_season, t.season, t.episodes_aired, t.episodes_all, t.episodes_len,
|
||||
i.storage_type as title_storage_type,
|
||||
i.image_path as title_image_path,
|
||||
COALESCE(
|
||||
jsonb_agg(g.tag_names) FILTER (WHERE g.tag_names IS NOT NULL),
|
||||
'[]'::jsonb
|
||||
)::jsonb as tag_names,
|
||||
s.studio_name as studio_name,
|
||||
s.illust_id as studio_illust_id,
|
||||
s.studio_desc as studio_desc,
|
||||
si.storage_type as studio_storage_type,
|
||||
si.image_path as studio_image_path
|
||||
|
||||
ut.user_id, ut.title_id, ut.status, ut.rate, ut.review_id, ut.ctime
|
||||
FROM usertitles as ut
|
||||
LEFT JOIN users as u ON (ut.user_id = u.id)
|
||||
LEFT JOIN titles as t ON (ut.title_id = t.id)
|
||||
LEFT JOIN images as i ON (t.poster_id = i.id)
|
||||
LEFT JOIN title_tags as tt ON (t.id = tt.title_id)
|
||||
LEFT JOIN tags as g ON (tt.tag_id = g.id)
|
||||
LEFT JOIN studios as s ON (t.studio_id = s.id)
|
||||
LEFT JOIN images as si ON (s.illust_id = si.id)
|
||||
|
||||
WHERE t.id = $1::bigint AND u.id = $2::bigint
|
||||
GROUP BY
|
||||
t.id, i.id, s.id, si.id
|
||||
WHERE ut.title_id = $1::bigint AND ut.user_id = $2::bigint
|
||||
`
|
||||
|
||||
type GetUserTitleByIDParams struct {
|
||||
|
|
@ -339,39 +316,9 @@ type GetUserTitleByIDParams struct {
|
|||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
type GetUserTitleByIDRow struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
TitleID int64 `json:"title_id"`
|
||||
Status UsertitleStatusT `json:"status"`
|
||||
Rate *int32 `json:"rate"`
|
||||
ReviewID *int64 `json:"review_id"`
|
||||
Ctime time.Time `json:"ctime"`
|
||||
ID *int64 `json:"id"`
|
||||
TitleNames []byte `json:"title_names"`
|
||||
StudioID *int64 `json:"studio_id"`
|
||||
PosterID *int64 `json:"poster_id"`
|
||||
TitleStatus *TitleStatusT `json:"title_status"`
|
||||
Rating *float64 `json:"rating"`
|
||||
RatingCount *int32 `json:"rating_count"`
|
||||
ReleaseYear *int32 `json:"release_year"`
|
||||
ReleaseSeason *ReleaseSeasonT `json:"release_season"`
|
||||
Season *int32 `json:"season"`
|
||||
EpisodesAired *int32 `json:"episodes_aired"`
|
||||
EpisodesAll *int32 `json:"episodes_all"`
|
||||
EpisodesLen []byte `json:"episodes_len"`
|
||||
TitleStorageType *StorageTypeT `json:"title_storage_type"`
|
||||
TitleImagePath *string `json:"title_image_path"`
|
||||
TagNames json.RawMessage `json:"tag_names"`
|
||||
StudioName *string `json:"studio_name"`
|
||||
StudioIllustID *int64 `json:"studio_illust_id"`
|
||||
StudioDesc *string `json:"studio_desc"`
|
||||
StudioStorageType *StorageTypeT `json:"studio_storage_type"`
|
||||
StudioImagePath *string `json:"studio_image_path"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserTitleByID(ctx context.Context, arg GetUserTitleByIDParams) (GetUserTitleByIDRow, error) {
|
||||
func (q *Queries) GetUserTitleByID(ctx context.Context, arg GetUserTitleByIDParams) (Usertitle, error) {
|
||||
row := q.db.QueryRow(ctx, getUserTitleByID, arg.TitleID, arg.UserID)
|
||||
var i GetUserTitleByIDRow
|
||||
var i Usertitle
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.TitleID,
|
||||
|
|
@ -379,27 +326,6 @@ func (q *Queries) GetUserTitleByID(ctx context.Context, arg GetUserTitleByIDPara
|
|||
&i.Rate,
|
||||
&i.ReviewID,
|
||||
&i.Ctime,
|
||||
&i.ID,
|
||||
&i.TitleNames,
|
||||
&i.StudioID,
|
||||
&i.PosterID,
|
||||
&i.TitleStatus,
|
||||
&i.Rating,
|
||||
&i.RatingCount,
|
||||
&i.ReleaseYear,
|
||||
&i.ReleaseSeason,
|
||||
&i.Season,
|
||||
&i.EpisodesAired,
|
||||
&i.EpisodesAll,
|
||||
&i.EpisodesLen,
|
||||
&i.TitleStorageType,
|
||||
&i.TitleImagePath,
|
||||
&i.TagNames,
|
||||
&i.StudioName,
|
||||
&i.StudioIllustID,
|
||||
&i.StudioDesc,
|
||||
&i.StudioStorageType,
|
||||
&i.StudioImagePath,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue