Skip to content

Commit

Permalink
fix: empty rank for subject browsing (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc authored Jun 3, 2024
1 parent b4f5f6d commit 75ce30c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions internal/subject/mysql_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (r mysqlRepo) Count(
case "date":
q = q.Order(r.q.SubjectField.Date.Desc())
case "rank":
q = q.Order(r.q.SubjectField.Rank)
q = q.Where(r.q.SubjectField.Rank.Gt(0)).Order(r.q.SubjectField.Rank)
}
}

Expand Down Expand Up @@ -298,7 +298,7 @@ func (r mysqlRepo) Browse(
case "date":
q = q.Order(r.q.SubjectField.Date.Desc())
case "rank":
q = q.Order(r.q.SubjectField.Rank)
q = q.Where(r.q.SubjectField.Rank.Gt(0)).Order(r.q.SubjectField.Rank)
}
}

Expand Down
19 changes: 9 additions & 10 deletions internal/subject/mysql_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,15 @@ func TestBrowse(t *testing.T) {
}
s, err = repo.Browse(context.Background(), filter, 30, 0)
require.NoError(t, err)
require.Equal(t, 9, len(s))
require.Equal(t, model.SubjectID(2), s[0].ID)
require.Equal(t, model.SubjectID(20), s[1].ID)
require.Equal(t, model.SubjectID(17), s[2].ID)
require.Equal(t, model.SubjectID(16), s[3].ID)
require.Equal(t, model.SubjectID(15), s[4].ID)
require.Equal(t, model.SubjectID(406604), s[5].ID)
require.Equal(t, model.SubjectID(19), s[6].ID)
require.Equal(t, model.SubjectID(315957), s[7].ID)
require.Equal(t, model.SubjectID(18), s[8].ID)
require.Equal(t, 8, len(s))
require.Equal(t, model.SubjectID(20), s[0].ID)
require.Equal(t, model.SubjectID(17), s[1].ID)
require.Equal(t, model.SubjectID(16), s[2].ID)
require.Equal(t, model.SubjectID(15), s[3].ID)
require.Equal(t, model.SubjectID(406604), s[4].ID)
require.Equal(t, model.SubjectID(19), s[5].ID)
require.Equal(t, model.SubjectID(315957), s[6].ID)
require.Equal(t, model.SubjectID(18), s[7].ID)

filter = subject.BrowseFilter{
Type: 4,
Expand Down
2 changes: 1 addition & 1 deletion openapi/v0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ paths:
required: false
schema:
type: string
- name: order
- name: sort
in: query
description: 排序,枚举值 {date|rank}
required: false
Expand Down
2 changes: 1 addition & 1 deletion web/handler/subject/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (h Subject) Browse(c echo.Context) error {
func parseBrowseQuery(c echo.Context) (*subject.BrowseFilter, error) {
filter := subject.BrowseFilter{}
u := accessor.GetFromCtx(c)
filter.NSFW = null.Bool{Value: !u.AllowNSFW(), Set: true}
filter.NSFW = null.Bool{Value: false, Set: !u.AllowNSFW()}
if stype, err := req.ParseSubjectType(c.QueryParam("type")); err != nil {
return nil, res.BadRequest(err.Error())
} else {
Expand Down

0 comments on commit 75ce30c

Please sign in to comment.