新增用户接口
This commit is contained in:
parent
f1bf00f4b5
commit
50ee6aa7a2
|
|
@ -58,11 +58,7 @@ namespace WGShare.API.Controllers.Backend
|
|||
.Where(x => ids.Contains(x.Id)).ExecuteCommandHasChangeAsync();
|
||||
}
|
||||
|
||||
[HttpGet("dp-list")]
|
||||
public async Task<List<Role>> GetDropDownList()
|
||||
{
|
||||
return await _sqlSugar.Queryable<Role>().Where(x => x.IsDelete == false).ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("auth-perm")]
|
||||
public async Task<bool> PermAuth([FromQuery] string roleId, [FromBody] List<RolePermInputDTO> inputDTO)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,106 @@
|
|||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using WGShare.API.Controllers.Basic;
|
||||
using WGShare.Domain.DTOs.User;
|
||||
using WGShare.Domain.Entities;
|
||||
using WGShare.Domain.FriendlyException;
|
||||
using WGShare.Domain.GeneralModel;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
namespace WGShare.API.Controllers.Frontend
|
||||
{
|
||||
[ApiExplorerSettings(GroupName = "frontend")]
|
||||
[Route("user")]
|
||||
public class UserController : BasicController
|
||||
{
|
||||
private readonly ISqlSugarClient _sqlSugar;
|
||||
|
||||
public UserController(ISqlSugarClient sqlSugar)
|
||||
{
|
||||
this._sqlSugar = sqlSugar;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("list")]
|
||||
public async Task<List<UserOutputDTO>> GetUserList([FromQuery] string? searchKeywod, [FromQuery] PagedBaseDto pagedBaseDto)
|
||||
{
|
||||
RefAsync<int> total = 0;
|
||||
|
||||
var list = await _sqlSugar.Queryable<User>()
|
||||
.InnerJoin<Role>((u, r) => u.RoleId == r.Id)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(searchKeywod), u => u.UserName.Contains(searchKeywod) || u.Account.Contains(searchKeywod))
|
||||
.ToPageListAsync(pagedBaseDto.PageIndex, pagedBaseDto.PageSize, total);
|
||||
|
||||
return list.Adapt<List<UserOutputDTO>>();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 新增用户
|
||||
/// </summary>
|
||||
/// <param name="inputDTO"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<bool> AddUser([FromQuery] UserInputDTO inputDTO)
|
||||
{
|
||||
var user = inputDTO.Adapt<User>();
|
||||
user.Id = YitIdHelper.NextId().ToString();
|
||||
user.TenantId = TenantId;
|
||||
|
||||
if (await _sqlSugar.Queryable<User>().AnyAsync(x => x.Account == user.Account))
|
||||
{
|
||||
throw Oops.Oh("账号已存在!");
|
||||
}
|
||||
|
||||
|
||||
return await _sqlSugar.Insertable(user).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户信息
|
||||
/// </summary>
|
||||
/// <param name="inputDTO"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<bool> Modify([FromBody] UserInputDTO inputDTO)
|
||||
{
|
||||
var entity = inputDTO.Adapt<User>();
|
||||
|
||||
if (await _sqlSugar.Queryable<User>().AnyAsync(x => x.Account == entity.Account && x.Id != inputDTO.Id))
|
||||
{
|
||||
throw Oops.Oh("账号已存在!");
|
||||
}
|
||||
|
||||
return await _sqlSugar.Updateable(entity)
|
||||
.IgnoreColumns(x => new { x.Pwd, x.TenantId }).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更改密码
|
||||
/// </summary>
|
||||
/// <param name="inputDTO"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("pwd")]
|
||||
public async Task<bool> ModifyPassword([FromBody] UserChangePwdDTO inputDTO)
|
||||
{
|
||||
var entity = inputDTO.Adapt<User>();
|
||||
|
||||
return await _sqlSugar.Updateable(entity)
|
||||
.UpdateColumns(x => new { x.Pwd }).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
public async Task<bool> Delete([FromBody] params string[] ids)
|
||||
{
|
||||
return await _sqlSugar.Updateable<User>()
|
||||
.SetColumns(x => x.IsDelete == true)
|
||||
.Where(x => ids.Contains(x.Id)).ExecuteCommandHasChangeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
using Masuit.Tools;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using System.Configuration;
|
||||
using System.Security.Claims;
|
||||
using WGShare.API.Controllers.Basic;
|
||||
using WGShare.API.Helpers;
|
||||
using WGShare.Domain.DTOs.Login;
|
||||
using WGShare.Domain.Entities;
|
||||
using WGShare.Domain.FriendlyException;
|
||||
|
||||
namespace WGShare.API.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 前后端共用接口
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "public")]
|
||||
[Route("pub")]
|
||||
public class PublicController : BasicController
|
||||
{
|
||||
private readonly ISqlSugarClient _sqlSugar;
|
||||
|
||||
public PublicController(ISqlSugarClient sqlSugar)
|
||||
{
|
||||
_sqlSugar = sqlSugar;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色列表下拉框
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("role-dp-list")]
|
||||
public async Task<List<Role>> GetDropDownList()
|
||||
{
|
||||
return await _sqlSugar.Queryable<Role>().Where(x => x.IsDelete == false).ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -37,40 +37,7 @@ namespace WGShare.API
|
|||
});
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(w =>
|
||||
{
|
||||
w.SwaggerDoc("frontend", new OpenApiInfo { Title = "ǰ¶Ë", Version = "frontend" });
|
||||
w.SwaggerDoc("backend", new OpenApiInfo { Title = "ºó¶Ë", Version = "backend" });
|
||||
w.SwaggerDoc("public", new OpenApiInfo { Title = "¹«¹²½Ó¿Ú", Version = "public" });
|
||||
w.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||
{
|
||||
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
|
||||
Name = "Authorization",
|
||||
In = ParameterLocation.Header,
|
||||
Type = SecuritySchemeType.ApiKey,
|
||||
Scheme = "Bearer"
|
||||
});
|
||||
|
||||
w.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{
|
||||
new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "Bearer"
|
||||
}
|
||||
},
|
||||
new string[] {}
|
||||
}
|
||||
});
|
||||
|
||||
//string xmlPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SwaggerGroup.xml");
|
||||
//w.IncludeXmlComments(xmlPath, true);
|
||||
}
|
||||
);
|
||||
|
||||
builder.Services.AddSwagger();
|
||||
builder.Services.AddSingleton(new JwtHelper(configuration));
|
||||
builder.Services.AddAuth(configuration["Jwt:Issuer"],
|
||||
configuration["Jwt:Audience"],
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
using Mapster;
|
||||
using MapsterMapper;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.Text;
|
||||
using System.Reflection.Metadata;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace WGShare.API.ServiceConfigs
|
||||
{
|
||||
public static class SwaggerServiceExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加认证和授权
|
||||
/// </summary>
|
||||
/// <param name="services">服务集合</param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddSwagger(this IServiceCollection services)
|
||||
{
|
||||
services.AddSwaggerGen(w =>
|
||||
{
|
||||
w.SwaggerDoc("frontend", new OpenApiInfo { Title = "前端", Version = "frontend" });
|
||||
w.SwaggerDoc("backend", new OpenApiInfo { Title = "后端", Version = "backend" });
|
||||
w.SwaggerDoc("public", new OpenApiInfo { Title = "公共接口", Version = "public" });
|
||||
w.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||
{
|
||||
Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
|
||||
Name = "Authorization",
|
||||
In = ParameterLocation.Header,
|
||||
Type = SecuritySchemeType.ApiKey,
|
||||
Scheme = "Bearer"
|
||||
});
|
||||
|
||||
w.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{
|
||||
new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "Bearer"
|
||||
}
|
||||
},
|
||||
new string[] {}
|
||||
}
|
||||
});
|
||||
|
||||
//string xmlPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SwaggerGroup.xml");
|
||||
//w.IncludeXmlComments(xmlPath, true);
|
||||
});
|
||||
|
||||
|
||||
return services;
|
||||
//services.AddAuthorization(options =>
|
||||
//{
|
||||
// options.AddPolicy(Constant.Policy.FreePolicyName,
|
||||
// policy => policy.RequireClaim(Constant.Auth.PermissionsKey, Constant.Auth.FreeClaimValue, Constant.Auth.VipClaimValue));
|
||||
// options.AddPolicy(Constant.Policy.VipPolicyName,
|
||||
// policy => policy.RequireClaim(Constant.Auth.PermissionsKey, Constant.Auth.VipClaimValue));
|
||||
//});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue