using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Common.Page;
using GxPress.Repository.Interface;
using GxPress.Request.App.Group;
using GxPress.Request.App.GroupUser;
using GxPress.Request.App.Topic;
using GxPress.Result.App.Group;
using GxPress.Result.App.GroupUser;
using GxPress.Result.App.Topic;
using GxPress.Service.Interface.Group;
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;
public GroupController(ILogger logger, IGroupRepository groupRepository,
IGroupFolderRepository groupFolderRepository, IGroupUserRepository groupUserRepository,
ILoginContext loginContext, IGroupService groupService, ITopicRepository topicRepository, ITopicService topicService)
{
_logger = logger;
_groupFolderRepository = groupFolderRepository;
_groupRepository = groupRepository;
_groupUserRepository = groupUserRepository;
_loginContext = loginContext;
_groupService = groupService;
_topicRepository = topicRepository;
_topicService = topicService;
}
///
/// 新建小组
///
///
///
[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)
{
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);
}
///
///设置权限
/// 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);
}
}
}