Skip to content

Commit e79c81c

Browse files
xbingWdhsifssawesomeYG
authored
Feat/v1.2.0 (#68)
* fix: contribute rank calc * fix: contribute rank calc * fix: add contribute rank init * fix: comments add created_at return * refactor: remove unused API files and enhance UI components - Deleted obsolete API files for Article, Category, GroupItem, and others to streamline the codebase. - Updated iconfont.js with new SVG icons for improved visual consistency. - Enhanced theme configuration by adding new font families for better typography. - Adjusted layout styles for improved responsiveness across different devices. - Added loading indicators and improved user experience in various components. This commit focuses on cleaning up the codebase and enhancing the overall user interface. --------- Co-authored-by: 姚凯 <kai.yao@chaitin.com> Co-authored-by: awesomeYG <gang.yang@chaitin.com>
1 parent c2bd5dc commit e79c81c

36 files changed

+1704
-3826
lines changed

backend/docs/docs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4967,6 +4967,9 @@ const docTemplate = `{
49674967
"content": {
49684968
"type": "string"
49694969
},
4970+
"created_at": {
4971+
"type": "integer"
4972+
},
49704973
"dislike": {
49714974
"type": "integer"
49724975
},
@@ -5206,6 +5209,9 @@ const docTemplate = `{
52065209
"content": {
52075210
"type": "string"
52085211
},
5212+
"created_at": {
5213+
"type": "integer"
5214+
},
52095215
"dislike": {
52105216
"type": "integer"
52115217
},
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package migration
2+
3+
import (
4+
"context"
5+
6+
"gorm.io/gorm"
7+
8+
"github.com/chaitin/koalaqa/migration/migrator"
9+
"github.com/chaitin/koalaqa/repo"
10+
)
11+
12+
type initRankContribute struct {
13+
repoRank *repo.Rank
14+
}
15+
16+
func (m *initRankContribute) Version() int64 {
17+
return 20251110110326
18+
}
19+
20+
func (m *initRankContribute) Migrate(tx *gorm.DB) error {
21+
return m.repoRank.RefresContribute(context.Background())
22+
}
23+
24+
func newInitRankContribute(rank *repo.Rank) migrator.Migrator {
25+
return &initRankContribute{repoRank: rank}
26+
}
27+
28+
func init() {
29+
registerDBMigrator(newInitRankContribute)
30+
}

backend/model/discussion.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ type DiscussionListItem struct {
6363
}
6464

6565
type DiscussionReply struct {
66-
ID uint `json:"id"`
67-
UpdatedAt Timestamp `json:"updated_at"`
66+
Base
6867
UserID uint `json:"user_id"`
6968
UserName string `json:"user_name"`
7069
UserAvatar string `json:"user_avatar"`

backend/repo/rank.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@ func (r *Rank) UserContribute(ctx context.Context) ([]model.Rank, error) {
2525
t := time.Now().AddDate(0, 0, -7)
2626
var res []model.Rank
2727
err := r.db.WithContext(ctx).Model(&model.User{}).
28-
Select("? AS type,users.id AS score_id, user_comment.answer_disc_count*0.2+user_comment.accpted_count*0.4+user_disc.blog_count*0.25+user_disc.qa_count*0.15 AS score", model.RankTypeContribute).
29-
Joins("JOIN (SELECT user_id, COUNT(1) FILTER (WHERE type = 'qa') AS qa_count, COUNT(1) FILTER (WHERE type = 'blog') AS blog_count FROM discussions WHERE created_at >= ? GROUP BY user_id) AS user_disc ON user_disc.user_id = users.id", t).
30-
Joins("JOIN (SELECT user_id, COUNT(1) FILTER (WHERE accepted) AS accpted_count, COUNT(DISTINCT discussion_id) AS answer_disc_count FROM comments WHERE created_at >= ? GROUP BY user_id) AS user_comment ON user_comment.user_id = users.id", t).
31-
Order("score DESC").
28+
Select("? AS type,users.id AS score_id, COALESCE(user_comment.answer_disc_count, 0)*0.2+COALESCE(user_comment.accpted_count, 0)*0.4+COALESCE(user_disc.blog_count, 0)*0.25+COALESCE(user_disc.qa_count, 0)*0.15 AS score", model.RankTypeContribute).
29+
Joins("LEFT JOIN (SELECT user_id, COUNT(1) FILTER (WHERE type = 'qa') AS qa_count, COUNT(1) FILTER (WHERE type = 'blog') AS blog_count FROM discussions WHERE created_at >= ? GROUP BY user_id) AS user_disc ON user_disc.user_id = users.id", t).
30+
Joins("LEFT JOIN (SELECT user_id, COUNT(1) FILTER (WHERE accepted) AS accpted_count, COUNT(DISTINCT discussion_id) AS answer_disc_count FROM comments WHERE created_at >= ? GROUP BY user_id) AS user_comment ON user_comment.user_id = users.id", t).
31+
Order("score DESC, score_id ASC").
3232
Limit(5).
3333
Find(&res).Error
3434
if err != nil {
3535
return nil, err
3636
}
3737

38+
for i := range res {
39+
if res[i].Score == 0 {
40+
return res[:i], nil
41+
}
42+
}
43+
3844
return res, nil
3945
}
4046

@@ -50,6 +56,10 @@ func (r *Rank) RefresContribute(ctx context.Context) error {
5056
return err
5157
}
5258

59+
if len(ranks) == 0 {
60+
return nil
61+
}
62+
5363
err = tx.CreateInBatches(&ranks, 1000).Error
5464
if err != nil {
5565
return err

ui/front/public/font/iconfont.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/front/src/api/Article.ts

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

ui/front/src/api/Category.ts

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

0 commit comments

Comments
 (0)