Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions openapi/components/subject_tags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ items:
required:
- name
- count
- total_cont
type: object
properties:
name:
title: Name
type: string
count:
title: Count
description: 使用此标签标记本条目的用户数
type: integer
total_cont:
title: Total Count
description: 此标签在所有条目中的使用总次数
type: integer
10 changes: 6 additions & 4 deletions web/res/subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ func ToSlimSubjectV0(s model.Subject) SlimSubjectV0 {
Date: date,
Tags: slice.Map(lo.Slice(s.Tags, 0, 10), func(item model.Tag) SubjectTag {
return SubjectTag{
Name: item.Name,
Count: item.Count,
Name: item.Name,
Count: item.Count,
TotalCont: item.TotalCount,
}
}),
ShortSummary: gstr.Slice(s.Summary, 0, defaultShortSummaryLength),
Expand Down Expand Up @@ -142,8 +143,9 @@ func ToSubjectV0(s model.Subject, totalEpisode int64, metaTags []tag.Tag) Subjec
}),
Tags: slice.Map(s.Tags, func(tag model.Tag) SubjectTag {
return SubjectTag{
Name: tag.Name,
Count: tag.Count,
Name: tag.Name,
Count: tag.Count,
TotalCont: tag.TotalCount,
}
}),
Collection: SubjectCollectionStat{
Expand Down
46 changes: 46 additions & 0 deletions web/res/subject_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package res_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/bangumi/server/internal/model"
"github.com/bangumi/server/web/res"
)

func TestToSubjectV0_TagTotalCount(t *testing.T) {
t.Parallel()

subject := model.Subject{
Tags: []model.Tag{{Name: "tag", Count: 10, TotalCount: 100}},
}
want := []res.SubjectTag{{Name: "tag", Count: 10, TotalCont: 100}}

require.Equal(t, want, res.ToSubjectV0(subject, 0, nil).Tags)
}

func TestToSlimSubjectV0_TagTotalCount(t *testing.T) {
t.Parallel()

subject := model.Subject{
Tags: []model.Tag{{Name: "tag", Count: 10, TotalCount: 100}},
}
want := []res.SubjectTag{{Name: "tag", Count: 10, TotalCont: 100}}

require.Equal(t, want, res.ToSlimSubjectV0(subject).Tags)
}
Loading