Skip to content

Commit 5379060

Browse files
committed
refact
1 parent aaec84c commit 5379060

33 files changed

+122
-125
lines changed

apis/assistant.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package apis
33
import (
44
"strconv"
55

6-
"github.com/juggleim/jugglechat-server/apimodels"
6+
"github.com/juggleim/jugglechat-server/apis/models"
77
"github.com/juggleim/jugglechat-server/errs"
88
"github.com/juggleim/jugglechat-server/services"
99

1010
"github.com/gin-gonic/gin"
1111
)
1212

1313
func AssistantAnswer(ctx *gin.Context) {
14-
req := apimodels.AssistantAnswerReq{}
14+
req := models.AssistantAnswerReq{}
1515
if err := ctx.BindJSON(&req); err != nil {
1616
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
1717
return
@@ -25,7 +25,7 @@ func AssistantAnswer(ctx *gin.Context) {
2525
}
2626

2727
func PromptAdd(ctx *gin.Context) {
28-
req := apimodels.Prompt{}
28+
req := models.Prompt{}
2929
if err := ctx.BindJSON(&req); err != nil || req.Prompts == "" {
3030
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
3131
return
@@ -39,7 +39,7 @@ func PromptAdd(ctx *gin.Context) {
3939
}
4040

4141
func PromptUpdate(ctx *gin.Context) {
42-
req := apimodels.Prompt{}
42+
req := models.Prompt{}
4343
if err := ctx.BindJSON(&req); err != nil || req.Id == "" || req.Prompts == "" {
4444
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
4545
return
@@ -53,7 +53,7 @@ func PromptUpdate(ctx *gin.Context) {
5353
}
5454

5555
func PromptDel(ctx *gin.Context) {
56-
req := apimodels.Prompt{}
56+
req := models.Prompt{}
5757
if err := ctx.BindJSON(&req); err != nil || req.Id == "" {
5858
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
5959
return
@@ -67,7 +67,7 @@ func PromptDel(ctx *gin.Context) {
6767
}
6868

6969
func PromptBatchDel(ctx *gin.Context) {
70-
req := apimodels.PromptIds{}
70+
req := models.PromptIds{}
7171
if err := ctx.BindJSON(&req); err != nil || len(req.Ids) <= 0 {
7272
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
7373
return

apis/bot.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"net/http"
55
"strconv"
66

7-
"github.com/juggleim/jugglechat-server/apimodels"
7+
"github.com/juggleim/jugglechat-server/apis/models"
88
"github.com/juggleim/jugglechat-server/errs"
99
"github.com/juggleim/jugglechat-server/services"
1010
"github.com/juggleim/jugglechat-server/services/aiengines"
@@ -33,7 +33,7 @@ func QryBots(ctx *gin.Context) {
3333
}
3434

3535
func BotMsgListener(ctx *gin.Context) {
36-
req := apimodels.BotMsg{}
36+
req := models.BotMsg{}
3737
if err := ctx.BindJSON(&req); err != nil {
3838
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
3939
return
@@ -48,7 +48,7 @@ func BotMsgListener(ctx *gin.Context) {
4848
idIndex := 1
4949
assistantInfo.AiEngine.StreamChat(services.ToCtx(ctx), req.SenderId, req.BotId, prompt, req.Messages[0].Content, func(answerPart string, isEnd bool) {
5050
if !isEnd {
51-
item := &apimodels.BotResponsePartData{
51+
item := &models.BotResponsePartData{
5252
Id: utils.Int2String(int64(idIndex)),
5353
Type: "message",
5454
Content: answerPart,

apis/file.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
package apis
22

33
import (
4-
"fmt"
5-
6-
"github.com/juggleim/jugglechat-server/apimodels"
4+
"github.com/juggleim/jugglechat-server/apis/models"
75
"github.com/juggleim/jugglechat-server/errs"
86
"github.com/juggleim/jugglechat-server/services"
97

108
"github.com/gin-gonic/gin"
119
)
1210

1311
func GetFileCred(ctx *gin.Context) {
14-
fmt.Print("xxxxxx")
15-
req := apimodels.QryFileCredReq{}
12+
req := models.QryFileCredReq{}
1613
if err := ctx.BindJSON(&req); err != nil {
1714
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
1815
return

apis/friend.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package apis
33
import (
44
"strconv"
55

6-
"github.com/juggleim/jugglechat-server/apimodels"
6+
"github.com/juggleim/jugglechat-server/apis/models"
77
"github.com/juggleim/jugglechat-server/errs"
88
"github.com/juggleim/jugglechat-server/services"
99
"github.com/juggleim/jugglechat-server/utils"
@@ -27,12 +27,12 @@ func QryFriends(ctx *gin.Context) {
2727
ErrorHttpResp(ctx, code)
2828
return
2929
}
30-
ret := &apimodels.Friends{
31-
Items: []*apimodels.UserObj{},
30+
ret := &models.Friends{
31+
Items: []*models.UserObj{},
3232
Offset: friends.Offset,
3333
}
3434
for _, friend := range friends.Items {
35-
ret.Items = append(ret.Items, &apimodels.UserObj{
35+
ret.Items = append(ret.Items, &models.UserObj{
3636
UserId: friend.UserId,
3737
Nickname: friend.Nickname,
3838
Avatar: friend.Avatar,
@@ -68,11 +68,11 @@ func QryFriendsWithPage(ctx *gin.Context) {
6868
ErrorHttpResp(ctx, code)
6969
return
7070
}
71-
ret := &apimodels.Friends{
72-
Items: []*apimodels.UserObj{},
71+
ret := &models.Friends{
72+
Items: []*models.UserObj{},
7373
}
7474
for _, friend := range friends.Items {
75-
ret.Items = append(ret.Items, &apimodels.UserObj{
75+
ret.Items = append(ret.Items, &models.UserObj{
7676
UserId: friend.UserId,
7777
Nickname: friend.Nickname,
7878
Avatar: friend.Avatar,
@@ -84,7 +84,7 @@ func QryFriendsWithPage(ctx *gin.Context) {
8484
}
8585

8686
func SearchFriends(ctx *gin.Context) {
87-
req := apimodels.SearchFriendsReq{}
87+
req := models.SearchFriendsReq{}
8888
if err := ctx.BindJSON(&req); err != nil || req.Key == "" {
8989
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
9090
return
@@ -98,12 +98,12 @@ func SearchFriends(ctx *gin.Context) {
9898
}
9999

100100
func AddFriend(ctx *gin.Context) {
101-
req := apimodels.Friend{}
101+
req := models.Friend{}
102102
if err := ctx.BindJSON(&req); err != nil {
103103
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
104104
return
105105
}
106-
code := services.AddFriends(services.ToCtx(ctx), &apimodels.FriendIdsReq{
106+
code := services.AddFriends(services.ToCtx(ctx), &models.FriendIdsReq{
107107
FriendIds: []string{req.FriendId},
108108
})
109109
if code != errs.IMErrorCode_SUCCESS {
@@ -114,12 +114,12 @@ func AddFriend(ctx *gin.Context) {
114114
}
115115

116116
func DelFriend(ctx *gin.Context) {
117-
req := apimodels.FriendIds{}
117+
req := models.FriendIds{}
118118
if err := ctx.BindJSON(&req); err != nil {
119119
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
120120
return
121121
}
122-
code := services.DelFriends(services.ToCtx(ctx), &apimodels.FriendIdsReq{
122+
code := services.DelFriends(services.ToCtx(ctx), &models.FriendIdsReq{
123123
FriendIds: req.FriendIds,
124124
})
125125
if code != errs.IMErrorCode_SUCCESS {
@@ -130,12 +130,12 @@ func DelFriend(ctx *gin.Context) {
130130
}
131131

132132
func ApplyFriend(ctx *gin.Context) {
133-
req := apimodels.ApplyFriend{}
133+
req := models.ApplyFriend{}
134134
if err := ctx.BindJSON(&req); err != nil {
135135
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
136136
return
137137
}
138-
code := services.ApplyFriend(services.ToCtx(ctx), &apimodels.ApplyFriend{
138+
code := services.ApplyFriend(services.ToCtx(ctx), &models.ApplyFriend{
139139
FriendId: req.FriendId,
140140
})
141141
if code != errs.IMErrorCode_SUCCESS {
@@ -146,7 +146,7 @@ func ApplyFriend(ctx *gin.Context) {
146146
}
147147

148148
func ConfirmFriend(ctx *gin.Context) {
149-
req := apimodels.ConfirmFriend{}
149+
req := models.ConfirmFriend{}
150150
if err := ctx.BindJSON(&req); err != nil {
151151
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
152152
return

apis/group.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"image/png"
77
"strconv"
88

9-
"github.com/juggleim/jugglechat-server/apimodels"
9+
"github.com/juggleim/jugglechat-server/apis/models"
1010
"github.com/juggleim/jugglechat-server/errs"
1111
"github.com/juggleim/jugglechat-server/services"
1212
"github.com/juggleim/jugglechat-server/utils"
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
func CreateGroup(ctx *gin.Context) {
20-
req := apimodels.Group{}
20+
req := models.Group{}
2121
if err := ctx.BindJSON(&req); err != nil {
2222
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
2323
return
@@ -30,7 +30,7 @@ func CreateGroup(ctx *gin.Context) {
3030
}
3131
memberIds = ids
3232
}
33-
code, grpInfo := services.CreateGroup(services.ToCtx(ctx), &apimodels.GroupMembersReq{
33+
code, grpInfo := services.CreateGroup(services.ToCtx(ctx), &models.GroupMembersReq{
3434
GroupName: req.GroupName,
3535
GroupPortrait: req.GroupPortrait,
3636
MemberIds: memberIds,
@@ -39,20 +39,20 @@ func CreateGroup(ctx *gin.Context) {
3939
ErrorHttpResp(ctx, code)
4040
return
4141
}
42-
SuccessHttpResp(ctx, &apimodels.Group{
42+
SuccessHttpResp(ctx, &models.Group{
4343
GroupId: grpInfo.GroupId,
4444
GroupName: grpInfo.GroupName,
4545
GroupPortrait: grpInfo.GroupPortrait,
4646
})
4747
}
4848

4949
func UpdateGroup(ctx *gin.Context) {
50-
req := apimodels.Group{}
50+
req := models.Group{}
5151
if err := ctx.BindJSON(&req); err != nil {
5252
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
5353
return
5454
}
55-
code := services.UpdateGroup(services.ToCtx(ctx), &apimodels.GroupInfo{
55+
code := services.UpdateGroup(services.ToCtx(ctx), &models.GroupInfo{
5656
GroupId: req.GroupId,
5757
GroupName: req.GroupName,
5858
GroupPortrait: req.GroupPortrait,
@@ -65,7 +65,7 @@ func UpdateGroup(ctx *gin.Context) {
6565
}
6666

6767
func DissolveGroup(ctx *gin.Context) {
68-
req := apimodels.Group{}
68+
req := models.Group{}
6969
if err := ctx.BindJSON(&req); err != nil {
7070
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
7171
return
@@ -79,7 +79,7 @@ func DissolveGroup(ctx *gin.Context) {
7979
}
8080

8181
func QuitGroup(ctx *gin.Context) {
82-
req := apimodels.Group{}
82+
req := models.Group{}
8383
if err := ctx.BindJSON(&req); err != nil {
8484
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
8585
return
@@ -93,7 +93,7 @@ func QuitGroup(ctx *gin.Context) {
9393
}
9494

9595
func AddGrpMembers(ctx *gin.Context) {
96-
req := apimodels.Group{}
96+
req := models.Group{}
9797
if err := ctx.BindJSON(&req); err != nil {
9898
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
9999
return
@@ -102,7 +102,7 @@ func AddGrpMembers(ctx *gin.Context) {
102102
for _, user := range req.GrpMembers {
103103
memberIds = append(memberIds, user.UserId)
104104
}
105-
code := services.AddGrpMembers(services.ToCtx(ctx), &apimodels.GroupMembersReq{
105+
code := services.AddGrpMembers(services.ToCtx(ctx), &models.GroupMembersReq{
106106
GroupId: req.GroupId,
107107
MemberIds: memberIds,
108108
})
@@ -114,12 +114,12 @@ func AddGrpMembers(ctx *gin.Context) {
114114
}
115115

116116
func DelGrpMembers(ctx *gin.Context) {
117-
req := apimodels.Group{}
117+
req := models.Group{}
118118
if err := ctx.BindJSON(&req); err != nil || req.GroupId == "" || len(req.MemberIds) <= 0 {
119119
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
120120
return
121121
}
122-
code := services.DelGrpMembers(services.ToCtx(ctx), &apimodels.GroupMembersReq{
122+
code := services.DelGrpMembers(services.ToCtx(ctx), &models.GroupMembersReq{
123123
GroupId: req.GroupId,
124124
MemberIds: req.MemberIds,
125125
})
@@ -157,12 +157,12 @@ func QryMyGroups(ctx *gin.Context) {
157157
ErrorHttpResp(ctx, code)
158158
return
159159
}
160-
ret := &apimodels.Groups{
160+
ret := &models.Groups{
161161
Offset: grps.Offset,
162-
Items: []*apimodels.Group{},
162+
Items: []*models.Group{},
163163
}
164164
for _, grp := range grps.Items {
165-
ret.Items = append(ret.Items, &apimodels.Group{
165+
ret.Items = append(ret.Items, &models.Group{
166166
GroupId: grp.GroupId,
167167
GroupName: grp.GroupName,
168168
GroupPortrait: grp.GroupPortrait,
@@ -188,12 +188,12 @@ func QryGrpMembers(ctx *gin.Context) {
188188
ErrorHttpResp(ctx, code)
189189
return
190190
}
191-
ret := &apimodels.GroupMembersResp{
192-
Items: []*apimodels.GroupMember{},
191+
ret := &models.GroupMembersResp{
192+
Items: []*models.GroupMember{},
193193
}
194194
for _, member := range members.Items {
195-
ret.Items = append(ret.Items, &apimodels.GroupMember{
196-
UserObj: apimodels.UserObj{
195+
ret.Items = append(ret.Items, &models.GroupMember{
196+
UserObj: models.UserObj{
197197
UserId: member.UserId,
198198
Nickname: member.Nickname,
199199
Avatar: member.Avatar,
@@ -205,7 +205,7 @@ func QryGrpMembers(ctx *gin.Context) {
205205
}
206206

207207
func CheckGroupMembers(ctx *gin.Context) {
208-
req := apimodels.CheckGroupMembersReq{}
208+
req := models.CheckGroupMembersReq{}
209209
if err := ctx.BindJSON(&req); err != nil {
210210
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
211211
return
@@ -219,7 +219,7 @@ func CheckGroupMembers(ctx *gin.Context) {
219219
}
220220

221221
func SearchGroupMembers(ctx *gin.Context) {
222-
req := apimodels.SearchGroupMembersReq{}
222+
req := models.SearchGroupMembersReq{}
223223
if err := ctx.BindJSON(&req); err != nil || req.GroupId == "" || req.Key == "" {
224224
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
225225
return
@@ -233,12 +233,12 @@ func SearchGroupMembers(ctx *gin.Context) {
233233
}
234234

235235
func SetGrpAnnouncement(ctx *gin.Context) {
236-
req := apimodels.GroupAnnouncement{}
236+
req := models.GroupAnnouncement{}
237237
if err := ctx.BindJSON(&req); err != nil {
238238
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
239239
return
240240
}
241-
code := services.SetGrpAnnouncement(services.ToCtx(ctx), &apimodels.GroupAnnouncement{
241+
code := services.SetGrpAnnouncement(services.ToCtx(ctx), &models.GroupAnnouncement{
242242
GroupId: req.GroupId,
243243
Content: req.Content,
244244
})
@@ -256,14 +256,14 @@ func GetGrpAnnouncement(ctx *gin.Context) {
256256
ErrorHttpResp(ctx, code)
257257
return
258258
}
259-
SuccessHttpResp(ctx, &apimodels.GroupAnnouncement{
259+
SuccessHttpResp(ctx, &models.GroupAnnouncement{
260260
GroupId: grpAnnounce.GroupId,
261261
Content: grpAnnounce.Content,
262262
})
263263
}
264264

265265
func SetGrpDisplayName(ctx *gin.Context) {
266-
req := apimodels.SetGroupDisplayNameReq{}
266+
req := models.SetGroupDisplayNameReq{}
267267
if err := ctx.BindJSON(&req); err != nil {
268268
ErrorHttpResp(ctx, errs.IMErrorCode_APP_REQ_BODY_ILLEGAL)
269269
return

0 commit comments

Comments
 (0)