Skip to content

Commit

Permalink
New Presentation Class Library,
Browse files Browse the repository at this point in the history
This library creates bridge between api and controllers
  • Loading branch information
novru authored and novru committed May 17, 2024
1 parent 66b0e60 commit 50fcc48
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 218 deletions.
1 change: 1 addition & 0 deletions Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<ProjectReference Include="..\Core\Application\Application.csproj" />
<ProjectReference Include="..\Infrastructure\Infrastructure\Infrastructure.csproj" />
<ProjectReference Include="..\Infrastructure\Persistence\Persistence.csproj" />
<ProjectReference Include="..\Presentation\Presentation.csproj" />
</ItemGroup>

</Project>
65 changes: 0 additions & 65 deletions Api/Controllers/AuthController.cs

This file was deleted.

70 changes: 0 additions & 70 deletions Api/Controllers/HostController.cs

This file was deleted.

76 changes: 0 additions & 76 deletions Api/Controllers/UserController.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Api/GlobalException/GlobalExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception
{
(int statusCode, string errorMessage) = exception switch
{
InvalidRatingException => (StatusCodes.Status406NotAcceptable, "Rating must be between 1 and 5, Please provide correct number"),
InvalidRatingException => (StatusCodes.Status404NotFound, "Rating must be between 1 and 5, Please provide correct number"),
UserNotFoundException => (StatusCodes.Status404NotFound, "Cannot find user, check user credentials"),
CourseNotFoundException => (StatusCodes.Status404NotFound, "Cannot find course, check course credentials"),
_ => (500, "Error occured, Try again.")
Expand Down
5 changes: 4 additions & 1 deletion Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
using Microsoft.EntityFrameworkCore;
using Persistence.Context;
using Persistence.DependencyInjection;
using Presentation;

var builder = WebApplication.CreateBuilder(args);


builder.Services.AddControllers();
builder.Services.AddControllers()
.AddApplicationPart(typeof(AssemblyReference).Assembly);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

Expand Down
17 changes: 12 additions & 5 deletions ApplicationSolution.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastru
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{422CAA6C-B95C-4204-8D8B-1812A2B8911A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api", "Api\Api.csproj", "{E5ED3A67-6F1C-44AC-B52A-732BDCFF4BEB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api", "Api\Api.csproj", "{E5ED3A67-6F1C-44AC-B52A-732BDCFF4BEB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "Core\Application\Application.csproj", "{7D2F7E77-5568-49EB-B424-205A5364F42F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "Core\Application\Application.csproj", "{7D2F7E77-5568-49EB-B424-205A5364F42F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "Domain\Domain.csproj", "{0E920424-1736-4071-BC05-05D65F89C1CF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Domain", "Domain\Domain.csproj", "{0E920424-1736-4071-BC05-05D65F89C1CF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "Infrastructure\Infrastructure\Infrastructure.csproj", "{B9A3E25D-D74A-45E8-BE6E-916F4BC5DC4F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure", "Infrastructure\Infrastructure\Infrastructure.csproj", "{B9A3E25D-D74A-45E8-BE6E-916F4BC5DC4F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Persistence", "Infrastructure\Persistence\Persistence.csproj", "{6EBC21D7-9C0C-4611-9917-6DFB125236DD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistence", "Infrastructure\Persistence\Persistence.csproj", "{6EBC21D7-9C0C-4611-9917-6DFB125236DD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Presentation", "Presentation\Presentation.csproj", "{138BEBAD-0A17-4AA9-AE14-E116524689EB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -45,6 +47,10 @@ Global
{6EBC21D7-9C0C-4611-9917-6DFB125236DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6EBC21D7-9C0C-4611-9917-6DFB125236DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6EBC21D7-9C0C-4611-9917-6DFB125236DD}.Release|Any CPU.Build.0 = Release|Any CPU
{138BEBAD-0A17-4AA9-AE14-E116524689EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{138BEBAD-0A17-4AA9-AE14-E116524689EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{138BEBAD-0A17-4AA9-AE14-E116524689EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{138BEBAD-0A17-4AA9-AE14-E116524689EB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -55,6 +61,7 @@ Global
{0E920424-1736-4071-BC05-05D65F89C1CF} = {B02937F0-DCC8-4534-BB46-C074C243F3BE}
{B9A3E25D-D74A-45E8-BE6E-916F4BC5DC4F} = {65E5C48C-5A3F-41F4-B54D-E1F481059581}
{6EBC21D7-9C0C-4611-9917-6DFB125236DD} = {65E5C48C-5A3F-41F4-B54D-E1F481059581}
{138BEBAD-0A17-4AA9-AE14-E116524689EB} = {65E5C48C-5A3F-41F4-B54D-E1F481059581}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {00478273-7432-4735-9366-F69B4A526CD2}
Expand Down
9 changes: 9 additions & 0 deletions Presentation/Abstraction/ApiController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Mvc;

namespace Presentation.Abstraction;

[ApiController]
[Route("api/[controller]")]
public abstract class ApiController : ControllerBase
{
}
8 changes: 8 additions & 0 deletions Presentation/AssemblyReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Reflection;

namespace Presentation;

public static class AssemblyReference
{
public static readonly Assembly Assembly = typeof(Assembly).Assembly;
}
61 changes: 61 additions & 0 deletions Presentation/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Application.Models.Requests;
using Application.Models.Responses;
using Application.Services;
using Microsoft.AspNetCore.Mvc;
using Presentation.Abstraction;

namespace Presentation.Controllers;

public sealed class AuthController : ApiController
{
private readonly IAuthService _authService;

public AuthController(IAuthService authService)
{
_authService = authService;
}

[HttpPost("Login")]
public async Task<ActionResult> Login(LoginUserRequest request)
{
try
{
return Ok(await _authService.Login(request));
}
catch (Exception)
{
return BadRequest("Error occured with loginning");
}
}

[HttpPost("Register")]
public async Task<ActionResult> Register(RegisterUserRequest request)
{
try
{
if (await _authService.Register(request))
{
return Ok("Successfully Registered!");
}
throw new ArgumentException("Error occured with registering, try again later.");
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}

[HttpPost("RefreshToken")]
public async Task<ActionResult<AuthTokenInfo>> RefreshToken([FromBody] RefreshTokenRequest request)
{
try
{
var token = await _authService.RefreshToken(request);
return Ok(token);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
}
Loading

0 comments on commit 50fcc48

Please sign in to comment.