diff --git a/dao/im.go b/dao/im.go index f5848a5..75212be 100644 --- a/dao/im.go +++ b/dao/im.go @@ -265,8 +265,8 @@ func FindGroupByID(group_id int) []Group { return groups } -func UpdateGroup(group_id int, groupName, groupInfo, groupIcon string) error { - res := DB.Debug().Model(&Group{}).Where("id = ?", group_id).Updates(map[string]interface{}{"group_name": groupName, "group_info": groupInfo, "group_icon": groupIcon}) +func UpdateGroup(group_id int, groupName, groupInfo, groupType, groupIcon string, user_id int) error { + res := DB.Debug().Model(&Group{}).Where("id = ? and auth_id = ? ", group_id, user_id).Updates(map[string]interface{}{"group_name": groupName, "group_info": groupInfo, "group_icon": groupIcon, "group_type": groupType}) return res.Error } diff --git a/handler/im.go b/handler/im.go index ab7b407..bc872a1 100644 --- a/handler/im.go +++ b/handler/im.go @@ -35,6 +35,7 @@ type Message struct { } type CGroup struct { + ID int `json:"id" form:"id"` Group_name string `json:"group_name" form:"group_name"` Group_info string `json:"group_info" form:"group_info"` Group_type string `json:"group_type" form:"group_type"` @@ -69,6 +70,7 @@ func SetUpIMGroup(router *gin.Engine) { //拒绝邀请 imGroup.POST("/reject_invite", RejectInvite) imGroup.POST("/create_group", CreateGroup) + imGroup.POST("/update_group", UpdateGroup) imGroup.POST("/get_group", GetGroups) imGroup.POST("/get_group_req_user", GetFriendRequest) imGroup.GET("/sse_msg", ServerSendMsg) @@ -120,6 +122,22 @@ func GetGroups(c *gin.Context) { } +func UpdateGroup(c *gin.Context) { + id, _ := c.Get("id") + user_id := int(id.(float64)) + var req CGroup + if err := c.ShouldBind(&req); err == nil { + err2 := service.UpdateGroupService(req.ID, req.Group_name, req.Group_info, req.Group_type, req.Group_icon, user_id) + if err2 == nil { + c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"}) + } else { + c.JSON(http.StatusOK, gin.H{"error": err2.Error(), "code": proto.OperationFailed, "message": "failed"}) + } + } else { + c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": proto.ParameterError, "message": "failed"}) + } +} + func DelFriendOrGroup(c *gin.Context) { var req Message user_id, _ := c.Get("id") diff --git a/service/imService.go b/service/imService.go index 6aa1e42..60185c3 100644 --- a/service/imService.go +++ b/service/imService.go @@ -258,6 +258,13 @@ func GetFriendList(user_id int) FGRet { return fg } +func UpdateGroupService(group_id int, group_name, group_info, group_type, group_icon string, user_id int) error { + //更新群聊 + err := dao.UpdateGroup(group_id, group_name, group_info, group_type, group_icon, user_id) + return err + +} + func GetFriendRequest(user_id int) []dao.FriendRequest { //获取好友请求 users := dao.GetFriendRequest(user_id)