Skip to content

Commit

Permalink
user groups add page
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyunchong committed May 22, 2024
1 parent 7df7355 commit faf7466
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 27 deletions.
13 changes: 12 additions & 1 deletion src/LinCms.Application.Contracts/Cms/Groups/CreateGroupDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using LinCms.Data;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace LinCms.Cms.Groups;
Expand All @@ -14,4 +15,14 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
yield return new ValidationResult("请选择权限", new List<string> { "PermissionIds" });
}
}
}

public class GroupQuery:PageDto
{
public string Name { get; set; }

/// <summary>
/// 权限组描述
/// </summary>
public string Info { get; set; }
}
3 changes: 2 additions & 1 deletion src/LinCms.Application.Contracts/Cms/Groups/IGroupService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using IGeekFan.FreeKit.Extras.Dto;
using LinCms.Entities;

namespace LinCms.Cms.Groups;

public interface IGroupService
{
Task<List<LinGroup>> GetListAsync();
Task<PagedResultDto<LinGroup>> GetListAsync(GroupQuery query);

Task<GroupDto> GetAsync(long id);

Expand Down
2 changes: 1 addition & 1 deletion src/LinCms.Application.Contracts/Cms/Users/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IUserService
/// </summary>
/// <param name="searchDto"></param>
/// <returns></returns>
PagedResultDto<UserDto> GetUserListByGroupId(UserSearchDto searchDto);
Task<PagedResultDto<UserDto>> GetListAsync(UserSearchDto searchDto);

/// <summary>
/// 修改用户状态
Expand Down

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

11 changes: 8 additions & 3 deletions src/LinCms.Application/Cms/Groups/GroupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
using System.Linq;
using System.Threading.Tasks;
using FreeSql.Internal.ObjectPool;
using IGeekFan.FreeKit.Extras.Dto;
using IGeekFan.FreeKit.Extras.FreeSql;
using LinCms.Cms.Permissions;
using LinCms.Common;
using LinCms.Data;
using LinCms.Data.Enums;
using LinCms.Entities;
using LinCms.Exceptions;
using LinCms.Extensions;
using LinCms.Security;
using Microsoft.AspNetCore.Http;

Expand All @@ -21,13 +24,15 @@ public class GroupService(IFreeSql freeSql,
IAuditBaseRepository<LinGroupPermission, long> groupPermissionRepository)
: ApplicationService, IGroupService
{
public async Task<List<LinGroup>> GetListAsync()
public async Task<PagedResultDto<LinGroup>> GetListAsync(GroupQuery query)
{
List<LinGroup> linGroups = await groupRepository.Select
.WhereIf(query.Name.IsNotNullOrWhiteSpace(), r => r.Name.Contains(query.Name))
.WhereIf(query.Info.IsNotNullOrWhiteSpace(), r => r.Info.Contains(query.Info))
.OrderBy(r => r.SortCode)
.ToListAsync();
.ToPagerListAsync(query, out long count);

return linGroups;
return new PagedResultDto<LinGroup>(linGroups, count);
}

public async Task<GroupDto> GetAsync(long id)
Expand Down
8 changes: 4 additions & 4 deletions src/LinCms.Application/Cms/Users/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task ChangePasswordAsync(ChangePasswordDto passwordDto)
{
throw new LinCmsException("旧密码不正确");
}
if(user.Salt.IsNullOrWhiteSpace())
if (user.Salt.IsNullOrWhiteSpace())
{
user.Salt = Guid.NewGuid().ToString();
await userRepository.UpdateAsync(user);
Expand Down Expand Up @@ -75,16 +75,16 @@ public async Task ResetPasswordAsync(long id, ResetPasswordDto resetPasswordDto)
await userIdentityService.ChangePasswordAsync(id, resetPasswordDto.ConfirmPassword, user.Salt);
}

public PagedResultDto<UserDto> GetUserListByGroupId(UserSearchDto searchDto)
public async Task<PagedResultDto<UserDto>> GetListAsync(UserSearchDto searchDto)
{
List<UserDto> linUsers = userRepository.Select
List<UserDto> linUsers = (await userRepository.Select
.IncludeMany(r => r.LinGroups)
.WhereIf(searchDto.GroupId != null, r => r.LinUserGroups.AsSelect().Any(u => u.GroupId == searchDto.GroupId))
.WhereIf(searchDto.Email.IsNotNullOrWhiteSpace(), r => r.Email.Contains(searchDto.Email))
.WhereIf(searchDto.Nickname.IsNotNullOrWhiteSpace(), r => r.Nickname.Contains(searchDto.Nickname))
.WhereIf(searchDto.Username.IsNotNullOrWhiteSpace(), r => r.Username.Contains(searchDto.Username))
.OrderByDescending(r => r.Id)
.ToPagerList(searchDto, out long totalCount)
.ToPagerListAsync(searchDto, out long totalCount))
.Select(r =>
{
UserDto userDto = Mapper.Map<UserDto>(r);
Expand Down
4 changes: 2 additions & 2 deletions src/LinCms.Web/Controllers/Cms/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class AdminController(IUserService userSevice, IAdminService adminService
/// <returns></returns>
[HttpGet("users")]
[LinCmsAuthorize("查询所有用户", "管理员")]
public PagedResultDto<UserDto> GetUserListByGroupId([FromQuery] UserSearchDto searchDto)
public Task<PagedResultDto<UserDto>> GetListAsync([FromQuery] UserSearchDto searchDto)
{
return userSevice.GetUserListByGroupId(searchDto);
return userSevice.GetListAsync(searchDto);
}

/// <summary>
Expand Down
23 changes: 12 additions & 11 deletions src/LinCms.Web/Controllers/Cms/GroupController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using IGeekFan.FreeKit.Extras.Dto;
using LinCms.Aop.Filter;
using LinCms.Cms.Groups;
using LinCms.Data;
Expand All @@ -9,22 +10,22 @@
namespace LinCms.Controllers.Cms;

/// <summary>
/// 分组
/// 权限组
/// </summary>
[ApiExplorerSettings(GroupName = "cms")]
[Route("cms/admin/group")]
[ApiController]
public class GroupController(IGroupService groupService) : ControllerBase
{
[HttpGet("all")]
[LinCmsAuthorize("查询所有权限组", "管理员")]
public Task<List<LinGroup>> GetListAsync()
[HttpGet]
[LinCmsAuthorize("查询权限组", "管理员")]
public Task<PagedResultDto<LinGroup>> GetListAsync([FromQuery] GroupQuery query)
{
return groupService.GetListAsync();
return groupService.GetListAsync(query);
}

[HttpGet("{id}")]
[LinCmsAuthorize("查询一个权限组及其权限", "管理员")]
[LinCmsAuthorize("查询权限组", "管理员")]
public async Task<GroupDto> GetAsync(long id)
{
GroupDto groupDto = await groupService.GetAsync(id);
Expand All @@ -36,23 +37,23 @@ public async Task<GroupDto> GetAsync(long id)
public async Task<UnifyResponseDto> CreateAsync([FromBody] CreateGroupDto inputDto)
{
await groupService.CreateAsync(inputDto);
return UnifyResponseDto.Success("新建分组成功");
return UnifyResponseDto.Success("新建权限组成功");
}

[HttpPut("{id}")]
[LinCmsAuthorize("更新一个权限组", "管理员")]
[LinCmsAuthorize("更新权限组", "管理员")]
public async Task<UnifyResponseDto> UpdateAsync(long id, [FromBody] UpdateGroupDto updateGroupDto)
{
await groupService.UpdateAsync(id, updateGroupDto);
return UnifyResponseDto.Success("更新分组成功");
return UnifyResponseDto.Success("更新权限组成功");
}

[HttpDelete("{id}")]
[LinCmsAuthorize("删除一个权限组", "管理员")]
[LinCmsAuthorize("删除权限组", "管理员")]
public async Task<UnifyResponseDto> DeleteAsync(long id)
{
await groupService.DeleteAsync(id);
return UnifyResponseDto.Success("删除分组成功");
return UnifyResponseDto.Success("删除权限组成功");
}

}
6 changes: 3 additions & 3 deletions src/LinCms.Web/LinCms.Web.xml

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

0 comments on commit faf7466

Please sign in to comment.