Commit 23fce07b authored by hasan khaddour's avatar hasan khaddour

Restructure Api Layer.

parent 28a0eccc
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PSManagement.Application.Contracts.Authentication;
using PSManagement.Contracts.Authentication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Controllers.Authentication
{
[Route("api/[controller]")]
[ApiController]
public class AuthenticationController : ControllerBase
{
private readonly IAuthenticationService _authenticationService;
public AuthenticationController(IAuthenticationService authenticationService)
{
_authenticationService = authenticationService;
}
[HttpPost("Login")]
public async Task<IActionResult> Login([FromBody] LoginRequest loginRequest)
{
AuthenticationResult result = await _authenticationService.Login(loginRequest.Email,loginRequest.PassWorrd);
AuthenticationResponse response = new AuthenticationResponse(
result.Id,
result.FirstName,
result.LastName,
result.Email,
result.Token);
return Ok(response);
}
[HttpPost("Register")]
public async Task<IActionResult> Register([FromBody] RegisterRequest registerRequest)
{
AuthenticationResult result = await _authenticationService.Register(
registerRequest.Email,
registerRequest.FirstName,
registerRequest.LastName,
registerRequest.Password);
AuthenticationResponse response = new AuthenticationResponse(
result.Id,
result.FirstName,
result.LastName,
result.Email,
result.Token);
return Ok(response);
}
}
}
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class HomeController : ControllerBase
{
[HttpGet]
public async Task<IActionResult> Get()
{
return Ok( new { message = "success" });
}
}
}
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Api.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace PSManagement.Api.DI
{
public static class DependencyInjection
{
public static IServiceCollection AddApi(this IServiceCollection services)
{
return services;
}
}
}
......@@ -8,4 +8,10 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PSManagement.Application\PSManagement.Application.csproj" />
<ProjectReference Include="..\PSManagement.Infrastructure\PSManagement.Infrastructure.csproj" />
<ProjectReference Include="..\PSManagement.Presentation\PSManagement.Presentation.csproj" />
</ItemGroup>
</Project>
......@@ -5,7 +5,9 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using PSManagement.Presentaion.DI;
using PSManagement.Infrastructure.DI;
using PSManagement.Application.DI;
using Microsoft.OpenApi.Models;
using System;
using System.Collections.Generic;
......@@ -27,6 +29,10 @@ namespace PSManagement.Api
public void ConfigureServices(IServiceCollection services)
{
services.AddPresentation();
services.AddApplication();
services.AddInfrastructure(Configuration);
services.AddControllers();
services.AddSwaggerGen(c =>
{
......
using System;
namespace PSManagement.Api
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string Summary { get; set; }
}
}
......@@ -6,5 +6,11 @@
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"JwtSettings": {
"secret": "super-secret-key",
"ExpireMinutes": 60,
"Issuer": "HIAST-PS-Management",
"Audience": ""
}
}
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