diff --git a/backend/IM_API/Controllers/GroupController.cs b/backend/IM_API/Controllers/GroupController.cs index 066bd10..35476ed 100644 --- a/backend/IM_API/Controllers/GroupController.cs +++ b/backend/IM_API/Controllers/GroupController.cs @@ -88,5 +88,13 @@ namespace IM_API.Controllers var groupinfo = await _groupService.UpdateGroupInfoAsync(int.Parse(useridStr), groupId, dto); return Ok(new BaseResponse(groupinfo)); } + + [HttpGet] + [ProducesResponseType(typeof(BaseResponse), StatusCodes.Status200OK)] + public async Task GetGroupInfo([FromQuery]int groupId) + { + var group = await _groupService.GetGroupInfoAsync(groupId); + return Ok(new BaseResponse(group)); + } } } diff --git a/backend/IM_API/Interface/Services/IGroupService.cs b/backend/IM_API/Interface/Services/IGroupService.cs index 95e7242..55ed4b0 100644 --- a/backend/IM_API/Interface/Services/IGroupService.cs +++ b/backend/IM_API/Interface/Services/IGroupService.cs @@ -53,6 +53,8 @@ namespace IM_API.Interface.Services Task MakeGroupRequestAsync(int userId,int? adminUserId,int groupId); Task MakeGroupMemberAsync(int userId, int groupId, GroupMemberRole? role); Task> GetGroupMembers(int userId, int groupId); - Task UpdateGroupInfoAsync(int userId, int groupId, GroupUpdateDto updateDto); + Task UpdateGroupInfoAsync(int userId, int groupId, GroupUpdateDto updateDto); + + Task GetGroupInfoAsync(int groupId); } } diff --git a/backend/IM_API/Services/GroupService.cs b/backend/IM_API/Services/GroupService.cs index 036896a..b784623 100644 --- a/backend/IM_API/Services/GroupService.cs +++ b/backend/IM_API/Services/GroupService.cs @@ -292,5 +292,15 @@ namespace IM_API.Services return _mapper.Map(groupInfo); } + + public async Task GetGroupInfoAsync(int groupId) + { + var groupInfo = await _context.Groups.FirstOrDefaultAsync(x => x.Id == groupId); + + if (groupInfo is null) + throw new BaseException(CodeDefine.GROUP_NOT_FOUND); + + return _mapper.Map(groupInfo); + } } } diff --git a/frontend/pc/IM/src/renderer/src/components/messages/InfoSidebar.vue b/frontend/pc/IM/src/renderer/src/components/messages/InfoSidebar.vue index c536b16..4b4ac26 100644 --- a/frontend/pc/IM/src/renderer/src/components/messages/InfoSidebar.vue +++ b/frontend/pc/IM/src/renderer/src/components/messages/InfoSidebar.vue @@ -79,6 +79,10 @@ import { MESSAGE_TYPE } from '../../constants/MessageType'; import feather from 'feather-icons'; import { GROUP_MEMBER_ROLE } from '../../constants/GroupDefine'; import { uploadService } from '../../services/upload/uploadService'; +import { groupService } from '../../services/group'; +import { SYSTEM_BASE_STATUS } from '../../constants/systemBaseStatus'; +import { useMessage } from './useAlert'; +import { getFileHash } from '../../utils/uploadTools'; const props = defineProps({ chatType: { @@ -105,6 +109,8 @@ const props = defineProps({ const input = useTemplateRef('input') +const message = useMessage(); + defineEmits(['close', 'viewAll']); const uploadGroupAvatar = () => { @@ -113,7 +119,17 @@ const uploadGroupAvatar = () => { const fileUploadHandler = async (e) => { const file = e.target.files[0]; - const { data } = await uploadService.uploadSmallFile(file); + const hash = getFileHash(file) + const { data } = await uploadService.uploadSmallFile(file, hash); + const res = await groupService.updateGroupInfo(props.groupData.targetId, { + avatar: data.url + }) + + if(res.code == SYSTEM_BASE_STATUS.SUCCESS){ + message.success('头像更新成功') + }else{ + message.error(res.message) + } } // 判断当前用户是否为管理员 diff --git a/frontend/pc/IM/src/renderer/src/services/group.js b/frontend/pc/IM/src/renderer/src/services/group.js index a69d2f6..d6dfdba 100644 --- a/frontend/pc/IM/src/renderer/src/services/group.js +++ b/frontend/pc/IM/src/renderer/src/services/group.js @@ -12,5 +12,14 @@ export const groupService = { * @param {*} groupId * @returns */ - getGroupMember: (groupId) => request.get(`/Group/GetGroupMembers?groupId=${groupId}`) + getGroupMember: (groupId) => request.get(`/Group/GetGroupMembers?groupId=${groupId}`), + + /** + * 更新群组信息 + * @param {*} groupId + * @param {*} params + * @returns + */ + + updateGroupInfo: (groupId, params) => request.post(`/Group/UpdateGroup?groupId=${groupId}`, params) }