diff --git a/src/Apps/WebApi/Controllers/UserController.cs b/src/Apps/WebApi/Controllers/UserController.cs new file mode 100644 index 0000000..5aecf33 --- /dev/null +++ b/src/Apps/WebApi/Controllers/UserController.cs @@ -0,0 +1,52 @@ +using CleanApplication.Application.Common.Models; +using CleanApplication.Application.Dto; +using CleanApplication.Application.Users.Commands.Delete; +using CleanApplication.Application.Users.Commands.Update; +using CleanApplication.Application.Users.Queries.GetUserById; +using CleanApplication.Application.Users.Queries.GetUsersAdmin; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Threading.Tasks; + +namespace CleanApplication.WebApi.Controllers +{ + [Authorize] + public class UserController : ApiControllerBase + { + [HttpGet] + public async Task>>> Get([FromQuery] GetUsersQuery query) + { + return Ok(await Mediator.Send(query)); + } + [HttpGet("{id}")] + public async Task>> GetById(Guid id) + { + return await Mediator.Send(new GetUserByIdQuery { Id = id }); + } + + //[HttpPost] + //public async Task>> Create(CreateUserCommand command) + //{ + // return await Mediator.Send(command); + //} + + [HttpPut("{id}")] + public async Task>> Update(Guid id, UpdateUserCommand command) + { + if (id != command.Id) + { + return Ok(ServiceResult.Failed(ServiceError.InvalidId)); + } + + return Ok(await Mediator.Send(command)); + } + + [HttpDelete("{id}")] + public async Task>> Delete(Guid id) + { + return await Mediator.Send(new DeleteUserCommand { Id = id }); + + } + } +} diff --git a/src/Apps/WebApi/WebApi.csproj b/src/Apps/WebApi/WebApi.csproj index d70086f..35a1d6a 100644 --- a/src/Apps/WebApi/WebApi.csproj +++ b/src/Apps/WebApi/WebApi.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 CleanApplication.WebApi CleanApplication.WebApi aspnet-WebApi-58672EB4-2691-4613-ACE7-B3CD6A008334 diff --git a/src/Apps/WebApi/appsettings.json b/src/Apps/WebApi/appsettings.json index 1cf9f71..4e5999f 100644 --- a/src/Apps/WebApi/appsettings.json +++ b/src/Apps/WebApi/appsettings.json @@ -1,5 +1,5 @@ { - "UseInMemoryDatabase": false, + "UseInMemoryDatabase": true, "ConnectionStrings": { "DefaultConnection": "Server=.; Database=CleanApplicationTemp; User Id=sa; Password=sa; MultipleActiveResultSets=true" }, diff --git a/src/Common/Application/Application.csproj b/src/Common/Application/Application.csproj index 79f7368..0e345cc 100644 --- a/src/Common/Application/Application.csproj +++ b/src/Common/Application/Application.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 CleanApplication.Application CleanApplication.Application diff --git a/src/Common/Domain/Domain.csproj b/src/Common/Domain/Domain.csproj index cf6c67a..56ebacb 100644 --- a/src/Common/Domain/Domain.csproj +++ b/src/Common/Domain/Domain.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 CleanApplication.Domain CleanApplication.Domain diff --git a/src/Common/Infrastructure/Infrastructure.csproj b/src/Common/Infrastructure/Infrastructure.csproj index fe8ab16..561ab92 100644 --- a/src/Common/Infrastructure/Infrastructure.csproj +++ b/src/Common/Infrastructure/Infrastructure.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 CleanApplication.Infrastructure CleanApplication.Infrastructure diff --git a/tests/CleanApplication.Application.IntegrationTests/CleanApplication.Application.IntegrationTests.csproj b/tests/CleanApplication.Application.IntegrationTests/CleanApplication.Application.IntegrationTests.csproj index ea01a71..c5fcba1 100644 --- a/tests/CleanApplication.Application.IntegrationTests/CleanApplication.Application.IntegrationTests.csproj +++ b/tests/CleanApplication.Application.IntegrationTests/CleanApplication.Application.IntegrationTests.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 false