diff --git a/openapi/components/subject_tags.yaml b/openapi/components/subject_tags.yaml index 4595ab40c..920a626f6 100644 --- a/openapi/components/subject_tags.yaml +++ b/openapi/components/subject_tags.yaml @@ -5,6 +5,7 @@ items: required: - name - count + - total_cont type: object properties: name: @@ -12,4 +13,9 @@ items: type: string count: title: Count + description: 使用此标签标记本条目的用户数 + type: integer + total_cont: + title: Total Count + description: 此标签在所有条目中的使用总次数 type: integer diff --git a/web/res/subject.go b/web/res/subject.go index 0af10cb1f..1239c7855 100644 --- a/web/res/subject.go +++ b/web/res/subject.go @@ -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), @@ -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{ diff --git a/web/res/subject_test.go b/web/res/subject_test.go new file mode 100644 index 000000000..d9885ccab --- /dev/null +++ b/web/res/subject_test.go @@ -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 . + +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) +}