Skip to content

Commit

Permalink
z
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc committed May 26, 2024
1 parent 4665e98 commit cd8dae8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions internal/subject/mysql_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down
25 changes: 15 additions & 10 deletions web/handler/subject/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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 != "" {
Expand Down

0 comments on commit cd8dae8

Please sign in to comment.