Update Features

This commit is contained in:
drunkensailor666 2024-07-16 14:31:26 +07:00
parent 23690cc6cf
commit 235050705d
101 changed files with 1798 additions and 1401 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
using AutoMapper;
using MiniSkeletonAPI.Application.Common.Interfaces;
using MiniSkeletonAPI.Application.Identity.Roles.Queries.GetRolesWithPagination;
using MiniSkeletonAPI.Application.Identity.Roles.Dtos;
using MiniSkeletonAPI.Application.Identity.Users.Queries.GetUsersWithPagination;
using MiniSkeletonAPI.Domain.Entities;
using MiniSkeletonAPI.Infrastructure.Identity;
@ -12,7 +12,7 @@ using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace MiniSkeletonAPI.Application.Common.Mappings
namespace MiniSkeletonAPI.Infrastructure.Common.Mappings
{
public class MappingProfile : Profile
{

View File

@ -107,8 +107,8 @@ public class ApplicationDbContextInitialiser
//await _roleManager.CreateAsync(new IdentityRole("Administrators"));
var adminRole = await _roleManager.FindByNameAsync("Administrator");
//await _roleManager.AddClaimAsync(adminRole, new Claim(CustomClaimTypes.Permission, Permissions.Dashboards.View));
//await _roleManager.AddClaimAsync(adminRole, new Claim(CustomClaimTypes.Permission, Permissions.Dashboards.Create));
await _roleManager.AddClaimAsync(adminRole, new Claim(CustomClaimTypes.Permission, Permissions.Dashboards.View));
await _roleManager.AddClaimAsync(adminRole, new Claim(CustomClaimTypes.Permission, Permissions.Dashboards.Create));
// Default data
// Seed, if necessary
if (!_context.TodoLists.Any())

View File

@ -1,21 +1,21 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using MiniSkeletonAPI.Application.Common.Models;
using MiniSkeletonAPI.Infrastructure.Identity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using MiniSkeletonAPI.Application.Common.Interfaces;
using MiniSkeletonAPI.Domain.Entities;
using MiniSkeletonAPI.Infrastructure.Data;
using System.Text.Json;
using static System.Runtime.InteropServices.JavaScript.JSType;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using MiniSkeletonAPI.Application.Common.Mappings;
using MiniSkeletonAPI.Application.Identity.Users.Queries.GetUsersWithPagination;
using MiniSkeletonAPI.Application.Identity.Roles.Queries.GetRolesWithPagination;
using MiniSkeletonAPI.Application.Identity.Permissions.Dtos;
using MiniSkeletonAPI.Infrastructure.Common.Helpers;
using System.Reflection;
using System.Security.Claims;
using MiniSkeletonAPI.Application.Identity.Users.Dtos;
using MiniSkeletonAPI.Application.Identity.Roles.Dtos;
namespace MiniSkeletonAPI.Infrastructure.Identity;
public class IdentityService : IIdentityService
@ -211,4 +211,37 @@ public class IdentityService : IIdentityService
return result.ToApplicationResult();
}
public async Task<(Result Result, string UserId)> AddUserRolesAsync(UserRolesDto userRoles)
{
var user = await _userManager.FindByIdAsync(userRoles.UserId);
foreach (var role in userRoles.RoleIds)
{
var entityrole = await _roleManager.FindByIdAsync(role);
_userManager.AddToRoleAsync(user,entityrole.Name);
}
return (Result.Success(), user.Id);
}
public async Task<(Result Result, string UserId)> AddUserPermissionsAsync(UserPermissionsDto pmsRole)
{
var user = await _userManager.FindByIdAsync(pmsRole.UserId);
foreach (var permission in pmsRole.Permissions)
{
await _userManager.AddPermissionClaim(user,permission);
}
return (Result.Success(), user.Id);
}
public async Task<(Result Result, string RoleId)> AddRolePermissionsAsync(RolePermissionsDto pmsRole)
{
var role = await _roleManager.FindByIdAsync(pmsRole.RoleId);
foreach (var permission in pmsRole.Permissions)
{
await _roleManager.AddPermissionClaim(role, permission);
}
return (Result.Success(), role.Id);
}
}

View File

@ -1,4 +1,10 @@
namespace MiniSkeletonAPI.Infrastructure.Identity.Permission
using Microsoft.VisualBasic;
using Newtonsoft.Json.Linq;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Nodes;
namespace MiniSkeletonAPI.Infrastructure.Identity.Permission
{
public static class Permissions
{
@ -28,16 +34,100 @@
public const string Edit = "Permissions.Users.Edit";
public const string Delete = "Permissions.Users.Delete";
}
//public static class Products
//{
// public const string View = "Permissions.Products.View";
// public const string Create = "Permissions.Products.Create";
// public const string Edit = "Permissions.Products.Edit";
// public const string Delete = "Permissions.Products.Delete";
//}
public static class Roles
{
public const string View = "Permissions.Roles.View";
public const string Create = "Permissions.Roles.Create";
public const string Edit = "Permissions.Roles.Edit";
public const string Delete = "Permissions.Roles.Delete";
}
public static class TodoItems
{
public const string View = "Permissions.TodoItems.View";
public const string Create = "Permissions.TodoItems.Create";
public const string Edit = "Permissions.TodoItems.Edit";
public const string Delete = "Permissions.TodoItems.Delete";
}
public static class GetPermissions
{
public const string View = "Permissions.GetPermissions.View";
public const string Create = "Permissions.GetPermissions.Create";
public const string Edit = "Permissions.GetPermissions.Edit";
public const string Delete = "Permissions.GetPermissions.Delete";
}
public static class TodoLists
{
public const string View = "Permissions.TodoLists.View";
public const string Create = "Permissions.TodoLists.Create";
public const string Edit = "Permissions.TodoLists.Edit";
public const string Delete = "Permissions.TodoLists.Delete";
}
}
public class CustomClaimTypes
{
public const string Permission = "Permission";
}
public class StaticSerialization
{
//public static JObject Serialize(Type staticClass)
//{
// //var props = staticClass.GetProperties(BindingFlags.Static | BindingFlags.Public);
// var props = staticClass.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
// //Console.WriteLine(JsonSerializer.Serialize(staticClass.));
// var json = new JObject();
// foreach (var p in props)
// {
// var value = p.GetValue(null);
// //if (value == null || !p.CanWrite || !p.CanRead) continue;
// json[p.Name] = JToken.FromObject(value);
// }
// foreach (var t in staticClass.GetNestedTypes())
// json[t.Name] = Serialize(t);
// return json;
//}
public static IEnumerable<string> GetFieldFromStaticClass(Type staticClass)
{
var nestedTypes = staticClass.GetNestedTypes(BindingFlags.Public);
var sClass = new List<FieldInfo[]>();
foreach (Type type in nestedTypes)
{
sClass.Add(type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static));
}
var permissions = new List<string>();
var values = sClass.SelectMany(x => x).ToList();
foreach(var value in values)
{
permissions.Add(value.GetValue(null).ToString());
}
return permissions;
}
//public static void Deserialize(Type staticClass, JObject json)
//{
// if (json == null) return;
// var props = staticClass.GetProperties(BindingFlags.Static | BindingFlags.Public);
// foreach (var p in props)
// {
// if (!json.ContainsKey(p.Name) || !p.CanWrite) continue;
// p.SetValue(null, Convert.ChangeType(json[p.Name], p.PropertyType));
// }
// foreach (var t in staticClass.GetNestedTypes())
// {
// if (!json.ContainsKey(t.Name)) continue;
// Deserialize(t, json[t.Name] as JObject);
// }
//}
}
}

View File

@ -20,6 +20,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>

View File

@ -15,7 +15,8 @@
"Microsoft.EntityFrameworkCore.Design": "8.0.5",
"Microsoft.EntityFrameworkCore.Sqlite": "8.0.5",
"Microsoft.EntityFrameworkCore.Tools": "8.0.5",
"MiniSkeletonAPI.Application": "1.0.0"
"MiniSkeletonAPI.Application": "1.0.0",
"Newtonsoft.Json": "13.0.3"
},
"runtime": {
"MiniSkeletonAPI.Infrastructure.dll": {}
@ -645,6 +646,14 @@
}
}
},
"Newtonsoft.Json/13.0.3": {
"runtime": {
"lib/net6.0/Newtonsoft.Json.dll": {
"assemblyVersion": "13.0.0.0",
"fileVersion": "13.0.3.27908"
}
}
},
"SQLitePCLRaw.bundle_e_sqlite3/2.1.6": {
"dependencies": {
"SQLitePCLRaw.lib.e_sqlite3": "2.1.6",
@ -1245,6 +1254,13 @@
"path": "mono.texttemplating/2.2.1",
"hashPath": "mono.texttemplating.2.2.1.nupkg.sha512"
},
"Newtonsoft.Json/13.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==",
"path": "newtonsoft.json/13.0.3",
"hashPath": "newtonsoft.json.13.0.3.nupkg.sha512"
},
"SQLitePCLRaw.bundle_e_sqlite3/2.1.6": {
"type": "package",
"serviceable": true,

View File

@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("MiniSkeletonAPI.Infrastructure")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7a653f6d34571cc2890f52ce8f5420bdf838ad31")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+23690cc6cfd1a2e53e900ac2af495188aec711a8")]
[assembly: System.Reflection.AssemblyProductAttribute("MiniSkeletonAPI.Infrastructure")]
[assembly: System.Reflection.AssemblyTitleAttribute("MiniSkeletonAPI.Infrastructure")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
c63860dc5e694cd2f494ad227b44fa95a441b2e96bac32623d7f951254dd81ff
9a141473a6c4e9e442c12a22fc8f244939166b7f21e146d0f8bac682dd56d497

View File

@ -1 +1 @@
31ec96ef62c2578f82b3ffb599b310d4a2b9a9ca98a54ccedcec732bf6534c94
0e974f1d6e9bc5b35684d98168fa215012043dcc9cdf503e2ee07581666a8991

View File

@ -17,3 +17,4 @@ D:\DevPT3\MiniSkeletonAPI\src\MiniSkeletonAPI.Infrastructure\obj\Debug\net8.0\re
D:\DevPT3\MiniSkeletonAPI\src\MiniSkeletonAPI.Infrastructure\obj\Debug\net8.0\MiniSkeletonAPI.Infrastructure.pdb
D:\DevPT3\MiniSkeletonAPI\src\MiniSkeletonAPI.Infrastructure\obj\Debug\net8.0\MiniSkeletonAPI.Infrastructure.genruntimeconfig.cache
D:\DevPT3\MiniSkeletonAPI\src\MiniSkeletonAPI.Infrastructure\obj\Debug\net8.0\ref\MiniSkeletonAPI.Infrastructure.dll
D:\DevPT3\MiniSkeletonAPI\src\MiniSkeletonAPI.Infrastructure\obj\Debug\net8.0\MiniSkeletonAPI.Infrastructure.sourcelink.json

View File

@ -243,6 +243,10 @@
"suppressParent": "All",
"target": "Package",
"version": "[8.0.5, )"
},
"Newtonsoft.Json": {
"target": "Package",
"version": "[13.0.3, )"
}
},
"imports": [

View File

@ -943,6 +943,19 @@
"lib/netstandard2.0/Mono.TextTemplating.dll": {}
}
},
"Newtonsoft.Json/13.0.3": {
"type": "package",
"compile": {
"lib/net6.0/Newtonsoft.Json.dll": {
"related": ".xml"
}
},
"runtime": {
"lib/net6.0/Newtonsoft.Json.dll": {
"related": ".xml"
}
}
},
"SQLitePCLRaw.bundle_e_sqlite3/2.1.6": {
"type": "package",
"dependencies": {
@ -2784,6 +2797,36 @@
"mono.texttemplating.nuspec"
]
},
"Newtonsoft.Json/13.0.3": {
"sha512": "HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==",
"type": "package",
"path": "newtonsoft.json/13.0.3",
"files": [
".nupkg.metadata",
".signature.p7s",
"LICENSE.md",
"README.md",
"lib/net20/Newtonsoft.Json.dll",
"lib/net20/Newtonsoft.Json.xml",
"lib/net35/Newtonsoft.Json.dll",
"lib/net35/Newtonsoft.Json.xml",
"lib/net40/Newtonsoft.Json.dll",
"lib/net40/Newtonsoft.Json.xml",
"lib/net45/Newtonsoft.Json.dll",
"lib/net45/Newtonsoft.Json.xml",
"lib/net6.0/Newtonsoft.Json.dll",
"lib/net6.0/Newtonsoft.Json.xml",
"lib/netstandard1.0/Newtonsoft.Json.dll",
"lib/netstandard1.0/Newtonsoft.Json.xml",
"lib/netstandard1.3/Newtonsoft.Json.dll",
"lib/netstandard1.3/Newtonsoft.Json.xml",
"lib/netstandard2.0/Newtonsoft.Json.dll",
"lib/netstandard2.0/Newtonsoft.Json.xml",
"newtonsoft.json.13.0.3.nupkg.sha512",
"newtonsoft.json.nuspec",
"packageIcon.png"
]
},
"SQLitePCLRaw.bundle_e_sqlite3/2.1.6": {
"sha512": "BmAf6XWt4TqtowmiWe4/5rRot6GerAeklmOPfviOvwLoF5WwgxcJHAxZtySuyW9r9w+HLILnm8VfJFLCUJYW8A==",
"type": "package",
@ -3360,7 +3403,8 @@
"Microsoft.EntityFrameworkCore.Design >= 8.0.5",
"Microsoft.EntityFrameworkCore.Sqlite >= 8.0.5",
"Microsoft.EntityFrameworkCore.Tools >= 8.0.5",
"MiniSkeletonAPI.Application >= 1.0.0"
"MiniSkeletonAPI.Application >= 1.0.0",
"Newtonsoft.Json >= 13.0.3"
]
},
"packageFolders": {
@ -3448,6 +3492,10 @@
"suppressParent": "All",
"target": "Package",
"version": "[8.0.5, )"
},
"Newtonsoft.Json": {
"target": "Package",
"version": "[13.0.3, )"
}
},
"imports": [

View File

@ -1,6 +1,6 @@
{
"version": 2,
"dgSpecHash": "7cWD2G2Fj+dIy96NiIYaAVV8Bk/T+solMMx+2nzCqMDZcsZ0pjOHPHqcPtDi9S4956MtQykyCcVgB5Z4MJlqxA==",
"dgSpecHash": "ze2dJzSocydnhHD9EWo8SVMdFGTpMG2sjnDxpHpdDy0kd3Dx+MoifJJtuwMv91aBwWadNv9un2YNNLwM33XbNw==",
"success": true,
"projectFilePath": "D:\\DevPT3\\MiniSkeletonAPI\\src\\MiniSkeletonAPI.Infrastructure\\MiniSkeletonAPI.Infrastructure.csproj",
"expectedPackageFiles": [
@ -51,6 +51,7 @@
"C:\\Users\\muham\\.nuget\\packages\\microsoft.identitymodel.protocols.openidconnect\\7.1.2\\microsoft.identitymodel.protocols.openidconnect.7.1.2.nupkg.sha512",
"C:\\Users\\muham\\.nuget\\packages\\microsoft.identitymodel.tokens\\7.1.2\\microsoft.identitymodel.tokens.7.1.2.nupkg.sha512",
"C:\\Users\\muham\\.nuget\\packages\\mono.texttemplating\\2.2.1\\mono.texttemplating.2.2.1.nupkg.sha512",
"C:\\Users\\muham\\.nuget\\packages\\newtonsoft.json\\13.0.3\\newtonsoft.json.13.0.3.nupkg.sha512",
"C:\\Users\\muham\\.nuget\\packages\\sqlitepclraw.bundle_e_sqlite3\\2.1.6\\sqlitepclraw.bundle_e_sqlite3.2.1.6.nupkg.sha512",
"C:\\Users\\muham\\.nuget\\packages\\sqlitepclraw.core\\2.1.6\\sqlitepclraw.core.2.1.6.nupkg.sha512",
"C:\\Users\\muham\\.nuget\\packages\\sqlitepclraw.lib.e_sqlite3\\2.1.6\\sqlitepclraw.lib.e_sqlite3.2.1.6.nupkg.sha512",

View File

@ -19,8 +19,8 @@ public static class DependencyInjection
services.AddHealthChecks()
.AddDbContextCheck<ApplicationDbContext>();
services.AddExceptionHandler<CustomExceptionHandler>();
//services.AddProblemDetails();
// Customise default API behaviour
services.Configure<ApiBehaviorOptions>(options =>
options.SuppressModelStateInvalidFilter = true);

View File

@ -1,6 +0,0 @@
//namespace MiniSkeletonAPI.Presentation.Endpoints
//{
// public class Permissions
// {
// }
//}

View File

@ -5,6 +5,9 @@ using MiniSkeletonAPI.Application.Identity.Roles.Commands.UpdateRole;
using MiniSkeletonAPI.Application.Identity.Roles.Commands.DeleteRole;
using MiniSkeletonAPI.Application.Common.Models;
using MiniSkeletonAPI.Application.Identity.Roles.Queries.GetRolesWithPagination;
using MiniSkeletonAPI.Application.Identity.Permissions.Commands;
using MiniSkeletonAPI.Application.Identity.Roles.Dtos;
using MiniSkeletonAPI.Application.Identity.Users.Commands.AddUserRoles;
namespace MiniSkeletonAPI.Presentation.Endpoints;
@ -15,24 +18,26 @@ public class Roles : EndpointGroupBase
app.MapGroup(this)
.MapGet(GetRolesWithPagination)
.MapPost(CreateRole)
.MapPut(AddRolePermissions, "Permissions/{roleId}")
.MapPut(AddUserRoles, "User/{userId}")
.MapPut(UpdateRole, "{id}")
.MapDelete(DeleteRole, "{id}")
;
}
[Authorize(Permissions.Dashboards.View)]
public Task<PaginatedList<RoleBriefDto>> GetRolesWithPagination(ISender sender, [AsParameters] GetRolesWithPaginationQuery query)
[Authorize(Permissions.Roles.View)]
public async Task<PaginatedList<RoleBriefDto>> GetRolesWithPagination(ISender sender, [AsParameters] GetRolesWithPaginationQuery query)
{
return sender.Send(query);
return await sender.Send(query);
}
[Authorize(Permissions.Dashboards.Create)]
public Task<Guid> CreateRole(ISender sender, CreateRoleCommand command)
[Authorize(Permissions.Roles.Create)]
public async Task<Guid> CreateRole(ISender sender, CreateRoleCommand command)
{
return sender.Send(command);
return await sender.Send(command);
}
[Authorize(Permissions.Dashboards.Create)]
[Authorize(Permissions.Roles.Edit)]
public async Task<IResult> UpdateRole(ISender sender, Guid id, UpdateRoleCommand command)
{
if (id != command.Id) return Results.BadRequest();
@ -40,9 +45,24 @@ public class Roles : EndpointGroupBase
return Results.NoContent();
}
[Authorize(Permissions.Roles.Delete)]
public async Task<IResult> DeleteRole(ISender sender, Guid id)
{
await sender.Send(new DeleteRoleCommand(id));
return Results.NoContent();
}
[Authorize(Permissions.Roles.Edit)]
public async Task<IResult> AddUserRoles(ISender sender, Guid userId, AddUserRolesCommand command)
{
if (userId != command.UserId) return Results.BadRequest();
await sender.Send(command);
return Results.NoContent();
}
[Authorize(Permissions.Roles.Edit)]
public async Task<IResult> AddRolePermissions(ISender sender, Guid roleId, AddRolePermissionsCommand command)
{
if (roleId != command.RoleId) return Results.BadRequest();
await sender.Send(command);
return Results.NoContent();
}
}

View File

@ -6,6 +6,7 @@ using MiniSkeletonAPI.Application.TodoItems.Commands.UpdateTodoItem;
using MiniSkeletonAPI.Application.TodoItems.Commands.UpdateTodoItemDetail;
using MiniSkeletonAPI.Application.TodoItems.Queries.GetTodoItemsWIthPagination;
using MiniSkeletonAPI.Infrastructure.Identity.Permission;
using System.Text.Json;
namespace MiniSkeletonAPI.Presentation.Endpoints;
@ -21,16 +22,18 @@ public class TodoItems : EndpointGroupBase
.MapDelete(DeleteTodoItem, "{id}");
}
[Authorize(Permissions.Dashboards.View)]
[Authorize(Permissions.TodoItems.View)]
public Task<PaginatedList<TodoItemBriefDto>> GetTodoItemsWithPagination(ISender sender, [AsParameters] GetTodoItemsWithPaginationQuery query)
{
return sender.Send(query);
}
[Authorize(Permissions.Dashboards.Create)]
[Authorize(Permissions.TodoItems.Create)]
public Task<Guid> CreateTodoItem(ISender sender, CreateTodoItemCommand command)
{
return sender.Send(command);
}
[Authorize(Permissions.TodoItems.Edit)]
public async Task<IResult> UpdateTodoItem(ISender sender, Guid id, UpdateTodoItemCommand command)
{
@ -39,6 +42,7 @@ public class TodoItems : EndpointGroupBase
return Results.NoContent();
}
[Authorize(Permissions.TodoItems.Edit)]
public async Task<IResult> UpdateTodoItemDetail(ISender sender, Guid id, UpdateTodoItemDetailCommand command)
{
if (id != command.Id) return Results.BadRequest();
@ -46,6 +50,7 @@ public class TodoItems : EndpointGroupBase
return Results.NoContent();
}
[Authorize(Permissions.TodoItems.Delete)]
public async Task<IResult> DeleteTodoItem(ISender sender, Guid id)
{
await sender.Send(new DeleteTodoItemCommand(id));

View File

@ -7,6 +7,8 @@ using MiniSkeletonAPI.Application.Identity.Users.Commands.DeleteUser;
using MiniSkeletonAPI.Application.Identity.Users.Commands.CreateUser;
using MiniSkeletonAPI.Application.Identity.Users.Commands.UpdateUser;
using MiniSkeletonAPI.Application.Identity.Users.Queries.GetUsersWithPagination;
using MiniSkeletonAPI.Application.Identity.Permissions.Commands;
using MiniSkeletonAPI.Application.Common.Exceptions;
namespace CleanArchitecture.Web.Endpoints;
@ -17,23 +19,27 @@ public class Users : EndpointGroupBase
app.MapGroup(this)
.MapGet(GetUsersWithPagination)
.MapPost(CreateUser)
.MapPut(AddUserPermissions, "Permissions/{userid}")
.MapPut(UpdateUser, "{id}")
.MapDelete(DeleteUser, "{id}")
.MapCustomizedIdentityApi<ApplicationUser>();
.MapCustomizedIdentityApi<ApplicationUser>()
//.HasApiVersion(1.0)
;
}
[Authorize(Permissions.Dashboards.View)]
//[Authorize(Permissions.Users.View)]
public Task<PaginatedList<UserBriefDto>> GetUsersWithPagination(ISender sender, [AsParameters] GetUsersWithPaginationQuery query)
{
throw new Exception();
return sender.Send(query);
}
[Authorize(Permissions.Dashboards.Create)]
[Authorize(Permissions.Users.Create)]
public Task<Guid> CreateUser(ISender sender, CreateUserCommand command)
{
return sender.Send(command);
}
[Authorize(Permissions.Dashboards.Create)]
[Authorize(Permissions.Users.Edit)]
public async Task<IResult> UpdateUser(ISender sender, Guid id, UpdateUserCommand command)
{
if (id != command.Id) return Results.BadRequest();
@ -41,9 +47,18 @@ public class Users : EndpointGroupBase
return Results.NoContent();
}
[Authorize(Permissions.Users.Delete)]
public async Task<IResult> DeleteUser(ISender sender, Guid id)
{
await sender.Send(new DeleteUserCommand(id));
return Results.NoContent();
}
[Authorize(Permissions.Users.Edit)]
public async Task<IResult> AddUserPermissions(ISender sender, Guid userId, AddUserPermissionsCommand command)
{
if (userId != command.UserId) return Results.BadRequest();
await sender.Send(command);
return Results.NoContent();
}
}

View File

@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
namespace MiniSkeletonAPI.Presentation.Helpers
{
public static class ClaimsHelper
{
public static void GetPermissions(this List<RoleClaimsDto> allPermissions, Type policy, string roleId)
{
FieldInfo[] fields = policy.GetFields(BindingFlags.Static | BindingFlags.Public);
foreach (FieldInfo fi in fields)
{
allPermissions.Add(new RoleClaimsDto { Value = fi.GetValue(null).ToString(), Type = "Permissions" });
}
}
public static async Task AddPermissionClaim(this RoleManager<IdentityRole> roleManager, IdentityRole role, string permission)
{
var allClaims = await roleManager.GetClaimsAsync(role);
if (!allClaims.Any(a => a.Type == "Permission" && a.Value == permission))
{
await roleManager.AddClaimAsync(role, new Claim("Permission", permission));
}
}
}
}

View File

@ -1,8 +0,0 @@
namespace MiniSkeletonAPI.Presentation.Helpers;
public class RoleClaimsDto
{
public string Type { get; set; }
public string Value { get; set; }
public bool Selected { get; set; }
}

View File

@ -1,6 +1,7 @@
using MiniSkeletonAPI.Application.Common.Exceptions;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
namespace MiniSkeletonAPI.Presentation.Infrastructure;
@ -14,7 +15,8 @@ public class CustomExceptionHandler : IExceptionHandler
_exceptionHandlers = new()
{
{ typeof(ValidationException), HandleValidationException },
//{ typeof(NotFoundException), HandleNotFoundException },
{ typeof(NotFoundException), HandleNotFoundException },
{ typeof(NotImplementedException), HandleNotImplementedException },
{ typeof(UnauthorizedAccessException), HandleUnauthorizedAccessException },
{ typeof(ForbiddenAccessException), HandleForbiddenAccessException },
};
@ -23,16 +25,33 @@ public class CustomExceptionHandler : IExceptionHandler
public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken)
{
var exceptionType = exception.GetType();
await Console.Out.WriteLineAsync(JsonSerializer.Serialize(exceptionType.Name));
if (_exceptionHandlers.ContainsKey(exceptionType))
{
await _exceptionHandlers[exceptionType].Invoke(httpContext, exception);
return true;
}
else
{
HandleException(httpContext, exception);
}
return false;
}
private async Task HandleException(HttpContext httpContext, Exception ex)
{
httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError;
await httpContext.Response.WriteAsJsonAsync(new ProblemDetails()
{
Status = StatusCodes.Status500InternalServerError,
Type = "https://tools.ietf.org/html/rfc7231#section-6.5.4",
Title = "Internal Server Error.",
Detail = "Internal Server Error."
});
}
private async Task HandleValidationException(HttpContext httpContext, Exception ex)
{
var exception = (ValidationException)ex;
@ -47,6 +66,18 @@ public class CustomExceptionHandler : IExceptionHandler
}
private async Task HandleNotFoundException(HttpContext httpContext, Exception ex)
{
httpContext.Response.StatusCode = StatusCodes.Status404NotFound;
await httpContext.Response.WriteAsJsonAsync(new ProblemDetails()
{
Status = StatusCodes.Status404NotFound,
Type = "https://tools.ietf.org/html/rfc7231#section-6.5.4",
Title = "The specified resource was not found.",
Detail = "Not found"
});
}
private async Task HandleNotImplementedException(HttpContext httpContext, Exception ex)
{
//var exception = (NotFoundException)ex;
@ -57,7 +88,7 @@ public class CustomExceptionHandler : IExceptionHandler
Status = StatusCodes.Status404NotFound,
Type = "https://tools.ietf.org/html/rfc7231#section-6.5.4",
Title = "The specified resource was not found.",
Detail = "Not found"
Detail = "The Function Not Implemented"
});
}

View File

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Asp.Versioning.Http" Version="8.1.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.5">
<PrivateAssets>all</PrivateAssets>

View File

@ -1,9 +1,8 @@
using Microsoft.AspNetCore.Authorization;
using Asp.Versioning;
using Asp.Versioning.Builder;
using MiniSkeletonAPI.Application;
using MiniSkeletonAPI.Infrastructure;
using MiniSkeletonAPI.Infrastructure.Data;
using MiniSkeletonAPI.Infrastructure.Identity;
using MiniSkeletonAPI.Infrastructure.Identity.Permission;
using MiniSkeletonAPI.Presentation;
var builder = WebApplication.CreateBuilder(args);
@ -27,17 +26,17 @@ builder.Services.AddWebServices();
// };
// });
var app = builder.Build();
//app.MapCustomizedIdentityApi<ApplicationUser>();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
await app.InitialiseDatabaseAsync();
}
await app.InitialiseDatabaseAsync();
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
ApiVersionSet apiVersionSet = app.NewApiVersionSet()
.HasApiVersion(new ApiVersion(1))
.HasApiVersion(new ApiVersion(2))
.ReportApiVersions()
.Build();
app.UseHealthChecks("/health");
app.UseHttpsRedirection();
app.UseAuthorization();
@ -55,4 +54,3 @@ app.UseExceptionHandler(options => { });
//app.MapGet("/", () => "Hello World!");
app.MapEndpoints();
app.Run();
public partial class Program { }

View File

@ -8,6 +8,7 @@
".NETCoreApp,Version=v8.0": {
"MiniSkeletonAPI.Presentation/1.0.0": {
"dependencies": {
"Asp.Versioning.Http": "8.1.0",
"Microsoft.AspNetCore.OpenApi": "8.0.5",
"Microsoft.EntityFrameworkCore.Design": "8.0.5",
"Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore": "8.0.5",
@ -20,6 +21,28 @@
"MiniSkeletonAPI.Presentation.dll": {}
}
},
"Asp.Versioning.Abstractions/8.1.0": {
"dependencies": {
"Microsoft.Extensions.Primitives": "8.0.0"
},
"runtime": {
"lib/net8.0/Asp.Versioning.Abstractions.dll": {
"assemblyVersion": "8.1.0.0",
"fileVersion": "8.1.8851.31619"
}
}
},
"Asp.Versioning.Http/8.1.0": {
"dependencies": {
"Asp.Versioning.Abstractions": "8.1.0"
},
"runtime": {
"lib/net8.0/Asp.Versioning.Http.dll": {
"assemblyVersion": "8.1.0.0",
"fileVersion": "8.1.8851.31627"
}
}
},
"AutoMapper/13.0.1": {
"dependencies": {
"Microsoft.Extensions.Options": "8.0.2"
@ -1359,7 +1382,8 @@
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "8.0.5",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "8.0.6",
"Microsoft.EntityFrameworkCore.Sqlite": "8.0.5",
"MiniSkeletonAPI.Application": "1.0.0"
"MiniSkeletonAPI.Application": "1.0.0",
"Newtonsoft.Json": "13.0.3"
},
"runtime": {
"MiniSkeletonAPI.Infrastructure.dll": {}
@ -1373,6 +1397,20 @@
"serviceable": false,
"sha512": ""
},
"Asp.Versioning.Abstractions/8.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-mpeNZyMdvrHztJwR1sXIUQ+3iioEU97YMBnFA9WLbsPOYhGwDJnqJMmEd8ny7kcmS9OjTHoEuX/bSXXY3brIFA==",
"path": "asp.versioning.abstractions/8.1.0",
"hashPath": "asp.versioning.abstractions.8.1.0.nupkg.sha512"
},
"Asp.Versioning.Http/8.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Xu4xF62Cu9JqYi/CTa2TiK5kyHoa4EluPynj/bPFWDmlTIPzuJQbBI5RgFYVRFHjFVvWMoA77acRaFu7i7Wzqg==",
"path": "asp.versioning.http/8.1.0",
"hashPath": "asp.versioning.http.8.1.0.nupkg.sha512"
},
"AutoMapper/13.0.1": {
"type": "package",
"serviceable": true,

View File

@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("MiniSkeletonAPI.Presentation")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7a653f6d34571cc2890f52ce8f5420bdf838ad31")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+23690cc6cfd1a2e53e900ac2af495188aec711a8")]
[assembly: System.Reflection.AssemblyProductAttribute("MiniSkeletonAPI.Presentation")]
[assembly: System.Reflection.AssemblyTitleAttribute("MiniSkeletonAPI.Presentation")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
c84ece252e926a8d8db682d4bfdfcee76db67811612f73e7e8c4c3cdbffd4959
f11af4d06d5d5309d02728ceefe793f1eeac69aa03222dea09e3c730091b755d

View File

@ -1 +1 @@
981ddd4ab5af31082a46721147caf582430470423fe1e2981af7dc26a8235467
20584d4b7787fc59386d7ed18434d4c434a9843f8e25dd4594afd06deab1dcf8

View File

@ -169,3 +169,6 @@ D:\DevPT3\MiniSkeletonAPI\src\MiniSkeletonAPI.Presentation\bin\Debug\net8.0\Micr
D:\DevPT3\MiniSkeletonAPI\src\MiniSkeletonAPI.Presentation\bin\Debug\net8.0\Microsoft.IdentityModel.Protocols.OpenIdConnect.dll
D:\DevPT3\MiniSkeletonAPI\src\MiniSkeletonAPI.Presentation\bin\Debug\net8.0\Microsoft.IdentityModel.Tokens.dll
D:\DevPT3\MiniSkeletonAPI\src\MiniSkeletonAPI.Presentation\bin\Debug\net8.0\System.IdentityModel.Tokens.Jwt.dll
D:\DevPT3\MiniSkeletonAPI\src\MiniSkeletonAPI.Presentation\obj\Debug\net8.0\MiniSkeletonAPI.Presentation.sourcelink.json
D:\DevPT3\MiniSkeletonAPI\src\MiniSkeletonAPI.Presentation\bin\Debug\net8.0\Asp.Versioning.Abstractions.dll
D:\DevPT3\MiniSkeletonAPI\src\MiniSkeletonAPI.Presentation\bin\Debug\net8.0\Asp.Versioning.Http.dll

View File

@ -243,6 +243,10 @@
"suppressParent": "All",
"target": "Package",
"version": "[8.0.5, )"
},
"Newtonsoft.Json": {
"target": "Package",
"version": "[13.0.3, )"
}
},
"imports": [
@ -318,6 +322,10 @@
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"Asp.Versioning.Http": {
"target": "Package",
"version": "[8.1.0, )"
},
"Microsoft.AspNetCore.OpenApi": {
"target": "Package",
"version": "[8.0.5, )"

View File

@ -2,6 +2,41 @@
"version": 3,
"targets": {
"net8.0": {
"Asp.Versioning.Abstractions/8.1.0": {
"type": "package",
"dependencies": {
"Microsoft.Extensions.Primitives": "8.0.0"
},
"compile": {
"lib/net8.0/Asp.Versioning.Abstractions.dll": {
"related": ".xml"
}
},
"runtime": {
"lib/net8.0/Asp.Versioning.Abstractions.dll": {
"related": ".xml"
}
}
},
"Asp.Versioning.Http/8.1.0": {
"type": "package",
"dependencies": {
"Asp.Versioning.Abstractions": "8.1.0"
},
"compile": {
"lib/net8.0/Asp.Versioning.Http.dll": {
"related": ".xml"
}
},
"runtime": {
"lib/net8.0/Asp.Versioning.Http.dll": {
"related": ".xml"
}
},
"frameworkReferences": [
"Microsoft.AspNetCore.App"
]
},
"AutoMapper/13.0.1": {
"type": "package",
"dependencies": {
@ -2216,7 +2251,8 @@
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "8.0.5",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "8.0.6",
"Microsoft.EntityFrameworkCore.Sqlite": "8.0.5",
"MiniSkeletonAPI.Application": "1.0.0"
"MiniSkeletonAPI.Application": "1.0.0",
"Newtonsoft.Json": "13.0.3"
},
"compile": {
"bin/placeholder/MiniSkeletonAPI.Infrastructure.dll": {}
@ -2228,6 +2264,42 @@
}
},
"libraries": {
"Asp.Versioning.Abstractions/8.1.0": {
"sha512": "mpeNZyMdvrHztJwR1sXIUQ+3iioEU97YMBnFA9WLbsPOYhGwDJnqJMmEd8ny7kcmS9OjTHoEuX/bSXXY3brIFA==",
"type": "package",
"path": "asp.versioning.abstractions/8.1.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"LICENSE.txt",
"README.md",
"asp.versioning.abstractions.8.1.0.nupkg.sha512",
"asp.versioning.abstractions.nuspec",
"icon.png",
"lib/net8.0/Asp.Versioning.Abstractions.dll",
"lib/net8.0/Asp.Versioning.Abstractions.xml",
"lib/netstandard1.0/Asp.Versioning.Abstractions.dll",
"lib/netstandard1.0/Asp.Versioning.Abstractions.xml",
"lib/netstandard2.0/Asp.Versioning.Abstractions.dll",
"lib/netstandard2.0/Asp.Versioning.Abstractions.xml"
]
},
"Asp.Versioning.Http/8.1.0": {
"sha512": "Xu4xF62Cu9JqYi/CTa2TiK5kyHoa4EluPynj/bPFWDmlTIPzuJQbBI5RgFYVRFHjFVvWMoA77acRaFu7i7Wzqg==",
"type": "package",
"path": "asp.versioning.http/8.1.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"LICENSE.txt",
"README.md",
"asp.versioning.http.8.1.0.nupkg.sha512",
"asp.versioning.http.nuspec",
"icon.png",
"lib/net8.0/Asp.Versioning.Http.dll",
"lib/net8.0/Asp.Versioning.Http.xml"
]
},
"AutoMapper/13.0.1": {
"sha512": "/Fx1SbJ16qS7dU4i604Sle+U9VLX+WSNVJggk6MupKVkYvvBm4XqYaeFuf67diHefHKHs50uQIS2YEDFhPCakQ==",
"type": "package",
@ -6864,6 +6936,7 @@
},
"projectFileDependencyGroups": {
"net8.0": [
"Asp.Versioning.Http >= 8.1.0",
"Microsoft.AspNetCore.OpenApi >= 8.0.5",
"Microsoft.EntityFrameworkCore.Design >= 8.0.5",
"Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore >= 8.0.5",
@ -6930,6 +7003,10 @@
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"Asp.Versioning.Http": {
"target": "Package",
"version": "[8.1.0, )"
},
"Microsoft.AspNetCore.OpenApi": {
"target": "Package",
"version": "[8.0.5, )"

View File

@ -1,9 +1,11 @@
{
"version": 2,
"dgSpecHash": "sZl4PpiRDC+uLEIysu8qBrZ0+AwbrNpPOPTIgNJQwpzH1qqmslOpKTiey5w1VDoHVqN3dWB40G2A5LjIW+ObjQ==",
"dgSpecHash": "qWqlMh8NmW5cjy2z4cd26HGi2RfPjPyPP7CgXexY+l1I0T5fUtsGa/EeUuA8ZGXtC92G/6WeeEEDM5csrNhqIw==",
"success": true,
"projectFilePath": "D:\\DevPT3\\MiniSkeletonAPI\\src\\MiniSkeletonAPI.Presentation\\MiniSkeletonAPI.Presentation.csproj",
"expectedPackageFiles": [
"C:\\Users\\muham\\.nuget\\packages\\asp.versioning.abstractions\\8.1.0\\asp.versioning.abstractions.8.1.0.nupkg.sha512",
"C:\\Users\\muham\\.nuget\\packages\\asp.versioning.http\\8.1.0\\asp.versioning.http.8.1.0.nupkg.sha512",
"C:\\Users\\muham\\.nuget\\packages\\automapper\\13.0.1\\automapper.13.0.1.nupkg.sha512",
"C:\\Users\\muham\\.nuget\\packages\\fluentvalidation\\11.9.1\\fluentvalidation.11.9.1.nupkg.sha512",
"C:\\Users\\muham\\.nuget\\packages\\fluentvalidation.dependencyinjectionextensions\\11.9.1\\fluentvalidation.dependencyinjectionextensions.11.9.1.nupkg.sha512",

View File

@ -4,3 +4,13 @@ public class ForbiddenAccessException : Exception
{
public ForbiddenAccessException() : base() { }
}
public class NotFoundException : Exception
{
public NotFoundException() : base() { }
}
//public class NotImplementedException : Exception
//{
// public NotImplementedException() : base() { }
//}

View File

@ -20,3 +20,28 @@ public class ValidationException : Exception
public IDictionary<string, string[]> Errors { get; }
}
//public class NotFoundException : Exception
//{
// /// <summary>
// /// Initializes a new instance of the NotFoundException class with a specified name of the queried object and its key.
// /// </summary>
// /// <param name="objectName">Name of the queried object.</param>
// /// <param name="key">The value by which the object is queried.</param>
// public NotFoundException(string key, string objectName)
// : base($"Queried object {objectName} was not found, Key: {key}")
// {
// }
// /// <summary>
// /// Initializes a new instance of the NotFoundException class with a specified name of the queried object, its key,
// /// and the exception that is the cause of this exception.
// /// </summary>
// /// <param name="objectName">Name of the queried object.</param>
// /// <param name="key">The value by which the object is queried.</param>
// /// <param name="innerException">The exception that is the cause of the current exception.</param>
// public NotFoundException(string key, string objectName, Exception innerException)
// : base($"Queried object {objectName} was not found, Key: {key}", innerException)
// {
// }
//}

View File

@ -1,5 +1,8 @@
using MiniSkeletonAPI.Application.Common.Models;
using MiniSkeletonAPI.Application.Identity.Permissions.Dtos;
using MiniSkeletonAPI.Application.Identity.Roles.Dtos;
using MiniSkeletonAPI.Application.Identity.Roles.Queries.GetRolesWithPagination;
using MiniSkeletonAPI.Application.Identity.Users.Dtos;
using MiniSkeletonAPI.Application.Identity.Users.Queries.GetUsersWithPagination;
using MiniSkeletonAPI.Domain.Entities;
@ -20,4 +23,10 @@ public interface IIdentityService
Task<Result> DeleteRoleAsync(string userId);
Task<PaginatedList<RoleBriefDto>> GetRolesPaginatedAsync(GetRolesWithPaginationQuery request);
Task<(Result Result, string UserId)> AddUserRolesAsync(UserRolesDto userRoles);
Task<(Result Result, string RoleId)> AddRolePermissionsAsync(RolePermissionsDto rolePms);
Task<(Result Result, string UserId)> AddUserPermissionsAsync(UserPermissionsDto userPms);
}

View File

@ -14,14 +14,11 @@ public record CreateRoleCommand : IRequest<Guid>
public class CreateRoleCommandHandler : IRequestHandler<CreateRoleCommand, Guid>
{
private readonly IIdentityService _identityService;
//private readonly IApplicationDbContext _context;
private readonly IIdentityService _context;
public CreateRoleCommandHandler(
//IApplicationDbContext context,
IIdentityService identityService)
IIdentityService context)
{
//_context = context;
_identityService = identityService;
_context = context;
}
public async Task<Guid> Handle(CreateRoleCommand request, CancellationToken cancellationToken)
@ -31,8 +28,7 @@ public class CreateRoleCommandHandler : IRequestHandler<CreateRoleCommand, Guid>
Name = request.Name,
};
var entity = await _identityService.CreateRoleAsync(role);
//await _context.SaveChangesAsync(cancellationToken);
var entity = await _context.CreateRoleAsync(role);
return Guid.Parse(entity.RoleId);
}
}

View File

@ -8,10 +8,6 @@ using System.Threading.Tasks;
namespace MiniSkeletonAPI.Application.Identity.Roles.Commands.UpdateRole;
internal class UpdateRole
{
}
public record UpdateRoleCommand : IRequest
{
public required Guid Id { get; init; }
@ -20,15 +16,13 @@ public record UpdateRoleCommand : IRequest
public class UpdateRoleCommandHandler : IRequestHandler<UpdateRoleCommand>
{
//private readonly IApplicationDbContext _context;
private readonly IIdentityService _identityService;
private readonly IIdentityService _context;
public UpdateRoleCommandHandler(
//IApplicationDbContext context,
IIdentityService identityService
IIdentityService context
)
{
_identityService = identityService;
_context = context;
}
public async Task Handle(UpdateRoleCommand request, CancellationToken cancellationToken)
@ -38,6 +32,6 @@ public class UpdateRoleCommandHandler : IRequestHandler<UpdateRoleCommand>
Name = request.Name,
};
var entity = await _identityService.UpdateRoleAsync(role, request.Id.ToString());
var entity = await _context.UpdateRoleAsync(role, request.Id.ToString());
}
}

View File

@ -1,6 +1,6 @@
using MiniSkeletonAPI.Application.Common.Interfaces;
using MiniSkeletonAPI.Application.Common.Models;
using MiniSkeletonAPI.Application.Identity.Roles.Queries.GetRolesWithPagination;
using MiniSkeletonAPI.Application.Identity.Roles.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
@ -18,18 +18,15 @@ public record GetRolesWithPaginationQuery : IRequest<PaginatedList<RoleBriefDto>
public class GetRolesWithPaginationQueryHandler : IRequestHandler<GetRolesWithPaginationQuery, PaginatedList<RoleBriefDto>>
{
private readonly IIdentityService _context;
private readonly IMapper _mapper;
public GetRolesWithPaginationQueryHandler(IIdentityService context, IMapper mapper)
public GetRolesWithPaginationQueryHandler(IIdentityService context)
{
_context = context;
_mapper = mapper;
}
public async Task<PaginatedList<RoleBriefDto>> Handle(GetRolesWithPaginationQuery request, CancellationToken cancellationToken)
{
var data = await _context.GetRolesPaginatedAsync(request);
//_mapper.Map<RoleBriefDto>(data);
return data;
}
}

View File

@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MiniSkeletonAPI.Application.Identity.Roles.Queries.GetRolesWithPagination;
public record RoleBriefDto
{
public string Id { get; init; }
public string Name { get; init; }
//private class Mapping : Profile
//{
// public Mapping()
// {
// CreateMap<User, UserBriefDto>();
// }
//}
}

View File

@ -18,14 +18,11 @@ public record CreateUserCommand : IRequest<Guid>
public class CreateUserCommandHandler : IRequestHandler<CreateUserCommand, Guid>
{
private readonly IIdentityService _identityService;
//private readonly IApplicationDbContext _context;
private readonly IIdentityService _context;
public CreateUserCommandHandler(
//IApplicationDbContext context,
IIdentityService identityService)
IIdentityService context)
{
//_context = context;
_identityService = identityService;
_context = context;
}
public async Task<Guid> Handle(CreateUserCommand request, CancellationToken cancellationToken)
@ -37,8 +34,7 @@ public class CreateUserCommandHandler : IRequestHandler<CreateUserCommand, Guid>
Password = request.Password
};
var entity = await _identityService.CreateUserAsync(user, request.Password);
//await _context.SaveChangesAsync(cancellationToken);
var entity = await _context.CreateUserAsync(user, request.Password);
return Guid.Parse(entity.UserId);
}
}

View File

@ -20,14 +20,6 @@ public class DeleteUserCommandHandler : IRequestHandler<DeleteUserCommand>
public async Task Handle(DeleteUserCommand request, CancellationToken cancellationToken)
{
//var entity = await _context.Users
// .Where(l => l.Id == request.Id)
// .SingleOrDefaultAsync(cancellationToken);
var entity = await _context.DeleteUserAsync(request.Id.ToString());
//Guard.Against.NotFound(request.Id, entity);
//_context.Users.Remove(entity);
//await _context.SaveChangesAsync(cancellationToken);
await _context.DeleteUserAsync(request.Id.ToString());
}
}

View File

@ -20,15 +20,13 @@ public record UpdateUserCommand : IRequest
public class UpdateUserCommandHandler : IRequestHandler<UpdateUserCommand>
{
//private readonly IApplicationDbContext _context;
private readonly IIdentityService _identityService;
private readonly IIdentityService _context;
public UpdateUserCommandHandler(
//IApplicationDbContext context,
IIdentityService identityService
IIdentityService context
)
{
_identityService = identityService;
_context = context;
}
public async Task Handle(UpdateUserCommand request, CancellationToken cancellationToken)
@ -40,7 +38,7 @@ public class UpdateUserCommandHandler : IRequestHandler<UpdateUserCommand>
PhoneNumber = request.PhoneNumber,
Password = request.Password
};
var entity = await _identityService.UpdateUserAsync(user, request.Id.ToString());
var entity = await _context.UpdateUserAsync(user, request.Id.ToString());
}
}

View File

@ -17,18 +17,15 @@ public record GetUsersWithPaginationQuery : IRequest<PaginatedList<UserBriefDto>
public class GetUsersWithPaginationQueryHandler : IRequestHandler<GetUsersWithPaginationQuery, PaginatedList<UserBriefDto>>
{
private readonly IIdentityService _context;
private readonly IMapper _mapper;
public GetUsersWithPaginationQueryHandler(IIdentityService context, IMapper mapper)
public GetUsersWithPaginationQueryHandler(IIdentityService context)
{
_context = context;
_mapper = mapper;
}
public async Task<PaginatedList<UserBriefDto>> Handle(GetUsersWithPaginationQuery request, CancellationToken cancellationToken)
{
var data = await _context.GetUsersPaginatedAsync(request);
//_mapper.Map<UserBriefDto>(data);
return data;
}
}

View File

@ -18,9 +18,9 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Identity\Permissions\Queries\" />
<Folder Include="Identity\Users\Commands\UpdateUserRole\" />
<Folder Include="Identity\Users\Commands\UpdateUserPermission\" />
<Folder Include="Identity\Users\Permissions\" />
</ItemGroup>
</Project>

View File

@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("MiniSkeletonAPI.Application")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7a653f6d34571cc2890f52ce8f5420bdf838ad31")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+23690cc6cfd1a2e53e900ac2af495188aec711a8")]
[assembly: System.Reflection.AssemblyProductAttribute("MiniSkeletonAPI.Application")]
[assembly: System.Reflection.AssemblyTitleAttribute("MiniSkeletonAPI.Application")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
cb517e2b35055e3aecd639984d8e2b14570e56e28b00ae083aa8a309fa9b3ae0
53ba1e480d5d8dbf354c004c983300e958e0198cacba93222777114b65ee07f3

View File

@ -1 +1 @@
89fea7bffcb2bf1520e9b82b1163979c54e38d96fcbffffbf6ddd3d709a01093
4cbbf4ad03251d5015e149412156cf017a7894d5372c32015c89186eb6d97975

View File

@ -13,3 +13,4 @@ D:\DevPT3\MiniSkeletonAPI\src\core\MiniSkeletonAPI.Application\obj\Debug\net8.0\
D:\DevPT3\MiniSkeletonAPI\src\core\MiniSkeletonAPI.Application\obj\Debug\net8.0\refint\MiniSkeletonAPI.Application.dll
D:\DevPT3\MiniSkeletonAPI\src\core\MiniSkeletonAPI.Application\obj\Debug\net8.0\MiniSkeletonAPI.Application.pdb
D:\DevPT3\MiniSkeletonAPI\src\core\MiniSkeletonAPI.Application\obj\Debug\net8.0\ref\MiniSkeletonAPI.Application.dll
D:\DevPT3\MiniSkeletonAPI\src\core\MiniSkeletonAPI.Application\obj\Debug\net8.0\MiniSkeletonAPI.Application.sourcelink.json

View File

@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("MiniSkeletonAPI.Domain")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7a653f6d34571cc2890f52ce8f5420bdf838ad31")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+23690cc6cfd1a2e53e900ac2af495188aec711a8")]
[assembly: System.Reflection.AssemblyProductAttribute("MiniSkeletonAPI.Domain")]
[assembly: System.Reflection.AssemblyTitleAttribute("MiniSkeletonAPI.Domain")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
a04f6b52023919fd39ff71554c9c8eae007c31ecdd946466a2fc1d688309bb4f
4418b0950f3ef09ec3f06b452024f2dd7e5a0c75243d055cff5e26f1b57e92bd

View File

@ -10,3 +10,4 @@ D:\DevPT3\MiniSkeletonAPI\src\core\MiniSkeletonAPI.Domain\obj\Debug\net8.0\MiniS
D:\DevPT3\MiniSkeletonAPI\src\core\MiniSkeletonAPI.Domain\obj\Debug\net8.0\refint\MiniSkeletonAPI.Domain.dll
D:\DevPT3\MiniSkeletonAPI\src\core\MiniSkeletonAPI.Domain\obj\Debug\net8.0\MiniSkeletonAPI.Domain.pdb
D:\DevPT3\MiniSkeletonAPI\src\core\MiniSkeletonAPI.Domain\obj\Debug\net8.0\ref\MiniSkeletonAPI.Domain.dll
D:\DevPT3\MiniSkeletonAPI\src\core\MiniSkeletonAPI.Domain\obj\Debug\net8.0\MiniSkeletonAPI.Domain.sourcelink.json

Some files were not shown because too many files have changed in this diff Show More