Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 0 additions & 93 deletions WarehouseEngine.sln

This file was deleted.

15 changes: 15 additions & 0 deletions WarehouseEngine.slnLaunch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"Name": "UI and API",
"Projects": [
{
"Path": "src\\WarehouseEngine.Api\\WarehouseEngine.Api.csproj",
"Action": "Start"
},
{
"Path": "src\\WarehouseEngine.UI\\WarehouseEngine.UI.esproj",
"Action": "Start"
}
]
}
]
25 changes: 25 additions & 0 deletions WarehouseEngine.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Solution>
<Folder Name="/Solution Items/">
<File Path=".editorconfig" />
<File Path=".github/workflows/api-ci.yml" />
<File Path=".github/workflows/build-only.yml" />
<File Path=".github/workflows/ci.yml" />
<File Path=".gitignore" />
<File Path="README.MD" />
</Folder>
<Folder Name="/src/">
<Project Path="src/WarehouseEngine.Api/WarehouseEngine.Api.csproj" />
<Project Path="src/WarehouseEngine.Application/WarehouseEngine.Application.csproj" />
<Project Path="src/WarehouseEngine.Domain/WarehouseEngine.Domain.csproj" />
<Project Path="src/WarehouseEngine.Infrastructure/WarehouseEngine.Infrastructure.csproj" />
<Project Path="src/WarehouseEngine.UI/WarehouseEngine.UI.esproj">
<Build />
<Deploy />
</Project>
</Folder>
<Folder Name="/tests/">
<Project Path="tests/WarehouseEngine.Api.Integration.Tests/WarehouseEngine.Api.Integration.Tests.csproj" />
<Project Path="tests/WarehouseEngine.Application.Tests/WarehouseEngine.Application.Tests.csproj" />
<Project Path="tests/WarehouseEngine.Domain.Tests/WarehouseEngine.Domain.Tests.csproj" />
</Folder>
</Solution>
61 changes: 0 additions & 61 deletions src/WarehouseEngine.Api/Controllers/AuthenticateController.cs

This file was deleted.

42 changes: 0 additions & 42 deletions src/WarehouseEngine.Api/Controllers/ItemController.cs

This file was deleted.

95 changes: 0 additions & 95 deletions src/WarehouseEngine.Api/Controllers/VendorController.cs

This file was deleted.

52 changes: 52 additions & 0 deletions src/WarehouseEngine.Api/Endpoints/AuthenticateEndpoints.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Identity;
using WarehouseEngine.Application.Dtos;
using WarehouseEngine.Application.Interfaces;
using WarehouseEngine.Domain.Models.Auth;

namespace WarehouseEngine.Api.Endpoints;

internal class AuthenticateEndpoints
{
protected AuthenticateEndpoints() { }

public static void Map(WebApplication app)
{
app.MapPost("/api/v{version:apiVersion}/authenticate", [AllowAnonymous] async (
UserManager<IdentityUser> userManager,
IJwtService jwtService,
Login model,
HttpContext httpContext) =>
{
IdentityUser? user = await userManager.FindByNameAsync(model.Username);
if (user is not null && user.UserName is not null && await userManager.CheckPasswordAsync(user, model.Password))
{
IList<string> userRoles = await userManager.GetRolesAsync(user);

List<Claim> authClaims =
[
new Claim(WarehouseClaimTypes.UserId, user.Id),
new Claim(WarehouseClaimTypes.Name, user.UserName),
];

foreach (string userRole in userRoles)
{
authClaims.Add(new Claim(ClaimTypes.Role, userRole));
}

string token = jwtService.GetNewToken(authClaims);
httpContext.Response.Headers.Append("Bearer", token);

return Results.Ok(new AuthenticationResponse(token));
}
return Results.Unauthorized();
})
.Produces<AuthenticationResponse>(200)
.Produces(401)
.Produces(500)
.WithName("Login")
.WithTags("Authenticate");
}
}
Loading
Loading