From cd8dae81d265e43a8424fffaa6141a7a55c9abcd Mon Sep 17 00:00:00 2001 From: everpcpc Date: Mon, 27 May 2024 02:03:09 +0800 Subject: [PATCH] z --- internal/subject/mysql_repository.go | 4 ++-- web/handler/subject/browse.go | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/internal/subject/mysql_repository.go b/internal/subject/mysql_repository.go index 5218dd0ca..06af61bb2 100644 --- a/internal/subject/mysql_repository.go +++ b/internal/subject/mysql_repository.go @@ -234,7 +234,7 @@ func (r mysqlRepo) GetByIDs( func (r mysqlRepo) Count( ctx context.Context, filter BrowseFilter) (int64, error) { - q := r.q.Subject.WithContext(ctx).Joins(r.q.Subject.Fields).Where(r.q.Subject.TypeID.Eq(filter.Type)) + q := r.q.Subject.WithContext(ctx).Joins(r.q.Subject.Fields).Join(r.q.SubjectField, r.q.Subject.ID.EqCol(r.q.SubjectField.Sid)).Where(r.q.Subject.TypeID.Eq(filter.Type)) if filter.NSFW.Set { q = q.Where(r.q.Subject.Nsfw.Is(filter.NSFW.Value)) } @@ -267,7 +267,7 @@ func (r mysqlRepo) Count( func (r mysqlRepo) Browse( ctx context.Context, filter BrowseFilter, limit, offset int, ) ([]model.Subject, error) { - q := r.q.Subject.WithContext(ctx).Joins(r.q.Subject.Fields).Where(r.q.Subject.TypeID.Eq(filter.Type)) + q := r.q.Subject.WithContext(ctx).Joins(r.q.Subject.Fields).Join(r.q.SubjectField, r.q.Subject.ID.EqCol(r.q.SubjectField.Sid)).Where(r.q.Subject.TypeID.Eq(filter.Type)) if filter.NSFW.Set { q = q.Where(r.q.Subject.Nsfw.Is(filter.NSFW.Value)) } diff --git a/web/handler/subject/browse.go b/web/handler/subject/browse.go index ffaafdfa0..2d2105ba2 100644 --- a/web/handler/subject/browse.go +++ b/web/handler/subject/browse.go @@ -20,6 +20,7 @@ import ( "github.com/labstack/echo/v4" "github.com/trim21/errgo" + "github.com/bangumi/server/internal/model" "github.com/bangumi/server/internal/pkg/gstr" "github.com/bangumi/server/internal/pkg/null" "github.com/bangumi/server/internal/subject" @@ -77,7 +78,7 @@ func parseBrowseQuery(c echo.Context) (filter subject.BrowseFilter, err error) { filter.Type = stype } - if catStr := c.QueryParam("category"); catStr != "" { + if catStr := c.QueryParam("cat"); catStr != "" { if cat, e := req.ParseSubjectCategory(filter.Type, catStr); e != nil { err = res.BadRequest(e.Error()) return @@ -86,18 +87,22 @@ func parseBrowseQuery(c echo.Context) (filter subject.BrowseFilter, err error) { } } - if seriesStr := c.QueryParam("series"); seriesStr != "" { - if series, e := gstr.ParseBool(seriesStr); e != nil { - err = res.BadRequest(e.Error()) - return - } else { - filter.Series = null.Bool{Value: series, Set: true} + if filter.Type == model.SubjectTypeBook { + if seriesStr := c.QueryParam("series"); seriesStr != "" { + if series, e := gstr.ParseBool(seriesStr); e != nil { + err = res.BadRequest(e.Error()) + return + } else { + filter.Series = null.Bool{Value: series, Set: true} + } } } - if platform := c.QueryParam("platform"); platform != "" { - // TODO: check if platform is valid - filter.Platform = null.String{Value: platform, Set: true} + if filter.Type == model.SubjectTypeGame { + if platform := c.QueryParam("platform"); platform != "" { + // TODO: check if platform is valid + filter.Platform = null.String{Value: platform, Set: true} + } } if order := c.QueryParam("order"); order != "" {