another step for constructing base project
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
using Asp.Versioning;
|
||||
using Baya.Application.Features.Admin.Commands.AddAdminCommand;
|
||||
using Baya.Application.Features.Admin.Queries.GetToken;
|
||||
using Baya.Application.Models.Jwt;
|
||||
using Baya.WebFramework.Attributes;
|
||||
using Baya.WebFramework.BaseController;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Baya.Web.Api.Controllers.V1.Admin
|
||||
{
|
||||
[ApiVersion("1")]
|
||||
[ApiController]
|
||||
[Route("api/v{version:apiVersion}/AdminManager")]
|
||||
public class AdminManagerController(ISender sender) : BaseController
|
||||
{
|
||||
[HttpPost("Login")]
|
||||
[ProducesOkApiResponseType<AccessToken>]
|
||||
public async Task<IActionResult> AdminLogin(AdminGetTokenQuery model)
|
||||
{
|
||||
var query = await sender.Send(model);
|
||||
|
||||
return base.OperationResult(query);
|
||||
}
|
||||
|
||||
[Authorize(Roles = "admin")]
|
||||
[HttpPost("NewAdmin")]
|
||||
[ProducesOkApiResponseType]
|
||||
public async Task<IActionResult> AddNewAdmin(AddAdminCommand model)
|
||||
{
|
||||
var commandResult = await sender.Send(model);
|
||||
|
||||
return base.OperationResult(commandResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using Baya.Infrastructure.Identity.Identity.PermissionManager;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Asp.Versioning;
|
||||
using Baya.Application.Features.Order.Queries.GetAllOrders;
|
||||
using Baya.WebFramework.Attributes;
|
||||
using Baya.WebFramework.BaseController;
|
||||
using Mediator;
|
||||
|
||||
namespace Baya.Web.Api.Controllers.V1.Admin
|
||||
{
|
||||
[ApiVersion("1")]
|
||||
[ApiController]
|
||||
[Route("api/v{version:apiVersion}/OrderManagement")]
|
||||
[Display(Description= "Managing Users related Orders")]
|
||||
[Authorize(ConstantPolicies.DynamicPermission)]
|
||||
public class OrderManagementController : BaseController
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
public OrderManagementController(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
[HttpGet("OrderList")]
|
||||
[ProducesOkApiResponseType<List<GetAllOrdersQueryResult>>]
|
||||
public async Task<IActionResult> GetOrders()
|
||||
{
|
||||
var queryResult = await _sender.Send(new GetAllOrdersQuery());
|
||||
|
||||
return base.OperationResult(queryResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Asp.Versioning;
|
||||
using Baya.Application.Features.Role.Commands.AddRoleCommand;
|
||||
using Baya.Application.Features.Role.Commands.UpdateRoleClaimsCommand;
|
||||
using Baya.Application.Features.Role.Queries.GetAllRolesQuery;
|
||||
using Baya.Application.Features.Role.Queries.GetAuthorizableRoutesQuery;
|
||||
using Baya.Infrastructure.Identity.Identity.PermissionManager;
|
||||
using Baya.WebFramework.Attributes;
|
||||
using Baya.WebFramework.BaseController;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Baya.Web.Api.Controllers.V1.Admin
|
||||
{
|
||||
[ApiVersion("1")]
|
||||
[ApiController]
|
||||
[Route("api/v{version:apiVersion}/RoleManager")]
|
||||
[Authorize(ConstantPolicies.DynamicPermission)]
|
||||
[Display(Description = "Managing Related Roles for the System")]
|
||||
|
||||
public class RoleManagerController(ISender sender) : BaseController
|
||||
{
|
||||
[HttpGet("Roles")]
|
||||
[ProducesOkApiResponseType<List<GetAllRolesQueryResponse>>]
|
||||
public async Task<IActionResult> GetRoles()
|
||||
{
|
||||
var queryResult = await sender.Send(new GetAllRolesQuery());
|
||||
|
||||
return base.OperationResult(queryResult);
|
||||
}
|
||||
|
||||
[HttpGet("AuthRoutes")]
|
||||
[ProducesOkApiResponseType<List<GetAuthorizableRoutesQueryResponse>>]
|
||||
public async Task<IActionResult> GetAuthRoutes()
|
||||
{
|
||||
var queryModel = await sender.Send(new GetAuthorizableRoutesQuery());
|
||||
|
||||
return base.OperationResult(queryModel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a role permissions (claims) based on RouteKey received in AuthRoutes API
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("UpdateRolePermissions")]
|
||||
[ProducesOkApiResponseType]
|
||||
public async Task<IActionResult> UpdateRolePermissions(UpdateRoleClaimsCommand model)
|
||||
{
|
||||
var commandResult =
|
||||
await sender.Send(new UpdateRoleClaimsCommand(model.RoleId, model.RoleClaimValue));
|
||||
|
||||
return base.OperationResult(commandResult);
|
||||
}
|
||||
|
||||
[HttpPost("NewRole")]
|
||||
[ProducesOkApiResponseType]
|
||||
public async Task<IActionResult> AddRole(AddRoleCommand model)
|
||||
{
|
||||
var commandResult = await sender.Send(model);
|
||||
|
||||
return base.OperationResult(commandResult);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using Baya.Infrastructure.Identity.Identity.PermissionManager;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Asp.Versioning;
|
||||
using Baya.Application.Features.Users.Queries.GetUsers;
|
||||
using Baya.WebFramework.Attributes;
|
||||
using Baya.WebFramework.BaseController;
|
||||
using Mediator;
|
||||
|
||||
namespace Baya.Web.Api.Controllers.V1.Admin
|
||||
{
|
||||
[ApiVersion("1")]
|
||||
[ApiController]
|
||||
[Route("api/v{version:apiVersion}/UserManagement")]
|
||||
[Display(Description = "Managing API Users")]
|
||||
[Authorize(ConstantPolicies.DynamicPermission)]
|
||||
public class UserManagementController : BaseController
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
public UserManagementController(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
[HttpGet("CurrentUsers")]
|
||||
[ProducesOkApiResponseType<List<GetUsersQueryResponse>>]
|
||||
public async Task<IActionResult> GetAllUsers()
|
||||
{
|
||||
var queryResult = await _sender.Send(new GetUsersQuery());
|
||||
|
||||
return base.OperationResult(queryResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
using Asp.Versioning;
|
||||
using Baya.Application.Features.Order.Commands;
|
||||
using Baya.Application.Features.Order.Queries.GetUserOrders;
|
||||
using Baya.WebFramework.Attributes;
|
||||
using Baya.WebFramework.BaseController;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Baya.Web.Api.Controllers.V1.Order;
|
||||
|
||||
[ApiVersion("1")]
|
||||
[ApiController]
|
||||
[Route("api/v{version:apiVersion}/User")]
|
||||
[Authorize]
|
||||
public class OrderController(ISender sender) : BaseController
|
||||
{
|
||||
[HttpPost("CreateNewOrder")]
|
||||
[ProducesOkApiResponseType]
|
||||
public async Task<IActionResult> CreateNewOrder(AddOrderCommand model)
|
||||
{
|
||||
model.UserId = base.UserId;
|
||||
var command = await sender.Send(model);
|
||||
|
||||
return base.OperationResult(command);
|
||||
}
|
||||
|
||||
[HttpGet("GetUserOrders")]
|
||||
[ProducesOkApiResponseType<List<GetUsersQueryResultModel>>]
|
||||
public async Task<IActionResult> GetUserOrders()
|
||||
{
|
||||
var query = await sender.Send(new GetUserOrdersQueryModel(UserId));
|
||||
|
||||
return base.OperationResult(query);
|
||||
}
|
||||
|
||||
[HttpPut("UpdateOrder")]
|
||||
[ProducesOkApiResponseType]
|
||||
public async Task<IActionResult> UpdateOrder(UpdateUserOrderCommand model)
|
||||
{
|
||||
model.UserId=base.UserId;
|
||||
|
||||
var command = await sender.Send(model);
|
||||
|
||||
return base.OperationResult(command);
|
||||
}
|
||||
|
||||
[HttpDelete("DeleteAllUserOrders")]
|
||||
[ProducesOkApiResponseType]
|
||||
public async Task<IActionResult> DeleteAllUserOrders()
|
||||
=> base.OperationResult(await sender.Send(new DeleteUserOrdersCommand(base.UserId)));
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
using Asp.Versioning;
|
||||
using Baya.Application.Features.Users.Commands.Create;
|
||||
using Baya.Application.Features.Users.Commands.RefreshUserTokenCommand;
|
||||
using Baya.Application.Features.Users.Commands.RequestLogout;
|
||||
using Baya.Application.Features.Users.Queries.GenerateUserToken;
|
||||
using Baya.Application.Features.Users.Queries.TokenRequest;
|
||||
using Baya.Application.Models.Jwt;
|
||||
using Baya.WebFramework.Attributes;
|
||||
using Baya.WebFramework.BaseController;
|
||||
using Baya.WebFramework.Swagger;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Baya.Web.Api.Controllers.V1.UserManagement;
|
||||
|
||||
[ApiVersion("1")]
|
||||
[ApiController]
|
||||
[Route("api/v{version:apiVersion}/User")]
|
||||
public class UserController : BaseController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public UserController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
[HttpPost("Register")]
|
||||
[ProducesOkApiResponseType<UserCreateCommandResult>]
|
||||
public async Task<IActionResult> CreateUser(UserCreateCommand model)
|
||||
{
|
||||
var command = await _mediator.Send(model);
|
||||
|
||||
return base.OperationResult(command);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("TokenRequest")]
|
||||
[ProducesOkApiResponseType<UserTokenRequestQueryResponse>]
|
||||
public async Task<IActionResult> TokenRequest(UserTokenRequestQuery model)
|
||||
{
|
||||
var query = await _mediator.Send(model);
|
||||
|
||||
return base.OperationResult(query);
|
||||
}
|
||||
|
||||
[HttpPost("LoginConfirmation")]
|
||||
[ProducesOkApiResponseType<AccessToken>]
|
||||
public async Task<IActionResult> ValidateUser(GenerateUserTokenQuery model)
|
||||
{
|
||||
var result = await _mediator.Send(model);
|
||||
|
||||
return base.OperationResult(result);
|
||||
}
|
||||
|
||||
[HttpPost("RefreshSignIn")]
|
||||
[RequireTokenWithoutAuthorization]
|
||||
[ProducesOkApiResponseType<AccessToken>]
|
||||
public async Task<IActionResult> RefreshUserToken(RefreshUserTokenCommand model)
|
||||
{
|
||||
var checkCurrentAccessTokenValidity =await HttpContext.AuthenticateAsync(JwtBearerDefaults.AuthenticationScheme);
|
||||
|
||||
if (checkCurrentAccessTokenValidity.Succeeded)
|
||||
return BadRequest("Current access token is valid. No need to refresh");
|
||||
|
||||
var newTokenResult = await _mediator.Send(model);
|
||||
|
||||
return base.OperationResult(newTokenResult);
|
||||
}
|
||||
|
||||
[HttpPost("Logout")]
|
||||
[Authorize]
|
||||
[ProducesOkApiResponseType]
|
||||
public async Task<IActionResult> RequestLogout()
|
||||
{
|
||||
var commandResult = await _mediator.Send(new RequestLogoutCommand(base.UserId));
|
||||
|
||||
return base.OperationResult(commandResult);
|
||||
}
|
||||
|
||||
[HttpPost("PasswordTokenRequest")]
|
||||
[ProducesOkApiResponseType<AccessToken>]
|
||||
public async Task<IActionResult> PasswordTokenRequest(PasswordUserTokenRequestQuery model)
|
||||
=> base.OperationResult(await _mediator.Send(model));
|
||||
}
|
||||
@@ -11,14 +11,15 @@ using Baya.Infrastructure.Identity.ServiceConfiguration;
|
||||
using Baya.Infrastructure.Monitoring.Configurations;
|
||||
using Baya.Infrastructure.Persistence.ServiceConfiguration;
|
||||
using Baya.SharedKernel.Extensions;
|
||||
using Baya.Web.Api.Controllers.V1.UserManagement;
|
||||
using Baya.Web.Plugins.Grpc;
|
||||
using Baya.WebFramework.Filters;
|
||||
using Baya.WebFramework.Middlewares;
|
||||
using Baya.WebFramework.Routing;
|
||||
using Baya.WebFramework.ServiceConfiguration;
|
||||
using Baya.WebFramework.Swagger;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
||||
using Serilog;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -39,6 +40,7 @@ var identitySettings = configuration.GetSection(nameof(IdentitySettings)).Get<Id
|
||||
|
||||
builder.Services.AddControllers(options =>
|
||||
{
|
||||
options.Conventions.Add(new RouteTokenTransformerConvention(new SnakeCaseParameterTransformer()));
|
||||
options.Filters.Add(typeof(OkResultAttribute));
|
||||
options.Filters.Add(typeof(NotFoundResultAttribute));
|
||||
options.Filters.Add(typeof(ContentResultFilterAttribute));
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace Baya.WebFramework.Routing;
|
||||
|
||||
public sealed class SnakeCaseParameterTransformer : IOutboundParameterTransformer
|
||||
{
|
||||
private static readonly Regex _upperAfterLower = new(@"([a-z0-9])([A-Z])", RegexOptions.Compiled);
|
||||
private static readonly Regex _consecutiveUpper = new(@"([A-Z]+)([A-Z][a-z])", RegexOptions.Compiled);
|
||||
|
||||
public string TransformOutbound(object value)
|
||||
{
|
||||
if (value is null) return null;
|
||||
var s = _consecutiveUpper.Replace(value.ToString()!, "$1_$2");
|
||||
return _upperAfterLower.Replace(s, "$1_$2").ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -23,6 +23,7 @@ public class UnitOfWork : IUnitOfWork
|
||||
|
||||
public ValueTask RollBackAsync()
|
||||
{
|
||||
return _db.DisposeAsync();
|
||||
_db.ChangeTracker.Clear();
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user