Skip to content

Commit a02c614

Browse files
authored
fix(api)!: rename subject tag total_cont to total_count (#1130)
1 parent 2b1844a commit a02c614

4 files changed

Lines changed: 26 additions & 16 deletions

File tree

internal/search/subject/handle.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ func toResponseSubject(s model.Subject, metaTags []tag.Tag) ResponseSubject {
378378
}),
379379
Tags: slice.Map(s.Tags, func(tag model.Tag) res.SubjectTag {
380380
return res.SubjectTag{
381-
Name: tag.Name,
382-
Count: tag.Count,
383-
TotalCont: tag.TotalCount,
381+
Name: tag.Name,
382+
Count: tag.Count,
383+
TotalCount: tag.TotalCount,
384384
}
385385
}),
386386
Collection: res.SubjectCollectionStat{

openapi/components/subject_tags.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ items:
55
required:
66
- name
77
- count
8-
- total_cont
8+
- total_count
99
type: object
1010
properties:
1111
name:
@@ -15,7 +15,7 @@ items:
1515
title: Count
1616
description: 使用此标签标记本条目的用户数
1717
type: integer
18-
total_cont:
18+
total_count:
1919
title: Total Count
2020
description: 此标签在所有条目中的使用总次数
2121
type: integer

web/res/subject.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ const defaultShortSummaryLength = 120
3636
type V0wiki = []any
3737

3838
type SubjectTag struct {
39-
Name string `json:"name"`
40-
Count uint `json:"count"`
41-
TotalCont uint `json:"total_cont"`
39+
Name string `json:"name"`
40+
Count uint `json:"count"`
41+
TotalCount uint `json:"total_count"`
4242
}
4343

4444
type SubjectV0 struct {
@@ -93,9 +93,9 @@ func ToSlimSubjectV0(s model.Subject) SlimSubjectV0 {
9393
Date: date,
9494
Tags: slice.Map(lo.Slice(s.Tags, 0, 10), func(item model.Tag) SubjectTag {
9595
return SubjectTag{
96-
Name: item.Name,
97-
Count: item.Count,
98-
TotalCont: item.TotalCount,
96+
Name: item.Name,
97+
Count: item.Count,
98+
TotalCount: item.TotalCount,
9999
}
100100
}),
101101
ShortSummary: gstr.Slice(s.Summary, 0, defaultShortSummaryLength),
@@ -143,9 +143,9 @@ func ToSubjectV0(s model.Subject, totalEpisode int64, metaTags []tag.Tag) Subjec
143143
}),
144144
Tags: slice.Map(s.Tags, func(tag model.Tag) SubjectTag {
145145
return SubjectTag{
146-
Name: tag.Name,
147-
Count: tag.Count,
148-
TotalCont: tag.TotalCount,
146+
Name: tag.Name,
147+
Count: tag.Count,
148+
TotalCount: tag.TotalCount,
149149
}
150150
}),
151151
Collection: SubjectCollectionStat{

web/res/subject_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package res_test
1717
import (
1818
"testing"
1919

20+
"github.com/bytedance/sonic"
2021
"github.com/stretchr/testify/require"
2122

2223
"github.com/bangumi/server/internal/model"
@@ -29,7 +30,7 @@ func TestToSubjectV0_TagTotalCount(t *testing.T) {
2930
subject := model.Subject{
3031
Tags: []model.Tag{{Name: "tag", Count: 10, TotalCount: 100}},
3132
}
32-
want := []res.SubjectTag{{Name: "tag", Count: 10, TotalCont: 100}}
33+
want := []res.SubjectTag{{Name: "tag", Count: 10, TotalCount: 100}}
3334

3435
require.Equal(t, want, res.ToSubjectV0(subject, 0, nil).Tags)
3536
}
@@ -40,7 +41,16 @@ func TestToSlimSubjectV0_TagTotalCount(t *testing.T) {
4041
subject := model.Subject{
4142
Tags: []model.Tag{{Name: "tag", Count: 10, TotalCount: 100}},
4243
}
43-
want := []res.SubjectTag{{Name: "tag", Count: 10, TotalCont: 100}}
44+
want := []res.SubjectTag{{Name: "tag", Count: 10, TotalCount: 100}}
4445

4546
require.Equal(t, want, res.ToSlimSubjectV0(subject).Tags)
4647
}
48+
49+
func TestSubjectTag_JSON(t *testing.T) {
50+
t.Parallel()
51+
52+
data, err := sonic.Marshal(res.SubjectTag{Name: "tag", Count: 10, TotalCount: 100})
53+
require.NoError(t, err)
54+
require.JSONEq(t, `{"name":"tag","count":10,"total_count":100}`, string(data))
55+
require.NotContains(t, string(data), "total_cont")
56+
}

0 commit comments

Comments
 (0)