using System.Collections.Generic; using System.Threading.Tasks; using GxPress.Auth; using GxPress.Common.Page; using GxPress.Repository.Interface; using GxPress.Repository.Interface.Group; using GxPress.Request.App.Group; using GxPress.Request.App.GroupUser; using GxPress.Request.App.Topic; using GxPress.Result; using GxPress.Result.App.Group; using GxPress.Result.App.GroupUser; using GxPress.Result.App.Topic; using GxPress.Result.Web; using GxPress.Service.Interface.Group; using GxPress.Service.Interface.GroupCategory; using GxPress.Service.Interface.Topic; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; namespace GxPress.Api.AppControllers { /// /// 小组 /// [Route("api/app/group")] [ApiController] [Authorize] public class GroupController : ControllerBase { private readonly ILogger _logger; private readonly IGroupRepository _groupRepository; private readonly IGroupUserRepository _groupUserRepository; private readonly IGroupFolderRepository _groupFolderRepository; private readonly IGroupService _groupService; private readonly ILoginContext _loginContext; private readonly ITopicRepository _topicRepository; private readonly ITopicService _topicService; private readonly IGroupCategoryRepository groupCategoryRepository; private readonly IUserGroupCategoryRepository userGroupCategoryRepository; private readonly IGroupCategoryService groupCategoryService; public GroupController(ILogger logger, IGroupRepository groupRepository, IGroupFolderRepository groupFolderRepository, IGroupUserRepository groupUserRepository, ILoginContext loginContext, IGroupService groupService, ITopicRepository topicRepository, ITopicService topicService, IGroupCategoryRepository groupCategoryRepository, IUserGroupCategoryRepository userGroupCategoryRepository, IGroupCategoryService groupCategoryService) { _logger = logger; _groupFolderRepository = groupFolderRepository; _groupRepository = groupRepository; _groupUserRepository = groupUserRepository; _loginContext = loginContext; _groupService = groupService; _topicRepository = topicRepository; _topicService = topicService; this.groupCategoryRepository = groupCategoryRepository; this.userGroupCategoryRepository = userGroupCategoryRepository; this.groupCategoryService = groupCategoryService; } /// /// 新建小组 /// /// /// [HttpPut("insert")] public async Task Insert(GroupInRequest request) { request.UserId = _loginContext.AccountId; var result = await _groupService.InsertGroup(request); //插入小组用户 if (result.Id > 0 && request.UserIds.Count > 0) { var groupUserInRequest = new GroupUserInRequest(); groupUserInRequest.UserId = request.UserId; groupUserInRequest.UserIds = request.UserIds; groupUserInRequest.SourceType = 2; groupUserInRequest.GroupId = result.Id; await _groupService.InsertsAsync(groupUserInRequest); } return result; } /// /// 添加小组成员 /// /// /// [HttpPost("insert-user")] public async Task> AddGroupUser(GroupUserInRequest request) { request.UserId = _loginContext.AccountId; return await _groupService.InsertsAsync(request); } /// /// 删除小组成员 /// /// /// [HttpPost("delete-user")] public async Task DeleteGroupUser(GroupUserDeRequest request) { request.UserId = _loginContext.AccountId; return await _groupService.DeleteAsync(request); } /// /// 退出小组 /// /// /// [HttpDelete("{groupId}")] public async Task DeleteAsync(int groupId) { return await _groupService.DeleteAsync(_loginContext.AccountId, groupId); } /// /// 根据文件夹ID查询小组列表 /// /// /// [HttpPost("find")] public async Task> FindGroupByGroupFolderId(GroupSearchRequest request) { request.UserId = _loginContext.AccountId; return await _groupService.FindGroupByGroupFolderIdAsync(request); } /// /// 获取小组详情 /// /// /// [HttpPost("detail")] public async Task GroupDetailAsync(GroupDetailRequest request) { request.UserId = _loginContext.AccountId; return await _groupService.GroupDetailAsync(request); } /// /// 修改小组 /// /// /// [HttpPost("update")] public async Task Update(GroupUpRequest request) { return await _groupRepository.UpdateAsync(request); } /// /// 是否添加到通讯录 /// /// /// [HttpPut("contacts/{groupId}")] public async Task UpdateContactsAsync(int groupId) { return await _groupRepository.UpdateContactsAsync(groupId, _loginContext.AccountId); } /// ///设置权限 /// 1 超级管理员 2 管理员 3普通用户 /// /// /// [HttpPost("update-user")] public async Task UpdateGroupUser(GroupUserUpRequest request) { return await _groupUserRepository.UpdateAsync(request); } /// /// 根据GroupId获取话题列表 /// /// /// [HttpPost("search")] public async Task> FindTopicByGroupId(TopicDetailListRequest request) { request.UserId = _loginContext.AccountId; return await _topicService.FindTopicByGroupIdAsync(request); } /// /// 加入是否管理员同意 /// /// /// [HttpPut("set-admin/{groupId}")] public async Task SetGroupIsAdmin(int groupId) { return await _groupRepository.SetGroupIsAdminAsync(groupId); } /// /// 是否禁言 /// /// /// [HttpPut("set-words/{groupId}")] public async Task SetGroupIsWords(int groupId) { return await _groupRepository.SetGroupIsWordsAsync(groupId); } /// /// 扫描二维码获取小组详情 /// /// /// [HttpGet("{guId}")] public async Task GroupDetailByGuId(string guId) { var userId = _loginContext.AccountId; return await _groupService.GroupDetailByGuIdAsync(guId, userId); } /// /// 设置用户是否免打扰 /// /// /// [HttpPut("set-disturb/{groupId}")] public async Task SetIsUDisturbAsync(int groupId) { var userId = _loginContext.AccountId; return await _groupUserRepository.SetIsUDisturbAsync(groupId, userId); } /// /// 搜索小组成员 /// /// /// [HttpPost("search-group-user")] public async Task> SearchGroupUserAsync(TopicDetailListRequest request) { return await _groupRepository.SearchGroupUserAsync(request); } /// /// 根据广场类别查询小组 /// /// /// [HttpGet("category-list/{categoryId}")] public async Task> GetAllAsync(int categoryId) { return await _groupService.GetAllAsync(categoryId, _loginContext.AccountId); } /// /// 根据parendId获取小组广场 /// /// /// [HttpGet("group-category/{parentId}")] [AllowAnonymous] public async Task> GetGroupCategoryAsync(int parentId) { return await groupCategoryService.GetGroupCategoryAsync(parentId, _loginContext.AccountId); } /// /// 或者最近使用的小组 /// /// [HttpGet("lately-group")] public async Task> GetLatelyGroupDetailResultAsync() { return await _groupRepository.GetLatelyGroupDetailResultAsync(_loginContext.AccountId); } /// /// 小组转移 /// /// /// /// [HttpPut("transfer")] public async Task SetGroupTransferAsync(GroupTransferReqeust request) { request.UserId = _loginContext.AccountId; return await _groupService.SetGroupTransferAsync(request); } /// /// /// 小组列表 搜索专用 /// /// [HttpGet("list")] public async Task> GetUserGroupListAsync() { return await _groupRepository.GetUserGroupListAsync(_loginContext.AccountId); } /// /// 小组广场搜索 /// /// /// [HttpGet("search")] public async Task> GetSearchGroupAsync([FromQuery] string keyWord) { return await _groupRepository.GetSearchGroupAsync(keyWord, _loginContext.AccountId); } /// /// 添加小组广场用户排序 /// /// /// [HttpPost("user-group-category")] public async Task InsertAsync(IEnumerable request) { return await userGroupCategoryRepository.InsertAsync(request, _loginContext.AccountId); } } }