Skip to content

Commit 2b78fb7

Browse files
awesomeYGdhsifssawesomeYG
authored
Feat/v1.1.0 (#67)
* fix: disc list order and filter * fix: notify add new var * fix: return unread num when read notify * fix: disc list resolved filter * fix: trend api perm * fix: trend list order * fix: trend create * feat: enhance API client and UI components - Updated httpClient to improve request handling and added global instance for easier access. - Refactored theme colors and typography for better consistency. - Introduced new components for user profiles and notifications, enhancing user experience. - Updated various UI elements for improved responsiveness and accessibility. - Removed deprecated API configuration example and cleaned up unused imports. This commit aims to streamline API interactions and enhance the overall user interface. --------- Co-authored-by: 姚凯 <kai.yao@chaitin.com> Co-authored-by: awesomeYG <gang.yang@chaitin.com>
1 parent 7931847 commit 2b78fb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2243
-1151
lines changed

backend/docs/docs.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,13 +3214,13 @@ const docTemplate = `{
32143214
"enum": [
32153215
"hot",
32163216
"new",
3217-
"mine"
3217+
"publish"
32183218
],
32193219
"type": "string",
32203220
"x-enum-varnames": [
32213221
"DiscussionListFilterHot",
32223222
"DiscussionListFilterNew",
3223-
"DiscussionListFilterMine"
3223+
"DiscussionListFilterPublish"
32243224
],
32253225
"name": "filter",
32263226
"in": "query"
@@ -3244,12 +3244,22 @@ const docTemplate = `{
32443244
"name": "keyword",
32453245
"in": "query"
32463246
},
3247+
{
3248+
"type": "boolean",
3249+
"name": "only_mine",
3250+
"in": "query"
3251+
},
32473252
{
32483253
"minimum": 1,
32493254
"type": "integer",
32503255
"name": "page",
32513256
"in": "query"
32523257
},
3258+
{
3259+
"type": "boolean",
3260+
"name": "resolved",
3261+
"in": "query"
3262+
},
32533263
{
32543264
"minimum": 1,
32553265
"type": "integer",
@@ -6149,12 +6159,12 @@ const docTemplate = `{
61496159
"enum": [
61506160
"hot",
61516161
"new",
6152-
"mine"
6162+
"publish"
61536163
],
61546164
"x-enum-varnames": [
61556165
"DiscussionListFilterHot",
61566166
"DiscussionListFilterNew",
6157-
"DiscussionListFilterMine"
6167+
"DiscussionListFilterPublish"
61586168
]
61596169
},
61606170
"svc.DiscussionUpdateReq": {

backend/repo/comment.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ func (c *Comment) List(ctx context.Context, res any, queryFuncs ...QueryOptFunc)
3535
Find(res).Error
3636
}
3737

38+
func (c *Comment) CountByForumIDs(ctx context.Context, res *int64, forumIDs model.Int64Array, queryFuncs ...QueryOptFunc) error {
39+
o := getQueryOpt(queryFuncs...)
40+
return c.model(ctx).
41+
Where("discussion_id IN (SELECT id FROM discussions WHERE forum_id = ANY(?))", forumIDs).
42+
Scopes(o.Scopes()...).
43+
Count(res).Error
44+
}
45+
3846
func init() {
3947
register(newComment)
4048
}

backend/router/user.go

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -168,53 +168,6 @@ func (u *user) LoginWeComCallback(ctx *context.Context) {
168168
u.loginThirdCallback(ctx, model.AuthTypeWeCom)
169169
}
170170

171-
// Statistics
172-
// @Summary stat user info
173-
// @Tags user
174-
// @Param user_id path uint true "user id"
175-
// @Produce json
176-
// @Success 200 {object} context.Response{data=svc.UserStatisticsRes}
177-
// @Router /user/{user_id} [get]
178-
func (u *user) Statistics(ctx *context.Context) {
179-
userID, err := ctx.ParamUint("user_id")
180-
if err != nil {
181-
ctx.BadRequest(err)
182-
return
183-
}
184-
185-
res, err := u.svcU.Statistics(ctx, userID)
186-
if err != nil {
187-
ctx.InternalError(err, "stat user failed")
188-
return
189-
}
190-
191-
ctx.Success(res)
192-
}
193-
194-
// TrendList
195-
// @Summary list user trend
196-
// @Tags user
197-
// @Param req query svc.TrendListReq true "req params"
198-
// @Produce json
199-
// @Success 200 {object} context.Response{data=model.ListRes{items=[]model.Trend}}
200-
// @Router /user/trend [get]
201-
func (u *user) TrendList(ctx *context.Context) {
202-
var req svc.TrendListReq
203-
err := ctx.ShouldBindQuery(&req)
204-
if err != nil {
205-
ctx.BadRequest(err)
206-
return
207-
}
208-
209-
res, err := u.svcTrend.List(ctx, ctx.GetUser().UID, req)
210-
if err != nil {
211-
ctx.InternalError(err, "list trend failed")
212-
return
213-
}
214-
215-
ctx.Success(res)
216-
}
217-
218171
func (u *user) Route(h server.Handler) {
219172
g := h.Group("/api/user")
220173
g.POST("/register", u.Register)
@@ -230,8 +183,6 @@ func (u *user) Route(h server.Handler) {
230183
}
231184

232185
}
233-
g.GET("/:user_id", u.Statistics)
234-
g.GET("/trend", u.TrendList)
235186
}
236187

237188
func newUser(cfg config.Config, u *svc.User, trend *svc.Trend) server.Router {

backend/router/user_auth.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ type notifyRes struct {
100100
Data any `json:"data"`
101101
}
102102

103+
type notifyInfo struct {
104+
model.MessageNotifyInfo
105+
New bool `json:"new"`
106+
}
107+
103108
type notifyReq struct {
104109
Type notifyType `json:"type"`
105110
ID uint `json:"id"`
@@ -148,7 +153,13 @@ func (u *userAuth) Notify(ctx *context.Context) {
148153
case <-ctx.Done():
149154
case writeC <- notifyRes{
150155
Type: notifyTypeInfo,
151-
Data: item,
156+
Data: notifyInfo{
157+
MessageNotifyInfo: model.MessageNotifyInfo{
158+
ID: item.ID,
159+
MessageNotifyCommon: item.MessageNotifyCommon,
160+
},
161+
New: false,
162+
},
152163
}:
153164
}
154165

@@ -166,7 +177,10 @@ func (u *userAuth) Notify(ctx *context.Context) {
166177
case <-ctx.Done():
167178
case writeC <- notifyRes{
168179
Type: notifyTypeInfo,
169-
Data: notifyData,
180+
Data: notifyInfo{
181+
MessageNotifyInfo: notifyData,
182+
New: true,
183+
},
170184
}:
171185
}
172186

@@ -208,6 +222,17 @@ func (u *userAuth) Notify(ctx *context.Context) {
208222
Data: struct{}{},
209223
}:
210224
}
225+
case notifyTypeRead:
226+
err = u.in.SvcNotify.Read(ctx, ctx.GetUser().UID, svc.NotifyReadReq{
227+
ID: req.ID,
228+
})
229+
if err != nil {
230+
logger.WithErr(err).With("id", req.ID).Warn("set notify read failed")
231+
continue
232+
}
233+
234+
// 需要返回未读数量
235+
fallthrough
211236
case notifyTypeUnread:
212237
num, err := u.in.SvcNotify.UnreadTotal(ctx, ctx.GetUser().UID)
213238
if err != nil {
@@ -222,14 +247,6 @@ func (u *userAuth) Notify(ctx *context.Context) {
222247
Data: num,
223248
}:
224249
}
225-
case notifyTypeRead:
226-
err = u.in.SvcNotify.Read(ctx, ctx.GetUser().UID, svc.NotifyReadReq{
227-
ID: req.ID,
228-
})
229-
if err != nil {
230-
logger.WithErr(err).With("id", req.ID).Warn("set notify read failed")
231-
continue
232-
}
233250
}
234251
case websocket.CloseMessage:
235252
logger.Info("receive close message")

backend/router/user_public.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package router
2+
3+
import (
4+
"github.com/chaitin/koalaqa/pkg/context"
5+
"github.com/chaitin/koalaqa/server"
6+
"github.com/chaitin/koalaqa/svc"
7+
)
8+
9+
type userPublic struct {
10+
svcU *svc.User
11+
svcTrend *svc.Trend
12+
}
13+
14+
// Statistics
15+
// @Summary stat user info
16+
// @Tags user
17+
// @Param user_id path uint true "user id"
18+
// @Produce json
19+
// @Success 200 {object} context.Response{data=svc.UserStatisticsRes}
20+
// @Router /user/{user_id} [get]
21+
func (u *userPublic) Statistics(ctx *context.Context) {
22+
userID, err := ctx.ParamUint("user_id")
23+
if err != nil {
24+
ctx.BadRequest(err)
25+
return
26+
}
27+
28+
res, err := u.svcU.Statistics(ctx, ctx.GetUser().UID, userID)
29+
if err != nil {
30+
ctx.InternalError(err, "stat user failed")
31+
return
32+
}
33+
34+
ctx.Success(res)
35+
}
36+
37+
// TrendList
38+
// @Summary list user trend
39+
// @Tags user
40+
// @Param req query svc.TrendListReq true "req params"
41+
// @Produce json
42+
// @Success 200 {object} context.Response{data=model.ListRes{items=[]model.Trend}}
43+
// @Router /user/trend [get]
44+
func (u *userPublic) TrendList(ctx *context.Context) {
45+
var req svc.TrendListReq
46+
err := ctx.ShouldBindQuery(&req)
47+
if err != nil {
48+
ctx.BadRequest(err)
49+
return
50+
}
51+
52+
res, err := u.svcTrend.List(ctx, ctx.GetUser().UID, req)
53+
if err != nil {
54+
ctx.InternalError(err, "list trend failed")
55+
return
56+
}
57+
58+
ctx.Success(res)
59+
}
60+
61+
func (u *userPublic) Route(h server.Handler) {
62+
g := h.Group("/user")
63+
g.GET("/:user_id", u.Statistics)
64+
g.GET("/trend", u.TrendList)
65+
}
66+
67+
func newUserPublic(u *svc.User, trend *svc.Trend) server.Router {
68+
return &userPublic{
69+
svcU: u,
70+
svcTrend: trend,
71+
}
72+
}
73+
74+
func init() {
75+
registerApiNoAuthRouter(newUserPublic)
76+
}

backend/sub/blog.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,6 @@ func (a *Blog) handleInsert(ctx context.Context, data topic.MsgDiscChange) error
6565
logger := a.logger.WithContext(ctx).With("disc_uuid", data.DiscUUID).With("type", data.Type)
6666
logger.Info("handle insert blog")
6767

68-
if data.OP == topic.OPInsert {
69-
var disc model.Discussion
70-
err := a.disc.GetByID(ctx, &disc, data.DiscID)
71-
if err != nil {
72-
logger.WithErr(err).Warn("get disc failed")
73-
return nil
74-
}
75-
76-
err = a.trend.Create(ctx, &model.Trend{
77-
UserID: disc.UserID,
78-
Type: model.TrendTypeCreateDiscuss,
79-
DiscussHeader: disc.Header(),
80-
})
81-
if err != nil {
82-
logger.WithErr(err).Warn("create trend failed")
83-
}
84-
}
85-
8668
_, prompt, err := a.llm.GeneratePostPrompt(ctx, data.DiscID)
8769
if err != nil {
8870
logger.WithErr(err).Error("generate post prompt failed")

backend/sub/comm.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,6 @@ func (d *Comment) handleInsert(ctx context.Context, data topic.MsgCommentChange)
8585
return nil
8686
}
8787

88-
forum, err := d.forum.GetByID(ctx, disc.ForumID)
89-
if err != nil {
90-
logger.WithErr(err).Warn("get forum failed")
91-
return nil
92-
}
93-
94-
// 回答问题更新 trend
95-
if comment.ParentID == 0 && !comment.Bot {
96-
err = d.trend.Create(ctx, &model.Trend{
97-
UserID: comment.UserID,
98-
Type: model.TrendTypeAnswer,
99-
DiscussHeader: disc.Header(),
100-
})
101-
if err != nil {
102-
logger.WithErr(err).Warn("create trend failed")
103-
}
104-
}
105-
10688
go func() {
10789
if disc.Type != model.DiscussionTypeQA || comment.ParentID == 0 {
10890
d.disc.IncrementComment(disc.UUID, !data.NotUpdateDisc)
@@ -115,6 +97,12 @@ func (d *Comment) handleInsert(ctx context.Context, data topic.MsgCommentChange)
11597
return nil
11698
}
11799

100+
forum, err := d.forum.GetByID(ctx, disc.ForumID)
101+
if err != nil {
102+
logger.WithErr(err).Warn("get forum failed")
103+
return nil
104+
}
105+
118106
// record rag
119107
ragID, err := d.rag.UpsertRecords(ctx, forum.DatasetID, disc.RagID, prompt, nil)
120108
if err != nil {

backend/sub/disc.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,6 @@ func (d *Disc) handleInsert(ctx context.Context, data topic.MsgDiscChange) error
7777
logger := d.logger.WithContext(ctx).With("disc_id", data.DiscID)
7878
logger.Info("handle insert discussion comment")
7979

80-
disc, err := d.disc.GetByID(ctx, data.DiscID)
81-
if err != nil {
82-
logger.WithErr(err).Warn("get disc failed")
83-
return nil
84-
}
85-
86-
err = d.trend.Create(ctx, &model.Trend{
87-
UserID: disc.UserID,
88-
Type: model.TrendTypeCreateDiscuss,
89-
DiscussHeader: disc.Header(),
90-
})
91-
if err != nil {
92-
logger.WithErr(err).Warn("create trend failed")
93-
}
94-
9580
bot, err := d.bot.Get(ctx)
9681
if err != nil {
9782
logger.WithErr(err).Error("get bot failed")

0 commit comments

Comments
 (0)