Skip to content

Commit

Permalink
fix: 删除好友
Browse files Browse the repository at this point in the history
  • Loading branch information
danmuking committed Apr 19, 2024
1 parent 7c5d43b commit c39a2a9
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 228 deletions.
21 changes: 20 additions & 1 deletion controller/friend_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// @Param msg body string true "验证消息"
// @Success 200 {object} resp.ResponseData "成功"
// @Failure 500 {object} resp.ResponseData "内部错误"
// @Router /api/contact/add [post]
// @Router /api/user/add [post]
func ApplyFriendController(c *gin.Context) {
uid := c.GetInt64("uid")
applyReq := req.UserApplyReq{}
Expand All @@ -28,3 +28,22 @@ func ApplyFriendController(c *gin.Context) {
resp.ReturnResponse(c, response)
return
}

// DeleteFriendController 删除好友
//
// @Summary 删除好友
// @Produce json
// @Param uid body int true "好友uid"
// @Success 200 {object} resp.ResponseData "成功"
// @Failure 500 {object} resp.ResponseData "内部错误"
// @Router /api/user/delete/:uid [delete]
func DeleteFriendController(c *gin.Context) {
uid := c.GetInt64("uid")
deleteFriendReq := req.DeleteFriendReq{}
if err := c.ShouldBindUri(&deleteFriendReq); err != nil {
resp.ErrorResponse(c, "参数错误")
return
}
response := service.DeleteFriendService(uid, deleteFriendReq)
resp.ReturnResponse(c, response)
}
22 changes: 11 additions & 11 deletions dal/model/message.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions dal/model/room.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions dal/model/room_friend.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions dal/query/message.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions dal/query/room.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions dal/query/room_friend.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions domain/enum/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ const (
User = Project + "user:"
UserFriend = Project + "userFriend:"
UserApply = Project + "userApply:"
RoomFriend = Project + "roomFriend:"
Contact = Project + "contact:"
)
5 changes: 5 additions & 0 deletions domain/vo/req/delete_friend_req.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package req

type DeleteFriendReq struct {
Uid int64 `uri:"uid" binding:"required"`
}
6 changes: 3 additions & 3 deletions event/listener/friend_new_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func FriendNewEvent(friend model.UserFriend) {
FromUID: friend.UID,
Content: "你们已经是好友了,开始聊天吧",
// TODO: 抽取为常量
Status: 0,
Type: enum.TextMessage,
Extra: "{}",
DeleteStatus: 0,
Type: enum.TextMessage,
Extra: "{}",
}
if err := service.SendTextMsg(&newMsg); err != nil {
log.Println("发送消息失败", err.Error())
Expand Down
6 changes: 4 additions & 2 deletions pkg/enum/common_enum.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package enum

const (
YES = 2
NO = 1
YES = 2
NO = 1
NORMAL = 0
DELETED = 1
)
2 changes: 1 addition & 1 deletion routes/init_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func initGin() {
//添加好友
apiUser.POST("/add", controller.ApplyFriendController)
//删除好友
apiUser.DELETE("/delete", service.DeleteFriendService)
apiUser.DELETE("/delete/:uid", controller.DeleteFriendController)
//获取好友申请列表
apiUser.GET("/getApplyList", service.GetApplyList)
//同意好友申请
Expand Down
2 changes: 1 addition & 1 deletion service/contact_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func getContactDto(contact model.Contact) (*dto.ContactDto, error) {
contactDto.Avatar = userR.Avatar
contactDto.LastTime = contact.ActiveTime
}
count, err := msgQ.Where(msg.RoomID.Eq(contact.RoomID), msg.Status.Eq(enum.NORMAL), msg.CreateTime.Gt(contact.ReadTime)).Limit(99).Count()
count, err := msgQ.Where(msg.RoomID.Eq(contact.RoomID), msg.DeleteStatus.Eq(enum.NORMAL), msg.CreateTime.Gt(contact.ReadTime)).Limit(99).Count()
if err != nil {
global.Logger.Errorf("统计未读数失败 %s", err)
return nil, err
Expand Down
Loading

0 comments on commit c39a2a9

Please sign in to comment.