Skip to content

Commit 6e77ebd

Browse files
committed
fix: move buildCredit to server
1 parent ff372f2 commit 6e77ebd

7 files changed

Lines changed: 25 additions & 523 deletions

File tree

internal/academic/pack/credit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func BuildCredit(data []*jwch.CreditStatistics) []*model.Credit {
3030
return credit
3131
}
3232

33-
func BuildCreditResponse(data *jwch.CreditResponse) model.CreditResponse {
33+
func BuildCreditResponse(data *CreditResponse) model.CreditResponse {
3434
if data == nil {
3535
return nil
3636
}

internal/academic/pack/credit_format.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,26 @@ import (
2424
"github.com/west2-online/jwch"
2525
)
2626

27+
// CreditDetail 用于表示学分的详细数据项
28+
type CreditDetail struct {
29+
Key string `json:"key"`
30+
Value string `json:"value"`
31+
}
32+
33+
// CreditCategory 用于表示学分分类
34+
type CreditCategory struct {
35+
Type string `json:"type"`
36+
Data []*CreditDetail `json:"data"`
37+
}
38+
39+
// CreditResponse 用于学分响应
40+
type CreditResponse []*CreditCategory
41+
2742
// BuildCreditCategory 格式化处理学分统计
28-
func BuildCreditCategory(categoryType string, credits []*jwch.CreditStatistics) *jwch.CreditCategory {
29-
category := &jwch.CreditCategory{
43+
func BuildCreditCategory(categoryType string, credits []*jwch.CreditStatistics) *CreditCategory {
44+
category := &CreditCategory{
3045
Type: categoryType,
31-
Data: make([]*jwch.CreditDetail, 0, len(credits)),
46+
Data: make([]*CreditDetail, 0, len(credits)),
3247
}
3348

3449
// 用于计算"总计"栏的还需学分总和
@@ -52,12 +67,12 @@ func BuildCreditCategory(categoryType string, credits []*jwch.CreditStatistics)
5267
total, _ := strconv.ParseFloat(credit.Total, 64)
5368
value := fmt.Sprintf("%g / %g (还需 %g 分)", gain, total, totalNeed)
5469

55-
category.Data = append(category.Data, &jwch.CreditDetail{
70+
category.Data = append(category.Data, &CreditDetail{
5671
Key: credit.Type,
5772
Value: value,
5873
})
5974
case isSpecial:
60-
category.Data = append(category.Data, &jwch.CreditDetail{
75+
category.Data = append(category.Data, &CreditDetail{
6176
Key: credit.Type,
6277
Value: credit.Gain,
6378
})
@@ -75,11 +90,11 @@ func BuildCreditCategory(categoryType string, credits []*jwch.CreditStatistics)
7590
totalNeed += need
7691
}
7792

78-
category.Data = append(category.Data, &jwch.CreditDetail{
93+
category.Data = append(category.Data, &CreditDetail{
7994
Key: credit.Type,
8095
Value: value,
8196
})
8297
}
8398
}
8499
return category
85-
}
100+
}

internal/academic/service/get_credit_v2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
// GetCreditV2 获取V2版本的学分统计
30-
func (s *AcademicService) GetCreditV2() (*jwch.CreditResponse, error) {
30+
func (s *AcademicService) GetCreditV2() (*pack.CreditResponse, error) {
3131
loginData, err := context.GetLoginData(s.ctx)
3232
if err != nil {
3333
return nil, fmt.Errorf("service.GetCreditV2: Get login data fail %w", err)
@@ -40,7 +40,7 @@ func (s *AcademicService) GetCreditV2() (*jwch.CreditResponse, error) {
4040
}
4141

4242
majorItem := pack.BuildCreditCategory("主修专业", majorCredits)
43-
var response jwch.CreditResponse
43+
var response pack.CreditResponse
4444
response = append(response, majorItem)
4545

4646
if len(minorCredits) > 0 {

internal/oa/handler.go

Lines changed: 0 additions & 104 deletions
This file was deleted.

internal/oa/service/feedback_service.go

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)