Commit b295eec4 authored by hasan khaddour's avatar hasan khaddour

refactor

parent a74dc97e
...@@ -20,7 +20,7 @@ namespace PSManagement.Api.Controllers.Authentication ...@@ -20,7 +20,7 @@ namespace PSManagement.Api.Controllers.Authentication
[HttpPost("Login")] [HttpPost("Login")]
public async Task<IActionResult> Login([FromBody] LoginRequest loginRequest) public async Task<IActionResult> Login([FromBody] LoginRequest loginRequest)
{ {
Result<AuthenticationResult> result = await _authenticationService.Login(loginRequest.Email, loginRequest.PassWorrd); Result<AuthenticationResult> result = await _authenticationService.Login(loginRequest.Email, loginRequest.PassWord);
if (result.IsSuccess) { if (result.IsSuccess) {
AuthenticationResponse response = new ( AuthenticationResponse response = new (
...@@ -32,7 +32,7 @@ namespace PSManagement.Api.Controllers.Authentication ...@@ -32,7 +32,7 @@ namespace PSManagement.Api.Controllers.Authentication
return Ok(response); return Ok(response);
} }
return Problem(title: result.Reasons[0].Message,detail:result.Errors[0].Message,statusCode:400); return Problem(title: result.Errors[0].Message,detail:result.Errors[0].Reasons[0].Message,statusCode:400);
} }
[HttpPost("Register")] [HttpPost("Register")]
public async Task<IActionResult> Register([FromBody] RegisterRequest registerRequest) public async Task<IActionResult> Register([FromBody] RegisterRequest registerRequest)
......
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MediatR;
using PSManagement.Contracts.Customers.Requests;
using PSManagement.Application.Customers.UseCases.Commands.CreateCustomer;
using PSManagement.Domain.Customers.ValueObjects;
namespace PSManagement.Api.Controllers.Customers
{
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class CustomersController : ControllerBase
{
private readonly ISender _sender;
public CustomersController(ISender sender)
{
_sender = sender;
}
[HttpPost]
public async Task<IActionResult> CreateCustomer(Guid userId, Guid subscriptionId, CreateCustomerRequest request)
{
Address address = new Address(request.City,request.StreetName,request.ZipCode,request.StreetNumber);
var command = new CreateCustomerCommand(request.CustomerName,address);
var result = await _sender.Send(command);
return result;
}
}
}
...@@ -5,13 +5,22 @@ ...@@ -5,13 +5,22 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MediatR" Version="5.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\PSManagement.Application\PSManagement.Application.csproj" /> <ProjectReference Include="..\PSManagement.Application\PSManagement.Application.csproj" />
<ProjectReference Include="..\PSManagement.Contracts\PSManagement.Contracts.csproj" />
<ProjectReference Include="..\PSManagement.Domain\PSManagement.Domain.csproj" />
<ProjectReference Include="..\PSManagement.Infrastructure.Persistence\PSManagement.Infrastructure.Persistence.csproj" />
<ProjectReference Include="..\PSManagement.Infrastructure\PSManagement.Infrastructure.csproj" /> <ProjectReference Include="..\PSManagement.Infrastructure\PSManagement.Infrastructure.csproj" />
<ProjectReference Include="..\PSManagement.Presentation\PSManagement.Presentation.csproj" /> <ProjectReference Include="..\PSManagement.Presentation\PSManagement.Presentation.csproj" />
<ProjectReference Include="..\PSManagement.SharedKernel\PSManagement.SharedKernel.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
}, },
"PSManagement.Api": { "PSManagement.Api": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": "true", "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "swagger", "launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000", "applicationUrl": "https://localhost:5001;http://localhost:5000",
......
...@@ -13,6 +13,7 @@ using System; ...@@ -13,6 +13,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using PSManagement.Infrastructure.Persistence.DI;
namespace PSManagement.Api namespace PSManagement.Api
{ {
...@@ -28,12 +29,27 @@ namespace PSManagement.Api ...@@ -28,12 +29,27 @@ namespace PSManagement.Api
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// adding dependency injection
services.AddPresentation(); services
services.AddApplication(); .AddPresentation()
services.AddInfrastructure(Configuration); .AddApplication()
.AddInfrastructure(Configuration)
.AddPersistence(Configuration);
services.AddControllers(); services.AddControllers();
services.AddCors(options =>
{
options.AddPolicy("AllowFrontend",
builder => builder
.WithOrigins("http://localhost:4200") // Add your frontend URL here
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials());
});
services.AddSwaggerGen(options => services.AddSwaggerGen(options =>
{ {
options.SwaggerDoc("v1", new OpenApiInfo { Title = "PSManagement.Api", Version = "v1" }); options.SwaggerDoc("v1", new OpenApiInfo { Title = "PSManagement.Api", Version = "v1" });
...@@ -75,7 +91,7 @@ namespace PSManagement.Api ...@@ -75,7 +91,7 @@ namespace PSManagement.Api
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseRouting(); app.UseRouting();
app.UseCors("AllowFrontend");
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
......
...@@ -12,5 +12,9 @@ ...@@ -12,5 +12,9 @@
"ExpireMinutes": 60, "ExpireMinutes": 60,
"Issuer": "HIAST-PS-Management-Server", "Issuer": "HIAST-PS-Management-Server",
"Audience": "All" "Audience": "All"
},
"ConnectionStrings": {
"DefaultConnection": "Data Source=.\\sqlexpress;Initial Catalog=PSManagement ;Integrated Security=True"
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment