From fad8965a3f1a5f7060d9beac7bedf2ce1d0ed1fc Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Mon, 8 Mar 2021 21:46:55 -0300 Subject: [PATCH 01/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Inicio=20estrutura=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 25 ++++++++++ .gitignore | 9 ++++ Wappa.sln | 45 +++++++++++++++++ .../Wappa.Core/Wappa.Core.csproj | 7 +++ .../Controllers/MotoristaController.cs | 16 +++++++ src/services/Wappa.Motorista.API/Dockerfile | 21 ++++++++ src/services/Wappa.Motorista.API/Program.cs | 26 ++++++++++ .../Properties/launchSettings.json | 36 ++++++++++++++ src/services/Wappa.Motorista.API/Startup.cs | 48 +++++++++++++++++++ .../Wappa.Motorista.API.csproj | 14 ++++++ .../Wappa.Motorista.API.csproj.user | 6 +++ .../appsettings.Development.json | 9 ++++ .../Wappa.Motorista.API/appsettings.json | 10 ++++ 13 files changed, 272 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Wappa.sln create mode 100644 src/building blocks/Wappa.Core/Wappa.Core.csproj create mode 100644 src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs create mode 100644 src/services/Wappa.Motorista.API/Dockerfile create mode 100644 src/services/Wappa.Motorista.API/Program.cs create mode 100644 src/services/Wappa.Motorista.API/Properties/launchSettings.json create mode 100644 src/services/Wappa.Motorista.API/Startup.cs create mode 100644 src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj create mode 100644 src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj.user create mode 100644 src/services/Wappa.Motorista.API/appsettings.Development.json create mode 100644 src/services/Wappa.Motorista.API/appsettings.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..3729ff0c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b2ca2ff8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +################################################################################ +# Este arquivo .gitignore foi criado automaticamente pelo Microsoft(R) Visual Studio. +################################################################################ + +/.vs +/src/building blocks/Wappa.Core/bin/Debug/netcoreapp3.1 +/src/building blocks/Wappa.Core/obj +/src/services/Wappa.Motorista.API/bin/Debug/netcoreapp3.1 +/src/services/Wappa.Motorista.API/obj diff --git a/Wappa.sln b/Wappa.sln new file mode 100644 index 00000000..e0795010 --- /dev/null +++ b/Wappa.sln @@ -0,0 +1,45 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30804.86 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Building Blocks", "Building Blocks", "{DC4A0A94-B314-410C-803D-95E4A3F5C0FA}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{D7CC5A53-341D-41FD-9A24-0BD3C5569258}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{C5A6B0DC-3A32-46A4-858D-73410D1A81E9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wappa.Core", "src\building blocks\Wappa.Core\Wappa.Core.csproj", "{F1EF41B4-CA77-4B64-8C64-8AA0E16626A1}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Motorista", "Motorista", "{545ADEF2-79F6-4825-97A7-AD34D64A94EC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wappa.Motorista.API", "src\services\Wappa.Motorista.API\Wappa.Motorista.API.csproj", "{9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F1EF41B4-CA77-4B64-8C64-8AA0E16626A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F1EF41B4-CA77-4B64-8C64-8AA0E16626A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F1EF41B4-CA77-4B64-8C64-8AA0E16626A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F1EF41B4-CA77-4B64-8C64-8AA0E16626A1}.Release|Any CPU.Build.0 = Release|Any CPU + {9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {C5A6B0DC-3A32-46A4-858D-73410D1A81E9} = {DC4A0A94-B314-410C-803D-95E4A3F5C0FA} + {F1EF41B4-CA77-4B64-8C64-8AA0E16626A1} = {C5A6B0DC-3A32-46A4-858D-73410D1A81E9} + {545ADEF2-79F6-4825-97A7-AD34D64A94EC} = {D7CC5A53-341D-41FD-9A24-0BD3C5569258} + {9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60} = {545ADEF2-79F6-4825-97A7-AD34D64A94EC} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1ABF1BAA-6091-41E7-93DE-3428D39E26BC} + EndGlobalSection +EndGlobal diff --git a/src/building blocks/Wappa.Core/Wappa.Core.csproj b/src/building blocks/Wappa.Core/Wappa.Core.csproj new file mode 100644 index 00000000..cb631906 --- /dev/null +++ b/src/building blocks/Wappa.Core/Wappa.Core.csproj @@ -0,0 +1,7 @@ + + + + netcoreapp3.1 + + + diff --git a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs new file mode 100644 index 00000000..22fa5ed1 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Wappa.Motorista.API.Controllers +{ + [ApiController] + [Route("[controller]")] + public class MotoristaController : ControllerBase + { + + } +} diff --git a/src/services/Wappa.Motorista.API/Dockerfile b/src/services/Wappa.Motorista.API/Dockerfile new file mode 100644 index 00000000..3a95deee --- /dev/null +++ b/src/services/Wappa.Motorista.API/Dockerfile @@ -0,0 +1,21 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base +WORKDIR /app +EXPOSE 80 + +FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build +WORKDIR /src +COPY ["src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj", "src/services/Wappa.Motorista.API/"] +RUN dotnet restore "src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj" +COPY . . +WORKDIR "/src/src/services/Wappa.Motorista.API" +RUN dotnet build "Wappa.Motorista.API.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "Wappa.Motorista.API.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Wappa.Motorista.API.dll"] \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Program.cs b/src/services/Wappa.Motorista.API/Program.cs new file mode 100644 index 00000000..5bcd36fe --- /dev/null +++ b/src/services/Wappa.Motorista.API/Program.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Wappa.Motorista.API +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/src/services/Wappa.Motorista.API/Properties/launchSettings.json b/src/services/Wappa.Motorista.API/Properties/launchSettings.json new file mode 100644 index 00000000..f95bb52b --- /dev/null +++ b/src/services/Wappa.Motorista.API/Properties/launchSettings.json @@ -0,0 +1,36 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:52004", + "sslPort": 0 + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Wappa.Motorista.API": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:5000" + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast", + "publishAllPorts": true + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Startup.cs b/src/services/Wappa.Motorista.API/Startup.cs new file mode 100644 index 00000000..16ab1e3e --- /dev/null +++ b/src/services/Wappa.Motorista.API/Startup.cs @@ -0,0 +1,48 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Wappa.Motorista.API +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj b/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj new file mode 100644 index 00000000..547a61ef --- /dev/null +++ b/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj @@ -0,0 +1,14 @@ + + + + netcoreapp3.1 + Linux + ..\..\.. + + + + + + + + diff --git a/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj.user b/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj.user new file mode 100644 index 00000000..e681dafe --- /dev/null +++ b/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj.user @@ -0,0 +1,6 @@ + + + + Docker + + \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/appsettings.Development.json b/src/services/Wappa.Motorista.API/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/src/services/Wappa.Motorista.API/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/src/services/Wappa.Motorista.API/appsettings.json b/src/services/Wappa.Motorista.API/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/src/services/Wappa.Motorista.API/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} From b43cb6a3b59733c061e11d4f7685c6424cbcf03c Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Mon, 8 Mar 2021 22:09:40 -0300 Subject: [PATCH 02/83] feature/TAR-1-Criar-API-Motorista #comment - FOi criado as entidades --- .../Wappa.Core/DomainObjects/Entity.cs | 54 +++++++++++++++++++ .../DomainObjects/IAggregateRoot.cs | 4 ++ .../Wappa.Core/DomainObjects/Localizacao.cs | 7 +++ .../Wappa.Motorista.API/Models/Carro.cs | 24 +++++++++ .../Wappa.Motorista.API/Models/Endereco.cs | 30 +++++++++++ .../Wappa.Motorista.API/Models/Motorista.cs | 22 ++++++++ .../Wappa.Motorista.API.csproj | 18 ++++++- 7 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 src/building blocks/Wappa.Core/DomainObjects/Entity.cs create mode 100644 src/building blocks/Wappa.Core/DomainObjects/IAggregateRoot.cs create mode 100644 src/building blocks/Wappa.Core/DomainObjects/Localizacao.cs create mode 100644 src/services/Wappa.Motorista.API/Models/Carro.cs create mode 100644 src/services/Wappa.Motorista.API/Models/Endereco.cs create mode 100644 src/services/Wappa.Motorista.API/Models/Motorista.cs diff --git a/src/building blocks/Wappa.Core/DomainObjects/Entity.cs b/src/building blocks/Wappa.Core/DomainObjects/Entity.cs new file mode 100644 index 00000000..51a7be8b --- /dev/null +++ b/src/building blocks/Wappa.Core/DomainObjects/Entity.cs @@ -0,0 +1,54 @@ +using System; + +namespace NSE.Core.DomainObjects +{ + public abstract class Entity + { + public Guid Id { get; set; } + + protected Entity() + { + Id = Guid.NewGuid(); + } + + #region Comparações + + public override bool Equals(object obj) + { + var compareTo = obj as Entity; + + if (ReferenceEquals(this, compareTo)) return true; + if (ReferenceEquals(null, compareTo)) return false; + + return Id.Equals(compareTo.Id); + } + + public static bool operator ==(Entity a, Entity b) + { + if (ReferenceEquals(a, null) && ReferenceEquals(b, null)) + return true; + + if (ReferenceEquals(a, null) || ReferenceEquals(b, null)) + return false; + + return a.Equals(b); + } + + public static bool operator !=(Entity a, Entity b) + { + return !(a == b); + } + + public override int GetHashCode() + { + return (GetType().GetHashCode() * 907) + Id.GetHashCode(); + } + + public override string ToString() + { + return $"{GetType().Name} [Id={Id}]"; + } + + #endregion + } +} \ No newline at end of file diff --git a/src/building blocks/Wappa.Core/DomainObjects/IAggregateRoot.cs b/src/building blocks/Wappa.Core/DomainObjects/IAggregateRoot.cs new file mode 100644 index 00000000..5aaecff5 --- /dev/null +++ b/src/building blocks/Wappa.Core/DomainObjects/IAggregateRoot.cs @@ -0,0 +1,4 @@ +namespace NSE.Core.DomainObjects +{ + public interface IAggregateRoot { } +} \ No newline at end of file diff --git a/src/building blocks/Wappa.Core/DomainObjects/Localizacao.cs b/src/building blocks/Wappa.Core/DomainObjects/Localizacao.cs new file mode 100644 index 00000000..499397c3 --- /dev/null +++ b/src/building blocks/Wappa.Core/DomainObjects/Localizacao.cs @@ -0,0 +1,7 @@ +namespace NSE.Core.DomainObjects +{ + public class Localizacao + { + + } +} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Models/Carro.cs b/src/services/Wappa.Motorista.API/Models/Carro.cs new file mode 100644 index 00000000..364d8bb6 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Models/Carro.cs @@ -0,0 +1,24 @@ +using NSE.Core.DomainObjects; +using System; + +namespace Wappa.Motorista.API.Models +{ + public class Carro: Entity + { + public string Marca { get; private set; } + public string Modelo { get; private set; } + public string Placa { get; private set; } + + public Guid MotoristaId { get; private set; } + + // EF Relation + public Motorista Motorista { get; protected set; } + + public Carro(string marca, string modelo, string placa) + { + Marca = marca; + Modelo = modelo; + Placa = placa; + } + } +} diff --git a/src/services/Wappa.Motorista.API/Models/Endereco.cs b/src/services/Wappa.Motorista.API/Models/Endereco.cs new file mode 100644 index 00000000..d7a8b43e --- /dev/null +++ b/src/services/Wappa.Motorista.API/Models/Endereco.cs @@ -0,0 +1,30 @@ +using NSE.Core.DomainObjects; +using System; + +namespace Wappa.Motorista.API.Models +{ + public class Endereco: Entity + { + public string Logradouro { get; private set; } + public string Numero { get; private set; } + public string Complemento { get; private set; } + public string Bairro { get; private set; } + public string Cep { get; private set; } + public string Cidade { get; private set; } + public string Estado { get; private set; } + public Guid MotoristaId { get; private set; } + + public Motorista Cliente { get; protected set; } + + public Endereco(string logradouro, string numero, string complemento, string bairro, string cep, string cidade, string estado) + { + Logradouro = logradouro; + Numero = numero; + Complemento = complemento; + Bairro = bairro; + Cep = cep; + Cidade = cidade; + Estado = estado; + } + } +} diff --git a/src/services/Wappa.Motorista.API/Models/Motorista.cs b/src/services/Wappa.Motorista.API/Models/Motorista.cs new file mode 100644 index 00000000..670d5d37 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Models/Motorista.cs @@ -0,0 +1,22 @@ +using NSE.Core.DomainObjects; +using System; + +namespace Wappa.Motorista.API.Models +{ + public class Motorista: Entity, IAggregateRoot + { + public string Nome { get; private set; } + public string SobreNome { get; private set; } + public Carro Carro { get; private set; } + public Endereco Endereco { get; private set; } + + protected Motorista() { } + + public Motorista(Guid id, string nome, string sobreNome) + { + Id = id; + Nome = nome; + SobreNome = sobreNome; + } + } +} diff --git a/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj b/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj index 547a61ef..1af9f45b 100644 --- a/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj +++ b/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj @@ -7,7 +7,23 @@ - + + + + + + + + + + + + + + + + + From a680db17bec224eb83c0503be4c687bed986ecf3 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Mon, 8 Mar 2021 22:39:34 -0300 Subject: [PATCH 03/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Corre=C3=A7=C3=A3o=20namespace,=20cria=C3=A7=C3=A3o?= =?UTF-8?q?=20dos=20mappings,=20cria=C3=A7=C3=A3o=20do=20repositorio,=20cr?= =?UTF-8?q?ia=C3=A7=C3=A3o=20do=20contexto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Wappa.sln | 4 +- .../Wappa.Core/Data/IRepository.cs | 10 +++++ .../Wappa.Core/Data/IUnitOfWork.cs | 9 ++++ .../Wappa.Core/DomainObjects/Entity.cs | 2 +- .../DomainObjects/IAggregateRoot.cs | 2 +- .../Wappa.Core/DomainObjects/Localizacao.cs | 2 +- .../Controllers/MotoristaController.cs | 2 +- .../Data/Mappings/CarroMapping.cs | 29 ++++++++++++ .../Data/Mappings/EnderecoMapping.cs | 43 ++++++++++++++++++ .../Data/Mappings/MotoristaMapping.cs | 32 ++++++++++++++ .../Data/MotoristsContext.cs | 44 +++++++++++++++++++ .../Data/Repository/MotoristaRepository.cs | 36 +++++++++++++++ src/services/Wappa.Motorista.API/Dockerfile | 12 ++--- .../Wappa.Motorista.API/Models/Carro.cs | 4 +- .../Wappa.Motorista.API/Models/Endereco.cs | 6 +-- .../Models/IMotoristaRepository.cs | 13 ++++++ .../Wappa.Motorista.API/Models/Motorista.cs | 4 +- src/services/Wappa.Motorista.API/Program.cs | 2 +- .../Properties/launchSettings.json | 2 +- src/services/Wappa.Motorista.API/Startup.cs | 2 +- ...API.csproj => Wappa.Motoristas.API.csproj} | 4 -- ....user => Wappa.Motoristas.API.csproj.user} | 0 22 files changed, 238 insertions(+), 26 deletions(-) create mode 100644 src/building blocks/Wappa.Core/Data/IRepository.cs create mode 100644 src/building blocks/Wappa.Core/Data/IUnitOfWork.cs create mode 100644 src/services/Wappa.Motorista.API/Data/Mappings/CarroMapping.cs create mode 100644 src/services/Wappa.Motorista.API/Data/Mappings/EnderecoMapping.cs create mode 100644 src/services/Wappa.Motorista.API/Data/Mappings/MotoristaMapping.cs create mode 100644 src/services/Wappa.Motorista.API/Data/MotoristsContext.cs create mode 100644 src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs create mode 100644 src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs rename src/services/Wappa.Motorista.API/{Wappa.Motorista.API.csproj => Wappa.Motoristas.API.csproj} (95%) rename src/services/Wappa.Motorista.API/{Wappa.Motorista.API.csproj.user => Wappa.Motoristas.API.csproj.user} (100%) diff --git a/Wappa.sln b/Wappa.sln index e0795010..a4ddb158 100644 --- a/Wappa.sln +++ b/Wappa.sln @@ -9,11 +9,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{D7 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{C5A6B0DC-3A32-46A4-858D-73410D1A81E9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wappa.Core", "src\building blocks\Wappa.Core\Wappa.Core.csproj", "{F1EF41B4-CA77-4B64-8C64-8AA0E16626A1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wappa.Core", "src\building blocks\Wappa.Core\Wappa.Core.csproj", "{F1EF41B4-CA77-4B64-8C64-8AA0E16626A1}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Motorista", "Motorista", "{545ADEF2-79F6-4825-97A7-AD34D64A94EC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wappa.Motorista.API", "src\services\Wappa.Motorista.API\Wappa.Motorista.API.csproj", "{9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wappa.Motoristas.API", "src\services\Wappa.Motorista.API\Wappa.Motoristas.API.csproj", "{9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/building blocks/Wappa.Core/Data/IRepository.cs b/src/building blocks/Wappa.Core/Data/IRepository.cs new file mode 100644 index 00000000..7ce95f12 --- /dev/null +++ b/src/building blocks/Wappa.Core/Data/IRepository.cs @@ -0,0 +1,10 @@ +using System; +using Wappa.Core.DomainObjects; + +namespace Wappa.Core.Data +{ + public interface IRepository : IDisposable where T : IAggregateRoot + { + IUnitOfWork UnitOfWork { get; } + } +} \ No newline at end of file diff --git a/src/building blocks/Wappa.Core/Data/IUnitOfWork.cs b/src/building blocks/Wappa.Core/Data/IUnitOfWork.cs new file mode 100644 index 00000000..f182272e --- /dev/null +++ b/src/building blocks/Wappa.Core/Data/IUnitOfWork.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Wappa.Core.Data +{ + public interface IUnitOfWork + { + Task Commit(); + } +} \ No newline at end of file diff --git a/src/building blocks/Wappa.Core/DomainObjects/Entity.cs b/src/building blocks/Wappa.Core/DomainObjects/Entity.cs index 51a7be8b..bcb31d24 100644 --- a/src/building blocks/Wappa.Core/DomainObjects/Entity.cs +++ b/src/building blocks/Wappa.Core/DomainObjects/Entity.cs @@ -1,6 +1,6 @@ using System; -namespace NSE.Core.DomainObjects +namespace Wappa.Core.DomainObjects { public abstract class Entity { diff --git a/src/building blocks/Wappa.Core/DomainObjects/IAggregateRoot.cs b/src/building blocks/Wappa.Core/DomainObjects/IAggregateRoot.cs index 5aaecff5..8c3dc9bb 100644 --- a/src/building blocks/Wappa.Core/DomainObjects/IAggregateRoot.cs +++ b/src/building blocks/Wappa.Core/DomainObjects/IAggregateRoot.cs @@ -1,4 +1,4 @@ -namespace NSE.Core.DomainObjects +namespace Wappa.Core.DomainObjects { public interface IAggregateRoot { } } \ No newline at end of file diff --git a/src/building blocks/Wappa.Core/DomainObjects/Localizacao.cs b/src/building blocks/Wappa.Core/DomainObjects/Localizacao.cs index 499397c3..21749a95 100644 --- a/src/building blocks/Wappa.Core/DomainObjects/Localizacao.cs +++ b/src/building blocks/Wappa.Core/DomainObjects/Localizacao.cs @@ -1,4 +1,4 @@ -namespace NSE.Core.DomainObjects +namespace Wappa.Core.DomainObjects { public class Localizacao { diff --git a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs index 22fa5ed1..06dbd3d9 100644 --- a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs +++ b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Threading.Tasks; -namespace Wappa.Motorista.API.Controllers +namespace Wappa.Motoristas.API.Controllers { [ApiController] [Route("[controller]")] diff --git a/src/services/Wappa.Motorista.API/Data/Mappings/CarroMapping.cs b/src/services/Wappa.Motorista.API/Data/Mappings/CarroMapping.cs new file mode 100644 index 00000000..6054695c --- /dev/null +++ b/src/services/Wappa.Motorista.API/Data/Mappings/CarroMapping.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Wappa.Motoristas.API.Models; + +namespace Wappa.Motoristas.API.Data.Mappings +{ + public class CarroMapping : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(c => c.Id); + + builder.Property(c => c.Marca) + .IsRequired() + .HasColumnType("varchar(200)"); + + builder.Property(c => c.Modelo) + .IsRequired() + .HasColumnType("varchar(100)"); + + builder.Property(c => c.Placa) + .IsRequired() + .HasColumnType("varchar(20)"); + + + builder.ToTable("Carros"); + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Data/Mappings/EnderecoMapping.cs b/src/services/Wappa.Motorista.API/Data/Mappings/EnderecoMapping.cs new file mode 100644 index 00000000..ff63ddc8 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Data/Mappings/EnderecoMapping.cs @@ -0,0 +1,43 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Wappa.Motoristas.API.Models; + +namespace Wappa.Motoristas.API.Data.Mappings +{ + public class EnderecoMapping : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(c => c.Id); + + builder.Property(c => c.Logradouro) + .IsRequired() + .HasColumnType("varchar(200)"); + + builder.Property(c => c.Numero) + .IsRequired() + .HasColumnType("varchar(50)"); + + builder.Property(c => c.Cep) + .IsRequired() + .HasColumnType("varchar(20)"); + + builder.Property(c => c.Complemento) + .HasColumnType("varchar(250)"); + + builder.Property(c => c.Bairro) + .IsRequired() + .HasColumnType("varchar(100)"); + + builder.Property(c => c.Cidade) + .IsRequired() + .HasColumnType("varchar(100)"); + + builder.Property(c => c.Estado) + .IsRequired() + .HasColumnType("varchar(50)"); + + builder.ToTable("Enderecos"); + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Data/Mappings/MotoristaMapping.cs b/src/services/Wappa.Motorista.API/Data/Mappings/MotoristaMapping.cs new file mode 100644 index 00000000..d85e31ad --- /dev/null +++ b/src/services/Wappa.Motorista.API/Data/Mappings/MotoristaMapping.cs @@ -0,0 +1,32 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Wappa.Motoristas.API.Models; + +namespace Wappa.Motoristas.API.Data.Mappings +{ + public class MotoristaMapping : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(c => c.Id); + + builder.Property(c => c.Nome) + .IsRequired() + .HasColumnType("varchar(200)"); + + builder.Property(c => c.SobreNome) + .IsRequired() + .HasColumnType("varchar(200)"); + + // 1 : 1 => Motorista : Endereco + builder.HasOne(c => c.Endereco) + .WithOne(c => c.Motorista); + + // 1 : 1 => Motorista : Carro + builder.HasOne(c => c.Carro) + .WithOne(c => c.Motorista); + + builder.ToTable("Motoristas"); + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs b/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs new file mode 100644 index 00000000..bdc49268 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs @@ -0,0 +1,44 @@ +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Wappa.Motoristas.API.Models; +using Wappa.Core.Data; +using Wappa.Core.DomainObjects; + +namespace Wappa.Motoristas.API.Data +{ + public sealed class MotoristaContext : DbContext, IUnitOfWork + { + + public MotoristaContext(DbContextOptions options) + : base(options) + { + ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; + ChangeTracker.AutoDetectChangesEnabled = false; + } + + public DbSet Motorista { get; set; } + public DbSet Enderecos { get; set; } + public DbSet Carros { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + + foreach (var property in modelBuilder.Model.GetEntityTypes().SelectMany( + e => e.GetProperties().Where(p => p.ClrType == typeof(string)))) + property.SetColumnType("varchar(100)"); + + foreach (var relationship in modelBuilder.Model.GetEntityTypes() + .SelectMany(e => e.GetForeignKeys())) relationship.DeleteBehavior = DeleteBehavior.ClientSetNull; + + modelBuilder.ApplyConfigurationsFromAssembly(typeof(MotoristaContext).Assembly); + } + + public async Task Commit() + { + var sucesso = await base.SaveChangesAsync() > 0; + + return sucesso; + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs b/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs new file mode 100644 index 00000000..358eda3f --- /dev/null +++ b/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Wappa.Core.Data; +using Wappa.Motoristas.API.Models; +using Wappa.Motoristas.API.Data; + +namespace Wappa.Motoristas.API.Data.Repository +{ + public class MotoristaRepository : IMotoristaRepository + { + private readonly MotoristaContext _context; + + public MotoristaRepository(MotoristaContext context) + { + _context = context; + } + + public IUnitOfWork UnitOfWork => _context; + + public async Task> ObterTodos() + { + return await _context.Motorista.AsNoTracking().ToListAsync(); + } + + public void Adicionar(Motorista cliente) + { + _context.Motorista.Add(cliente); + } + + public void Dispose() + { + _context.Dispose(); + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Dockerfile b/src/services/Wappa.Motorista.API/Dockerfile index 3a95deee..0a4e15d2 100644 --- a/src/services/Wappa.Motorista.API/Dockerfile +++ b/src/services/Wappa.Motorista.API/Dockerfile @@ -6,16 +6,16 @@ EXPOSE 80 FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build WORKDIR /src -COPY ["src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj", "src/services/Wappa.Motorista.API/"] -RUN dotnet restore "src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj" +COPY ["src/services/Wappa.Motoristas.API/Wappa.Motoristas.API.csproj", "src/services/Wappa.Motoristas.API/"] +RUN dotnet restore "src/services/Wappa.Motoristas.API/Wappa.Motoristas.API.csproj" COPY . . -WORKDIR "/src/src/services/Wappa.Motorista.API" -RUN dotnet build "Wappa.Motorista.API.csproj" -c Release -o /app/build +WORKDIR "/src/src/services/Wappa.Motoristas.API" +RUN dotnet build "Wappa.Motoristas.API.csproj" -c Release -o /app/build FROM build AS publish -RUN dotnet publish "Wappa.Motorista.API.csproj" -c Release -o /app/publish +RUN dotnet publish "Wappa.Motoristas.API.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Wappa.Motorista.API.dll"] \ No newline at end of file +ENTRYPOINT ["dotnet", "Wappa.Motoristas.API.dll"] \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Models/Carro.cs b/src/services/Wappa.Motorista.API/Models/Carro.cs index 364d8bb6..2d859b26 100644 --- a/src/services/Wappa.Motorista.API/Models/Carro.cs +++ b/src/services/Wappa.Motorista.API/Models/Carro.cs @@ -1,7 +1,7 @@ -using NSE.Core.DomainObjects; +using Wappa.Core.DomainObjects; using System; -namespace Wappa.Motorista.API.Models +namespace Wappa.Motoristas.API.Models { public class Carro: Entity { diff --git a/src/services/Wappa.Motorista.API/Models/Endereco.cs b/src/services/Wappa.Motorista.API/Models/Endereco.cs index d7a8b43e..6eee5876 100644 --- a/src/services/Wappa.Motorista.API/Models/Endereco.cs +++ b/src/services/Wappa.Motorista.API/Models/Endereco.cs @@ -1,7 +1,7 @@ -using NSE.Core.DomainObjects; +using Wappa.Core.DomainObjects; using System; -namespace Wappa.Motorista.API.Models +namespace Wappa.Motoristas.API.Models { public class Endereco: Entity { @@ -14,7 +14,7 @@ public class Endereco: Entity public string Estado { get; private set; } public Guid MotoristaId { get; private set; } - public Motorista Cliente { get; protected set; } + public Motorista Motorista { get; protected set; } public Endereco(string logradouro, string numero, string complemento, string bairro, string cep, string cidade, string estado) { diff --git a/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs b/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs new file mode 100644 index 00000000..ad8bff81 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Wappa.Core.Data; + +namespace Wappa.Motoristas.API.Models +{ + public interface IMotoristaRepository : IRepository + { + void Adicionar(Motorista cliente); + + Task> ObterTodos(); + } +} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Models/Motorista.cs b/src/services/Wappa.Motorista.API/Models/Motorista.cs index 670d5d37..6a9607bd 100644 --- a/src/services/Wappa.Motorista.API/Models/Motorista.cs +++ b/src/services/Wappa.Motorista.API/Models/Motorista.cs @@ -1,7 +1,7 @@ -using NSE.Core.DomainObjects; +using Wappa.Core.DomainObjects; using System; -namespace Wappa.Motorista.API.Models +namespace Wappa.Motoristas.API.Models { public class Motorista: Entity, IAggregateRoot { diff --git a/src/services/Wappa.Motorista.API/Program.cs b/src/services/Wappa.Motorista.API/Program.cs index 5bcd36fe..e31df427 100644 --- a/src/services/Wappa.Motorista.API/Program.cs +++ b/src/services/Wappa.Motorista.API/Program.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Threading.Tasks; -namespace Wappa.Motorista.API +namespace Wappa.Motoristas.API { public class Program { diff --git a/src/services/Wappa.Motorista.API/Properties/launchSettings.json b/src/services/Wappa.Motorista.API/Properties/launchSettings.json index f95bb52b..9fb4c232 100644 --- a/src/services/Wappa.Motorista.API/Properties/launchSettings.json +++ b/src/services/Wappa.Motorista.API/Properties/launchSettings.json @@ -17,7 +17,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, - "Wappa.Motorista.API": { + "Wappa.Motoristas.API": { "commandName": "Project", "launchBrowser": true, "launchUrl": "weatherforecast", diff --git a/src/services/Wappa.Motorista.API/Startup.cs b/src/services/Wappa.Motorista.API/Startup.cs index 16ab1e3e..e39e827d 100644 --- a/src/services/Wappa.Motorista.API/Startup.cs +++ b/src/services/Wappa.Motorista.API/Startup.cs @@ -10,7 +10,7 @@ using System.Linq; using System.Threading.Tasks; -namespace Wappa.Motorista.API +namespace Wappa.Motoristas.API { public class Startup { diff --git a/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj similarity index 95% rename from src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj rename to src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj index 1af9f45b..48a3dab3 100644 --- a/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj +++ b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj @@ -18,10 +18,6 @@ - - - - diff --git a/src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj.user b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj.user similarity index 100% rename from src/services/Wappa.Motorista.API/Wappa.Motorista.API.csproj.user rename to src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj.user From a742fe711a774b8d40d844758a51b051e9c5c6bd Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Mon, 8 Mar 2021 23:15:04 -0300 Subject: [PATCH 04/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20implementado=20configura=C3=A7=C3=B5es=20da=20a?= =?UTF-8?q?pi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Configuration/ApiConfig.cs | 48 +++++++++++++ .../DependencyInjectionConfig.cs | 16 +++++ .../Configuration/SwaggerConfig.cs | 58 ++++++++++++++++ .../Data/MotoristsContext.cs | 2 +- .../Properties/launchSettings.json | 36 +++++++--- src/services/Wappa.Motorista.API/Startup.cs | 67 ++++++++++--------- .../Wappa.Motoristas.API.csproj | 3 +- .../Wappa.Motoristas.API.csproj.user | 5 +- .../appsettings.Development.json | 9 +++ 9 files changed, 202 insertions(+), 42 deletions(-) create mode 100644 src/services/Wappa.Motorista.API/Configuration/ApiConfig.cs create mode 100644 src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs create mode 100644 src/services/Wappa.Motorista.API/Configuration/SwaggerConfig.cs diff --git a/src/services/Wappa.Motorista.API/Configuration/ApiConfig.cs b/src/services/Wappa.Motorista.API/Configuration/ApiConfig.cs new file mode 100644 index 00000000..22fee81e --- /dev/null +++ b/src/services/Wappa.Motorista.API/Configuration/ApiConfig.cs @@ -0,0 +1,48 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Wappa.Motoristas.API.Data; + +namespace Wappa.Motoristas.API.Configuration +{ + public static class ApiConfig + { + public static void AddApiConfiguration(this IServiceCollection services, IConfiguration configuration) + { + services.AddDbContext(options => + options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"))); + + services.AddControllers(); + + services.AddCors(options => + { + options.AddPolicy("Total", + builder => + builder + .AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader()); + }); + } + + public static void UseApiConfiguration(this IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseCors("Total"); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs new file mode 100644 index 00000000..07dbc565 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs @@ -0,0 +1,16 @@ +using Microsoft.Extensions.DependencyInjection; +using Wappa.Motoristas.API.Data; +using Wappa.Motoristas.API.Data.Repository; +using Wappa.Motoristas.API.Models; + +namespace NSE.Clientes.API.Configuration +{ + public static class DependencyInjectionConfig + { + public static void RegisterServices(this IServiceCollection services) + { + services.AddScoped(); + services.AddScoped(); + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Configuration/SwaggerConfig.cs b/src/services/Wappa.Motorista.API/Configuration/SwaggerConfig.cs new file mode 100644 index 00000000..7a4d9c3c --- /dev/null +++ b/src/services/Wappa.Motorista.API/Configuration/SwaggerConfig.cs @@ -0,0 +1,58 @@ +using System; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.OpenApi.Models; + +namespace NSE.Clientes.API.Configuration +{ + public static class SwaggerConfig + { + public static void AddSwaggerConfiguration(this IServiceCollection services) + { + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo() + { + Title = "Wappa Challenge Dev Motorista API", + Description = "Esta API faz controle o cadastro de motoristas.", + Contact = new OpenApiContact() { Name = "Phillipe R Souza", Email = "phillrog@hotmail.com" }, + }); + + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + Description = "Insira o token JWT desta maneira: Bearer {seu token}", + Name = "Authorization", + Scheme = "Bearer", + BearerFormat = "JWT", + In = ParameterLocation.Header, + Type = SecuritySchemeType.ApiKey + }); + + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + new string[] {} + } + }); + + }); + } + + public static void UseSwaggerConfiguration(this IApplicationBuilder app) + { + app.UseSwagger(); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); + }); + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs b/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs index bdc49268..404ec521 100644 --- a/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs +++ b/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs @@ -29,7 +29,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) property.SetColumnType("varchar(100)"); foreach (var relationship in modelBuilder.Model.GetEntityTypes() - .SelectMany(e => e.GetForeignKeys())) relationship.DeleteBehavior = DeleteBehavior.ClientSetNull; + .SelectMany(e => e.GetForeignKeys())) relationship.DeleteBehavior = DeleteBehavior.Cascade; modelBuilder.ApplyConfigurationsFromAssembly(typeof(MotoristaContext).Assembly); } diff --git a/src/services/Wappa.Motorista.API/Properties/launchSettings.json b/src/services/Wappa.Motorista.API/Properties/launchSettings.json index 9fb4c232..391048f5 100644 --- a/src/services/Wappa.Motorista.API/Properties/launchSettings.json +++ b/src/services/Wappa.Motorista.API/Properties/launchSettings.json @@ -4,33 +4,53 @@ "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:52004", - "sslPort": 0 + "sslPort": 44317 } }, "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { - "IIS Express": { + "IIS Development": { "commandName": "IISExpress", "launchBrowser": true, - "launchUrl": "weatherforecast", + "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, - "Wappa.Motoristas.API": { + "IIS Staging": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Staging" + } + }, + "IIS Production": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Production" + } + }, + "SelfHosting - Development": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "weatherforecast", + "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "http://localhost:5000" + "applicationUrl": "https://localhost:5001;http://localhost:4001" }, "Docker": { "commandName": "Docker", "launchBrowser": true, - "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast", - "publishAllPorts": true + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "publishAllPorts": true, + "useSSL": true } } } \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Startup.cs b/src/services/Wappa.Motorista.API/Startup.cs index e39e827d..aeceee8d 100644 --- a/src/services/Wappa.Motorista.API/Startup.cs +++ b/src/services/Wappa.Motorista.API/Startup.cs @@ -5,44 +5,49 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using NSE.Clientes.API.Configuration; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Wappa.Motoristas.API.Configuration; namespace Wappa.Motoristas.API { public class Startup { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddControllers(); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - } - } + public IConfiguration Configuration { get; } + + public Startup(IHostEnvironment hostEnvironment) + { + var builder = new ConfigurationBuilder() + .SetBasePath(hostEnvironment.ContentRootPath) + .AddJsonFile("appsettings.json", true, true) + .AddJsonFile($"appsettings.{hostEnvironment.EnvironmentName}.json", true, true) + .AddEnvironmentVariables(); + + if (hostEnvironment.IsDevelopment()) + { + builder.AddUserSecrets(); + } + + Configuration = builder.Build(); + } + + public void ConfigureServices(IServiceCollection services) + { + services.AddApiConfiguration(Configuration); + + services.AddSwaggerConfiguration(); + + services.RegisterServices(); + } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + app.UseSwaggerConfiguration(); + + app.UseApiConfiguration(env); + } + } } diff --git a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj index 48a3dab3..857a570e 100644 --- a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj +++ b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj @@ -1,9 +1,10 @@ - + netcoreapp3.1 Linux ..\..\.. + 0caf6535-96f2-4d67-a416-3089d65205c3 diff --git a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj.user b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj.user index e681dafe..195b56e1 100644 --- a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj.user +++ b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj.user @@ -1,6 +1,9 @@  - Docker + IIS Development + + + ProjectDebugger \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/appsettings.Development.json b/src/services/Wappa.Motorista.API/appsettings.Development.json index 8983e0fc..5ca6dd36 100644 --- a/src/services/Wappa.Motorista.API/appsettings.Development.json +++ b/src/services/Wappa.Motorista.API/appsettings.Development.json @@ -5,5 +5,14 @@ "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } + }, + "ConnectionStrings": { + "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=NerdStoreEnterpriseDB;Trusted_Connection=True;MultipleActiveResultSets=true" + }, + "AppSettings": { + "Secret": "MEUSEGREDOSUPERSECRETO", + "ExpiracaoHoras": 2, + "Emissor": "MeuSistema", + "ValidoEm": "https://localhost" } } From e572cbef71eaa78a5bf06850326a203fadf72006 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Mon, 8 Mar 2021 23:17:59 -0300 Subject: [PATCH 05/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Corre=C3=A7=C3=A3o=20namespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Configuration/DependencyInjectionConfig.cs | 2 +- .../Wappa.Motorista.API/Configuration/SwaggerConfig.cs | 2 +- src/services/Wappa.Motorista.API/Startup.cs | 7 ------- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs index 07dbc565..3c0a4330 100644 --- a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs +++ b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs @@ -3,7 +3,7 @@ using Wappa.Motoristas.API.Data.Repository; using Wappa.Motoristas.API.Models; -namespace NSE.Clientes.API.Configuration +namespace Wappa.Motoristas.API.Configuration { public static class DependencyInjectionConfig { diff --git a/src/services/Wappa.Motorista.API/Configuration/SwaggerConfig.cs b/src/services/Wappa.Motorista.API/Configuration/SwaggerConfig.cs index 7a4d9c3c..1106cba3 100644 --- a/src/services/Wappa.Motorista.API/Configuration/SwaggerConfig.cs +++ b/src/services/Wappa.Motorista.API/Configuration/SwaggerConfig.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; -namespace NSE.Clientes.API.Configuration +namespace Wappa.Motoristas.API.Configuration { public static class SwaggerConfig { diff --git a/src/services/Wappa.Motorista.API/Startup.cs b/src/services/Wappa.Motorista.API/Startup.cs index aeceee8d..25fae191 100644 --- a/src/services/Wappa.Motorista.API/Startup.cs +++ b/src/services/Wappa.Motorista.API/Startup.cs @@ -1,15 +1,8 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using NSE.Clientes.API.Configuration; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Wappa.Motoristas.API.Configuration; namespace Wappa.Motoristas.API From d2ee5a30b600bb152c6138174b8df9a560b56f8b Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Mon, 8 Mar 2021 23:30:02 -0300 Subject: [PATCH 06/83] TAR-1-Criar-API-Motorista #comment - Dockerizando projeto --- .gitignore | 3 +++ Wappa.sln | 6 ++++++ docker-compose.dcproj | 18 ++++++++++++++++ docker-compose.override.yml | 13 ++++++++++++ docker-compose.yml | 8 +++++++ src/services/Wappa.Motorista.API/Dockerfile | 8 ++++--- .../Wappa.Motorista.API/Dockerfile.original | 21 +++++++++++++++++++ .../Wappa.Motoristas.API.csproj | 1 + 8 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 docker-compose.dcproj create mode 100644 docker-compose.override.yml create mode 100644 docker-compose.yml create mode 100644 src/services/Wappa.Motorista.API/Dockerfile.original diff --git a/.gitignore b/.gitignore index b2ca2ff8..dd70580a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ /src/building blocks/Wappa.Core/obj /src/services/Wappa.Motorista.API/bin/Debug/netcoreapp3.1 /src/services/Wappa.Motorista.API/obj +/obj +/bin/Debug +/src/services/Wappa.Motoristas.API/obj/Docker diff --git a/Wappa.sln b/Wappa.sln index a4ddb158..d6ca280a 100644 --- a/Wappa.sln +++ b/Wappa.sln @@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Motorista", "Motorista", "{ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wappa.Motoristas.API", "src\services\Wappa.Motorista.API\Wappa.Motoristas.API.csproj", "{9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60}" EndProject +Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{496BCAED-C350-4AD3-AEDE-5810E67E724C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,6 +31,10 @@ Global {9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60}.Debug|Any CPU.Build.0 = Debug|Any CPU {9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60}.Release|Any CPU.ActiveCfg = Release|Any CPU {9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60}.Release|Any CPU.Build.0 = Release|Any CPU + {496BCAED-C350-4AD3-AEDE-5810E67E724C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {496BCAED-C350-4AD3-AEDE-5810E67E724C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {496BCAED-C350-4AD3-AEDE-5810E67E724C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {496BCAED-C350-4AD3-AEDE-5810E67E724C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/docker-compose.dcproj b/docker-compose.dcproj new file mode 100644 index 00000000..6f758b48 --- /dev/null +++ b/docker-compose.dcproj @@ -0,0 +1,18 @@ + + + + 2.1 + Linux + 496bcaed-c350-4ad3-aede-5810e67e724c + LaunchBrowser + {Scheme}://localhost:{ServicePort}/swagger + wappa.motoristas.api + + + + docker-compose.yml + + + + + \ No newline at end of file diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 00000000..88dd6ed3 --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,13 @@ +version: '3.4' + +services: + wappa.motoristas.api: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=https://+:443;http://+:80 + ports: + - "80" + - "443" + volumes: + - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro + - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..11e23116 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3.4' + +services: + wappa.motoristas.api: + image: ${DOCKER_REGISTRY-}wappamotoristasapi + build: + context: . + dockerfile: src/services/Wappa.Motorista.API/Dockerfile diff --git a/src/services/Wappa.Motorista.API/Dockerfile b/src/services/Wappa.Motorista.API/Dockerfile index 0a4e15d2..37039e0c 100644 --- a/src/services/Wappa.Motorista.API/Dockerfile +++ b/src/services/Wappa.Motorista.API/Dockerfile @@ -3,13 +3,15 @@ FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base WORKDIR /app EXPOSE 80 +EXPOSE 443 FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build WORKDIR /src -COPY ["src/services/Wappa.Motoristas.API/Wappa.Motoristas.API.csproj", "src/services/Wappa.Motoristas.API/"] -RUN dotnet restore "src/services/Wappa.Motoristas.API/Wappa.Motoristas.API.csproj" +COPY ["src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj", "src/services/Wappa.Motorista.API/"] +COPY ["src/building blocks/Wappa.Core/Wappa.Core.csproj", "src/building blocks/Wappa.Core/"] +RUN dotnet restore "src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj" COPY . . -WORKDIR "/src/src/services/Wappa.Motoristas.API" +WORKDIR "/src/src/services/Wappa.Motorista.API" RUN dotnet build "Wappa.Motoristas.API.csproj" -c Release -o /app/build FROM build AS publish diff --git a/src/services/Wappa.Motorista.API/Dockerfile.original b/src/services/Wappa.Motorista.API/Dockerfile.original new file mode 100644 index 00000000..0a4e15d2 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Dockerfile.original @@ -0,0 +1,21 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base +WORKDIR /app +EXPOSE 80 + +FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build +WORKDIR /src +COPY ["src/services/Wappa.Motoristas.API/Wappa.Motoristas.API.csproj", "src/services/Wappa.Motoristas.API/"] +RUN dotnet restore "src/services/Wappa.Motoristas.API/Wappa.Motoristas.API.csproj" +COPY . . +WORKDIR "/src/src/services/Wappa.Motoristas.API" +RUN dotnet build "Wappa.Motoristas.API.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "Wappa.Motoristas.API.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Wappa.Motoristas.API.dll"] \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj index 857a570e..467ca7dd 100644 --- a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj +++ b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj @@ -5,6 +5,7 @@ Linux ..\..\.. 0caf6535-96f2-4d67-a416-3089d65205c3 + ..\..\..\docker-compose.dcproj From 098c4e5fa0917b6d5b0785625b05e95d208dffff Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Mon, 8 Mar 2021 23:50:23 -0300 Subject: [PATCH 07/83] feature/TAR-1-Criar-API-Motorista #comment - Foi configurado o docker compose e adicionado banco MSSQL, rabbitmq e portainer --- docker-compose.override.yml | 65 ++++++++++++++++--- docker-compose.yml | 9 +++ src/services/Wappa.Motorista.API/Dockerfile | 4 +- .../Wappa.Motorista.API/Dockerfile.original | 21 ------ 4 files changed, 66 insertions(+), 33 deletions(-) delete mode 100644 src/services/Wappa.Motorista.API/Dockerfile.original diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 88dd6ed3..c3e78194 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -1,13 +1,58 @@ version: '3.4' services: - wappa.motoristas.api: - environment: - - ASPNETCORE_ENVIRONMENT=Development - - ASPNETCORE_URLS=https://+:443;http://+:80 - ports: - - "80" - - "443" - volumes: - - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro - - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro \ No newline at end of file + banco: + container_name: banco + environment: + - ASPNETCORE_ENVIRONMENT=Development + - SA_PASSWORD=wappaDev(!)Senha + - ACCEPT_EULA=Y + healthcheck: + test: ["CMD", "/opt/mssql-tools/bin/sqlcmd", "-Usa", "-PyourStrong(!)Password", "-Q", "select 1"] + interval: 1s + retries: 20 + ports: + - "1435:1433" + networks: + - local + + rabbitmq: + image: rabbitmq:management + hostname: rabbit-host + container_name: rabbit + ports: + - 5672:5672 + - 15672:15672 + networks: + - local + + portainer: + image: portainer/portainer + hostname: portainer-host + container_name: portainer-local + command: -H unix:///var/run/docker.sock + restart: always + ports: + - 9000:9000 + - 8000:8000 + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - portainer_data:/data + + wappa.motoristas.api: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=https://+:5001;http://+:4001 + ports: + - "4001:4001" + - "5001:5001" + volumes: + - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro + - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro + +networks: + local: + driver: bridge + +volumes: + portainer_data: \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 11e23116..6dbdefd6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,15 @@ version: '3.4' services: + banco: + image: mcr.microsoft.com/mssql/server:2017-latest + + rabbitmq: + image: rabbitmq:management + + portainer: + image: portainer/portainer + wappa.motoristas.api: image: ${DOCKER_REGISTRY-}wappamotoristasapi build: diff --git a/src/services/Wappa.Motorista.API/Dockerfile b/src/services/Wappa.Motorista.API/Dockerfile index 37039e0c..01792a49 100644 --- a/src/services/Wappa.Motorista.API/Dockerfile +++ b/src/services/Wappa.Motorista.API/Dockerfile @@ -2,8 +2,8 @@ FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base WORKDIR /app -EXPOSE 80 -EXPOSE 443 +EXPOSE 4001 +EXPOSE 5001 FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build WORKDIR /src diff --git a/src/services/Wappa.Motorista.API/Dockerfile.original b/src/services/Wappa.Motorista.API/Dockerfile.original deleted file mode 100644 index 0a4e15d2..00000000 --- a/src/services/Wappa.Motorista.API/Dockerfile.original +++ /dev/null @@ -1,21 +0,0 @@ -#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. - -FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base -WORKDIR /app -EXPOSE 80 - -FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build -WORKDIR /src -COPY ["src/services/Wappa.Motoristas.API/Wappa.Motoristas.API.csproj", "src/services/Wappa.Motoristas.API/"] -RUN dotnet restore "src/services/Wappa.Motoristas.API/Wappa.Motoristas.API.csproj" -COPY . . -WORKDIR "/src/src/services/Wappa.Motoristas.API" -RUN dotnet build "Wappa.Motoristas.API.csproj" -c Release -o /app/build - -FROM build AS publish -RUN dotnet publish "Wappa.Motoristas.API.csproj" -c Release -o /app/publish - -FROM base AS final -WORKDIR /app -COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Wappa.Motoristas.API.dll"] \ No newline at end of file From 3b1f5251fe6607466a46c627cd867ade5f7d2895 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 00:37:58 -0300 Subject: [PATCH 08/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o banco e as tabelas com migration --- docker-compose.override.yml | 7 +- .../Configuration/ApiConfig.cs | 14 +- .../20210309031025_Motorista.Designer.cs | 136 ++++++++++++++++++ .../Migrations/20210309031025_Motorista.cs | 94 ++++++++++++ .../MotoristaContextModelSnapshot.cs | 134 +++++++++++++++++ src/services/Wappa.Motorista.API/Startup.cs | 5 +- .../Wappa.Motoristas.API.csproj | 13 +- .../appsettings.Development.json | 7 +- 8 files changed, 398 insertions(+), 12 deletions(-) create mode 100644 src/services/Wappa.Motorista.API/Migrations/20210309031025_Motorista.Designer.cs create mode 100644 src/services/Wappa.Motorista.API/Migrations/20210309031025_Motorista.cs create mode 100644 src/services/Wappa.Motorista.API/Migrations/MotoristaContextModelSnapshot.cs diff --git a/docker-compose.override.yml b/docker-compose.override.yml index c3e78194..57392a0a 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -2,10 +2,10 @@ version: '3.4' services: banco: - container_name: banco + container_name: banco_sql environment: - ASPNETCORE_ENVIRONMENT=Development - - SA_PASSWORD=wappaDev(!)Senha + - SA_PASSWORD=yourStrong(!)Password - ACCEPT_EULA=Y healthcheck: test: ["CMD", "/opt/mssql-tools/bin/sqlcmd", "-Usa", "-PyourStrong(!)Password", "-Q", "select 1"] @@ -43,12 +43,15 @@ services: environment: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=https://+:5001;http://+:4001 + - CONTAINER=true ports: - "4001:4001" - "5001:5001" volumes: - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro + networks: + - local networks: local: diff --git a/src/services/Wappa.Motorista.API/Configuration/ApiConfig.cs b/src/services/Wappa.Motorista.API/Configuration/ApiConfig.cs index 22fee81e..4b98a22a 100644 --- a/src/services/Wappa.Motorista.API/Configuration/ApiConfig.cs +++ b/src/services/Wappa.Motorista.API/Configuration/ApiConfig.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using System; using Wappa.Motoristas.API.Data; namespace Wappa.Motoristas.API.Configuration @@ -12,8 +13,15 @@ public static class ApiConfig { public static void AddApiConfiguration(this IServiceCollection services, IConfiguration configuration) { + var conn = ""; + + if (Environment.GetEnvironmentVariable("CONTAINER") == "true") + conn = configuration.GetConnectionString("Container"); + else + conn = configuration.GetConnectionString("Localhost"); + services.AddDbContext(options => - options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"))); + options.UseSqlServer(conn, m => m.MigrationsAssembly("Wappa.Motoristas.API"))); services.AddControllers(); @@ -28,13 +36,15 @@ public static void AddApiConfiguration(this IServiceCollection services, IConfig }); } - public static void UseApiConfiguration(this IApplicationBuilder app, IWebHostEnvironment env) + public static void UseApiConfiguration(this IApplicationBuilder app, IWebHostEnvironment env, MotoristaContext motoristaContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } + //motoristaContext.Database.Migrate(); + app.UseRouting(); app.UseCors("Total"); diff --git a/src/services/Wappa.Motorista.API/Migrations/20210309031025_Motorista.Designer.cs b/src/services/Wappa.Motorista.API/Migrations/20210309031025_Motorista.Designer.cs new file mode 100644 index 00000000..36459b05 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Migrations/20210309031025_Motorista.Designer.cs @@ -0,0 +1,136 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Wappa.Motoristas.API.Data; + +namespace Wappa.Motoristas.API.Migrations +{ + [DbContext(typeof(MotoristaContext))] + [Migration("20210309031025_Motorista")] + partial class Motorista + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Carro", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Marca") + .IsRequired() + .HasColumnType("varchar(200)"); + + b.Property("Modelo") + .IsRequired() + .HasColumnType("varchar(100)"); + + b.Property("MotoristaId") + .HasColumnType("uniqueidentifier"); + + b.Property("Placa") + .IsRequired() + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex("MotoristaId") + .IsUnique(); + + b.ToTable("Carros"); + }); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Endereco", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Bairro") + .IsRequired() + .HasColumnType("varchar(100)"); + + b.Property("Cep") + .IsRequired() + .HasColumnType("varchar(20)"); + + b.Property("Cidade") + .IsRequired() + .HasColumnType("varchar(100)"); + + b.Property("Complemento") + .HasColumnType("varchar(250)"); + + b.Property("Estado") + .IsRequired() + .HasColumnType("varchar(50)"); + + b.Property("Logradouro") + .IsRequired() + .HasColumnType("varchar(200)"); + + b.Property("MotoristaId") + .HasColumnType("uniqueidentifier"); + + b.Property("Numero") + .IsRequired() + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("MotoristaId") + .IsUnique(); + + b.ToTable("Enderecos"); + }); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Motorista", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Nome") + .IsRequired() + .HasColumnType("varchar(200)"); + + b.Property("SobreNome") + .IsRequired() + .HasColumnType("varchar(200)"); + + b.HasKey("Id"); + + b.ToTable("Motoristas"); + }); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Carro", b => + { + b.HasOne("Wappa.Motoristas.API.Models.Motorista", "Motorista") + .WithOne("Carro") + .HasForeignKey("Wappa.Motoristas.API.Models.Carro", "MotoristaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Endereco", b => + { + b.HasOne("Wappa.Motoristas.API.Models.Motorista", "Motorista") + .WithOne("Endereco") + .HasForeignKey("Wappa.Motoristas.API.Models.Endereco", "MotoristaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/services/Wappa.Motorista.API/Migrations/20210309031025_Motorista.cs b/src/services/Wappa.Motorista.API/Migrations/20210309031025_Motorista.cs new file mode 100644 index 00000000..440db8b2 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Migrations/20210309031025_Motorista.cs @@ -0,0 +1,94 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Wappa.Motoristas.API.Migrations +{ + public partial class Motorista : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Motoristas", + columns: table => new + { + Id = table.Column(nullable: false), + Nome = table.Column(type: "varchar(200)", nullable: false), + SobreNome = table.Column(type: "varchar(200)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Motoristas", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Carros", + columns: table => new + { + Id = table.Column(nullable: false), + Marca = table.Column(type: "varchar(200)", nullable: false), + Modelo = table.Column(type: "varchar(100)", nullable: false), + Placa = table.Column(type: "varchar(20)", nullable: false), + MotoristaId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Carros", x => x.Id); + table.ForeignKey( + name: "FK_Carros_Motoristas_MotoristaId", + column: x => x.MotoristaId, + principalTable: "Motoristas", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Enderecos", + columns: table => new + { + Id = table.Column(nullable: false), + Logradouro = table.Column(type: "varchar(200)", nullable: false), + Numero = table.Column(type: "varchar(50)", nullable: false), + Complemento = table.Column(type: "varchar(250)", nullable: true), + Bairro = table.Column(type: "varchar(100)", nullable: false), + Cep = table.Column(type: "varchar(20)", nullable: false), + Cidade = table.Column(type: "varchar(100)", nullable: false), + Estado = table.Column(type: "varchar(50)", nullable: false), + MotoristaId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Enderecos", x => x.Id); + table.ForeignKey( + name: "FK_Enderecos_Motoristas_MotoristaId", + column: x => x.MotoristaId, + principalTable: "Motoristas", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Carros_MotoristaId", + table: "Carros", + column: "MotoristaId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Enderecos_MotoristaId", + table: "Enderecos", + column: "MotoristaId", + unique: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Carros"); + + migrationBuilder.DropTable( + name: "Enderecos"); + + migrationBuilder.DropTable( + name: "Motoristas"); + } + } +} diff --git a/src/services/Wappa.Motorista.API/Migrations/MotoristaContextModelSnapshot.cs b/src/services/Wappa.Motorista.API/Migrations/MotoristaContextModelSnapshot.cs new file mode 100644 index 00000000..57567704 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Migrations/MotoristaContextModelSnapshot.cs @@ -0,0 +1,134 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Wappa.Motoristas.API.Data; + +namespace Wappa.Motoristas.API.Migrations +{ + [DbContext(typeof(MotoristaContext))] + partial class MotoristaContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Carro", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Marca") + .IsRequired() + .HasColumnType("varchar(200)"); + + b.Property("Modelo") + .IsRequired() + .HasColumnType("varchar(100)"); + + b.Property("MotoristaId") + .HasColumnType("uniqueidentifier"); + + b.Property("Placa") + .IsRequired() + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex("MotoristaId") + .IsUnique(); + + b.ToTable("Carros"); + }); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Endereco", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Bairro") + .IsRequired() + .HasColumnType("varchar(100)"); + + b.Property("Cep") + .IsRequired() + .HasColumnType("varchar(20)"); + + b.Property("Cidade") + .IsRequired() + .HasColumnType("varchar(100)"); + + b.Property("Complemento") + .HasColumnType("varchar(250)"); + + b.Property("Estado") + .IsRequired() + .HasColumnType("varchar(50)"); + + b.Property("Logradouro") + .IsRequired() + .HasColumnType("varchar(200)"); + + b.Property("MotoristaId") + .HasColumnType("uniqueidentifier"); + + b.Property("Numero") + .IsRequired() + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("MotoristaId") + .IsUnique(); + + b.ToTable("Enderecos"); + }); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Motorista", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Nome") + .IsRequired() + .HasColumnType("varchar(200)"); + + b.Property("SobreNome") + .IsRequired() + .HasColumnType("varchar(200)"); + + b.HasKey("Id"); + + b.ToTable("Motoristas"); + }); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Carro", b => + { + b.HasOne("Wappa.Motoristas.API.Models.Motorista", "Motorista") + .WithOne("Carro") + .HasForeignKey("Wappa.Motoristas.API.Models.Carro", "MotoristaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Endereco", b => + { + b.HasOne("Wappa.Motoristas.API.Models.Motorista", "Motorista") + .WithOne("Endereco") + .HasForeignKey("Wappa.Motoristas.API.Models.Endereco", "MotoristaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/services/Wappa.Motorista.API/Startup.cs b/src/services/Wappa.Motorista.API/Startup.cs index 25fae191..680f70d3 100644 --- a/src/services/Wappa.Motorista.API/Startup.cs +++ b/src/services/Wappa.Motorista.API/Startup.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Wappa.Motoristas.API.Configuration; +using Wappa.Motoristas.API.Data; namespace Wappa.Motoristas.API { @@ -36,11 +37,11 @@ public void ConfigureServices(IServiceCollection services) services.RegisterServices(); } - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MotoristaContext motoristaContext) { app.UseSwaggerConfiguration(); - app.UseApiConfiguration(env); + app.UseApiConfiguration(env, motoristaContext); } } } diff --git a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj index 467ca7dd..04fbdde8 100644 --- a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj +++ b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj @@ -10,14 +10,21 @@ - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/src/services/Wappa.Motorista.API/appsettings.Development.json b/src/services/Wappa.Motorista.API/appsettings.Development.json index 5ca6dd36..187cc577 100644 --- a/src/services/Wappa.Motorista.API/appsettings.Development.json +++ b/src/services/Wappa.Motorista.API/appsettings.Development.json @@ -6,13 +6,14 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "ConnectionStrings": { - "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=NerdStoreEnterpriseDB;Trusted_Connection=True;MultipleActiveResultSets=true" - }, "AppSettings": { "Secret": "MEUSEGREDOSUPERSECRETO", "ExpiracaoHoras": 2, "Emissor": "MeuSistema", "ValidoEm": "https://localhost" + }, + "ConnectionStrings": { + "Container": "Server=banco_sql,1433;Database=WappaDev; User=sa; Password=yourStrong(!)Password;Trusted_Connection=False;MultipleActiveResultSets=true", + "Localhost": "Server=localhost,1435;Database=WappaDev; User=sa; Password=yourStrong(!)Password;Trusted_Connection=False;MultipleActiveResultSets=true" } } From 9c6adafc895b321c0a8ba22898e1e35d09f0a894 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 00:54:17 -0300 Subject: [PATCH 09/83] feature/TAR-1-Criar-API-Motorista #comment - Implementando os metodos do repositorio de motorista --- .../Data/Repository/MotoristaRepository.cs | 18 ++++++++++++++---- .../Models/IMotoristaRepository.cs | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs b/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs index 358eda3f..2b716ddb 100644 --- a/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs +++ b/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs @@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore; using Wappa.Core.Data; using Wappa.Motoristas.API.Models; -using Wappa.Motoristas.API.Data; namespace Wappa.Motoristas.API.Data.Repository { @@ -23,14 +22,25 @@ public async Task> ObterTodos() return await _context.Motorista.AsNoTracking().ToListAsync(); } - public void Adicionar(Motorista cliente) + public void Adicionar(Motorista motorista) { - _context.Motorista.Add(cliente); + _context.Motorista.Add(motorista); } + + public void Atualizar(Motorista motorista) + { + _context.Motorista.Update(motorista); + } + + public void Deletar(Motorista motorista) + { + _context.Motorista.Remove(motorista); + } + public void Dispose() { _context.Dispose(); } - } + } } \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs b/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs index ad8bff81..e303058a 100644 --- a/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs +++ b/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs @@ -6,7 +6,9 @@ namespace Wappa.Motoristas.API.Models { public interface IMotoristaRepository : IRepository { - void Adicionar(Motorista cliente); + void Adicionar(Motorista motorista); + void Atualizar(Motorista motorista); + void Deletar(Motorista motorista); Task> ObterTodos(); } From cfc20266bba9df21975efaf08ba9b09a535a5fdd Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 02:28:25 -0300 Subject: [PATCH 10/83] feature/TAR-1-Criar-API-Motorista #comment - Implementando mediator --- .../Communication/ResponseResult.cs | 26 +++++++++++++++++ .../Wappa.Core/Mediator/IMediatorHandler.cs | 12 ++++++++ .../Wappa.Core/Mediator/MediatorHandler.cs | 27 ++++++++++++++++++ .../Wappa.Core/Messages/Command.cs | 22 +++++++++++++++ .../Wappa.Core/Messages/CommandHandler.cs | 28 +++++++++++++++++++ .../Wappa.Core/Messages/Event.cs | 15 ++++++++++ .../Messages/Integration/IntegrationEvent.cs | 10 +++++++ .../Messages/Integration/ResponseMessage.cs | 14 ++++++++++ .../Wappa.Core/Messages/Message.cs | 17 +++++++++++ .../Wappa.Core/Wappa.Core.csproj | 5 ++++ 10 files changed, 176 insertions(+) create mode 100644 src/building blocks/Wappa.Core/Communication/ResponseResult.cs create mode 100644 src/building blocks/Wappa.Core/Mediator/IMediatorHandler.cs create mode 100644 src/building blocks/Wappa.Core/Mediator/MediatorHandler.cs create mode 100644 src/building blocks/Wappa.Core/Messages/Command.cs create mode 100644 src/building blocks/Wappa.Core/Messages/CommandHandler.cs create mode 100644 src/building blocks/Wappa.Core/Messages/Event.cs create mode 100644 src/building blocks/Wappa.Core/Messages/Integration/IntegrationEvent.cs create mode 100644 src/building blocks/Wappa.Core/Messages/Integration/ResponseMessage.cs create mode 100644 src/building blocks/Wappa.Core/Messages/Message.cs diff --git a/src/building blocks/Wappa.Core/Communication/ResponseResult.cs b/src/building blocks/Wappa.Core/Communication/ResponseResult.cs new file mode 100644 index 00000000..26e3cc09 --- /dev/null +++ b/src/building blocks/Wappa.Core/Communication/ResponseResult.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; + +namespace Wappa.Core.Communication +{ + public class ResponseResult + { + public ResponseResult() + { + Errors = new ResponseErrorMessages(); + } + + public string Title { get; set; } + public int Status { get; set; } + public ResponseErrorMessages Errors { get; set; } + } + + public class ResponseErrorMessages + { + public ResponseErrorMessages() + { + Mensagens = new List(); + } + + public List Mensagens { get; set; } + } +} diff --git a/src/building blocks/Wappa.Core/Mediator/IMediatorHandler.cs b/src/building blocks/Wappa.Core/Mediator/IMediatorHandler.cs new file mode 100644 index 00000000..c8e125d5 --- /dev/null +++ b/src/building blocks/Wappa.Core/Mediator/IMediatorHandler.cs @@ -0,0 +1,12 @@ +using FluentValidation.Results; +using Wappa.Core.Messages; +using System.Threading.Tasks; + +namespace Wappa.Core.Mediator +{ + public interface IMediatorHandler + { + Task PublicarEvento(T evento) where T : Event; + Task EnviarComando(T comando) where T : Command; + } +} diff --git a/src/building blocks/Wappa.Core/Mediator/MediatorHandler.cs b/src/building blocks/Wappa.Core/Mediator/MediatorHandler.cs new file mode 100644 index 00000000..95623e36 --- /dev/null +++ b/src/building blocks/Wappa.Core/Mediator/MediatorHandler.cs @@ -0,0 +1,27 @@ +using FluentValidation.Results; +using MediatR; +using Wappa.Core.Messages; +using System.Threading.Tasks; + +namespace Wappa.Core.Mediator +{ + public class MediatorHandler : IMediatorHandler + { + private readonly IMediator _mediator; + + public MediatorHandler(IMediator mediator) + { + _mediator = mediator; + } + + public async Task EnviarComando(T comando) where T : Command + { + return await _mediator.Send(comando); + } + + public async Task PublicarEvento(T evento) where T : Event + { + await _mediator.Publish(evento); + } + } +} diff --git a/src/building blocks/Wappa.Core/Messages/Command.cs b/src/building blocks/Wappa.Core/Messages/Command.cs new file mode 100644 index 00000000..756e0f3e --- /dev/null +++ b/src/building blocks/Wappa.Core/Messages/Command.cs @@ -0,0 +1,22 @@ +using FluentValidation.Results; +using MediatR; +using System; + +namespace Wappa.Core.Messages +{ + public abstract class Command : Message, IRequest + { + public DateTime TimeStamp { get; private set; } + public ValidationResult ValidationResult { get; set; } + + protected Command() + { + TimeStamp = DateTime.Now; + } + + public virtual bool EhValido() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/building blocks/Wappa.Core/Messages/CommandHandler.cs b/src/building blocks/Wappa.Core/Messages/CommandHandler.cs new file mode 100644 index 00000000..54a4e93a --- /dev/null +++ b/src/building blocks/Wappa.Core/Messages/CommandHandler.cs @@ -0,0 +1,28 @@ +using FluentValidation.Results; +using System.Threading.Tasks; +using Wappa.Core.Data; + +namespace Wappa.Core.Messages +{ + public abstract class CommandHandler + { + protected ValidationResult ValidationResult; + + protected CommandHandler() + { + ValidationResult = new ValidationResult(); + } + + protected void AdicionarErro(string message) + { + ValidationResult.Errors.Add(new ValidationFailure(string.Empty, message)); + } + + protected async Task PersistirDados(IUnitOfWork unitOfWork) + { + if (!await unitOfWork.Commit()) AdicionarErro("Houve um erro ao persistir os dados"); + + return ValidationResult; + } + } +} diff --git a/src/building blocks/Wappa.Core/Messages/Event.cs b/src/building blocks/Wappa.Core/Messages/Event.cs new file mode 100644 index 00000000..fd3d3dc4 --- /dev/null +++ b/src/building blocks/Wappa.Core/Messages/Event.cs @@ -0,0 +1,15 @@ +using MediatR; +using System; + +namespace Wappa.Core.Messages +{ + public class Event : Message, INotification + { + public DateTime Timestamp { get; private set; } + + protected Event() + { + Timestamp = DateTime.Now; + } + } +} diff --git a/src/building blocks/Wappa.Core/Messages/Integration/IntegrationEvent.cs b/src/building blocks/Wappa.Core/Messages/Integration/IntegrationEvent.cs new file mode 100644 index 00000000..2d34d32c --- /dev/null +++ b/src/building blocks/Wappa.Core/Messages/Integration/IntegrationEvent.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Wappa.Core.Messages.Integration +{ + public abstract class IntegrationEvent : Event + { + } +} diff --git a/src/building blocks/Wappa.Core/Messages/Integration/ResponseMessage.cs b/src/building blocks/Wappa.Core/Messages/Integration/ResponseMessage.cs new file mode 100644 index 00000000..92812b0c --- /dev/null +++ b/src/building blocks/Wappa.Core/Messages/Integration/ResponseMessage.cs @@ -0,0 +1,14 @@ +using FluentValidation.Results; + +namespace Wappa.Core.Messages.Integration +{ + public class ResponseMessage : Message + { + public ValidationResult ValidationResult { get; set; } + + public ResponseMessage(ValidationResult validationResult) + { + ValidationResult = validationResult; + } + } +} diff --git a/src/building blocks/Wappa.Core/Messages/Message.cs b/src/building blocks/Wappa.Core/Messages/Message.cs new file mode 100644 index 00000000..859d3555 --- /dev/null +++ b/src/building blocks/Wappa.Core/Messages/Message.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Wappa.Core.Messages +{ + public abstract class Message + { + public string MessageType { get; protected set; } + public Guid AggregateId { get; protected set; } + + protected Message() + { + MessageType = GetType().Name; + } + } +} diff --git a/src/building blocks/Wappa.Core/Wappa.Core.csproj b/src/building blocks/Wappa.Core/Wappa.Core.csproj index cb631906..822a4959 100644 --- a/src/building blocks/Wappa.Core/Wappa.Core.csproj +++ b/src/building blocks/Wappa.Core/Wappa.Core.csproj @@ -4,4 +4,9 @@ netcoreapp3.1 + + + + + From 8d569a61852ed621bbd5d249f4425482554c5399 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 02:29:00 -0300 Subject: [PATCH 11/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o comando para adicionar um motorista --- .../Commands/AdicionarMotoristaCommand.cs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/services/Wappa.Motorista.API/Application/Commands/AdicionarMotoristaCommand.cs diff --git a/src/services/Wappa.Motorista.API/Application/Commands/AdicionarMotoristaCommand.cs b/src/services/Wappa.Motorista.API/Application/Commands/AdicionarMotoristaCommand.cs new file mode 100644 index 00000000..7e22b618 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Application/Commands/AdicionarMotoristaCommand.cs @@ -0,0 +1,48 @@ +using FluentValidation; +using Wappa.Core.Messages; +using System; +using Wappa.Motoristas.API.Application.DTO; + +namespace Wappa.Motoristas.API.Application.Commands +{ + public class AdicionarMotoristaCommand : Command + { + // Motorista + public string Nome { get; set; } + public string SobreNome { get; set; } + + // Carro + public CarroDTO Carro { get; set; } + + // Endereco + public EnderecoDTO Endereco { get; set; } + + public override bool EhValido() + { + ValidationResult = new AdicionarMotoristaValidation().Validate(this); + return ValidationResult.IsValid; + } + + public class AdicionarMotoristaValidation : AbstractValidator + { + public AdicionarMotoristaValidation() + { + RuleFor(c => c.Nome) + .NotNull() + .WithMessage("Inform o nome do motorista"); + + RuleFor(c => c.SobreNome) + .NotNull() + .WithMessage("Inform o sobrenome do motorista"); + + RuleFor(c => c.Carro) + .NotNull() + .WithMessage("Informe o carro do motorista"); + + RuleFor(c => c.Endereco) + .NotNull() + .WithMessage("Informe o endereço do motorista"); + } + } + } +} \ No newline at end of file From a0bfca46c632ee4b6ecb15625d8305bada4ece8e Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 02:29:43 -0300 Subject: [PATCH 12/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20criado=20o=20handler=20que=20processa=20a=20adi?= =?UTF-8?q?=C3=A7=C3=A3o=20no=20motorista?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/MotoristaCommandHandler.cs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/services/Wappa.Motorista.API/Application/Commands/MotoristaCommandHandler.cs diff --git a/src/services/Wappa.Motorista.API/Application/Commands/MotoristaCommandHandler.cs b/src/services/Wappa.Motorista.API/Application/Commands/MotoristaCommandHandler.cs new file mode 100644 index 00000000..a2637494 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Application/Commands/MotoristaCommandHandler.cs @@ -0,0 +1,57 @@ +using FluentValidation.Results; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Wappa.Core.Messages; +using Wappa.Motoristas.API.Models; + +namespace Wappa.Motoristas.API.Application.Commands +{ + public class MotoristaCommandHandler : CommandHandler, + IRequestHandler + { + private readonly IMotoristaRepository _motoristaRepository; + + public MotoristaCommandHandler(IMotoristaRepository motoristaRepository) + { + _motoristaRepository = motoristaRepository; + } + + public async Task Handle(AdicionarMotoristaCommand message, CancellationToken cancellationToken) + { + if (!message.EhValido()) return message.ValidationResult; + + var motorista = MapearMotorista(message); + + _motoristaRepository.Adicionar(motorista); + + return await PersistirDados(_motoristaRepository.UnitOfWork); + } + + private Motorista MapearMotorista(AdicionarMotoristaCommand message) + { + var endereco = new Endereco + { + Logradouro = message.Endereco.Logradouro, + Numero = message.Endereco.Numero, + Complemento = message.Endereco.Complemento, + Bairro = message.Endereco.Bairro, + Cep = message.Endereco.Cep, + Cidade = message.Endereco.Cidade, + Estado = message.Endereco.Estado + }; + + var carro = new Carro(message.Carro.Marca, message.Carro.Modelo, message.Carro.Placa); + + var motorista = new Motorista(message.Nome, message.SobreNome); + + motorista.Carro = carro; + motorista.Endereco = endereco; + + return motorista; + } + } +} From 211f2fbbdbf6bc0d6a728fa65c5d016ed47e1420 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 02:30:08 -0300 Subject: [PATCH 13/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o DTO para montar o motorista --- .../Wappa.Motorista.API/Application/DTO/CarroDTO.cs | 9 +++++++++ .../Application/DTO/EnderecoDTO.cs | 13 +++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs create mode 100644 src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs diff --git a/src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs b/src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs new file mode 100644 index 00000000..144f6e3b --- /dev/null +++ b/src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs @@ -0,0 +1,9 @@ +namespace Wappa.Motoristas.API.Application.DTO +{ + public class CarroDTO + { + public string Marca { get; set; } + public string Modelo { get; set; } + public string Placa { get; set; } + } +} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs b/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs new file mode 100644 index 00000000..9eb30cf4 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs @@ -0,0 +1,13 @@ +namespace Wappa.Motoristas.API.Application.DTO +{ + public class EnderecoDTO + { + public string Logradouro { get; set; } + public string Numero { get; set; } + public string Complemento { get; set; } + public string Bairro { get; set; } + public string Cep { get; set; } + public string Cidade { get; set; } + public string Estado { get; set; } + } +} \ No newline at end of file From 95df5ead557f1a678d454c5e3bb33e2a32d6b7fe Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 02:30:57 -0300 Subject: [PATCH 14/83] feature/TAR-1-Criar-API-Motorista #comment - Ajuste --- .../Data/MotoristsContext.cs | 6 +++++- .../Wappa.Motorista.API/Models/Endereco.cs | 18 ++++++++++-------- .../Wappa.Motorista.API/Models/Motorista.cs | 7 +++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs b/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs index 404ec521..01d8b56d 100644 --- a/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs +++ b/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs @@ -4,6 +4,7 @@ using Wappa.Motoristas.API.Models; using Wappa.Core.Data; using Wappa.Core.DomainObjects; +using FluentValidation.Results; namespace Wappa.Motoristas.API.Data { @@ -23,7 +24,8 @@ public MotoristaContext(DbContextOptions options) protected override void OnModelCreating(ModelBuilder modelBuilder) { - + modelBuilder.Ignore(); + foreach (var property in modelBuilder.Model.GetEntityTypes().SelectMany( e => e.GetProperties().Where(p => p.ClrType == typeof(string)))) property.SetColumnType("varchar(100)"); @@ -32,6 +34,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .SelectMany(e => e.GetForeignKeys())) relationship.DeleteBehavior = DeleteBehavior.Cascade; modelBuilder.ApplyConfigurationsFromAssembly(typeof(MotoristaContext).Assembly); + + base.OnModelCreating(modelBuilder); } public async Task Commit() diff --git a/src/services/Wappa.Motorista.API/Models/Endereco.cs b/src/services/Wappa.Motorista.API/Models/Endereco.cs index 6eee5876..083a0f38 100644 --- a/src/services/Wappa.Motorista.API/Models/Endereco.cs +++ b/src/services/Wappa.Motorista.API/Models/Endereco.cs @@ -5,17 +5,19 @@ namespace Wappa.Motoristas.API.Models { public class Endereco: Entity { - public string Logradouro { get; private set; } - public string Numero { get; private set; } - public string Complemento { get; private set; } - public string Bairro { get; private set; } - public string Cep { get; private set; } - public string Cidade { get; private set; } - public string Estado { get; private set; } - public Guid MotoristaId { get; private set; } + public string Logradouro { get; set; } + public string Numero { get; set; } + public string Complemento { get; set; } + public string Bairro { get; set; } + public string Cep { get; set; } + public string Cidade { get; set; } + public string Estado { get; set; } + public Guid MotoristaId { get; set; } public Motorista Motorista { get; protected set; } + public Endereco(){} + public Endereco(string logradouro, string numero, string complemento, string bairro, string cep, string cidade, string estado) { Logradouro = logradouro; diff --git a/src/services/Wappa.Motorista.API/Models/Motorista.cs b/src/services/Wappa.Motorista.API/Models/Motorista.cs index 6a9607bd..3fe01d5a 100644 --- a/src/services/Wappa.Motorista.API/Models/Motorista.cs +++ b/src/services/Wappa.Motorista.API/Models/Motorista.cs @@ -7,14 +7,13 @@ public class Motorista: Entity, IAggregateRoot { public string Nome { get; private set; } public string SobreNome { get; private set; } - public Carro Carro { get; private set; } - public Endereco Endereco { get; private set; } + public Carro Carro { get; set; } + public Endereco Endereco { get; set; } protected Motorista() { } - public Motorista(Guid id, string nome, string sobreNome) + public Motorista(string nome, string sobreNome) { - Id = id; Nome = nome; SobreNome = sobreNome; } From 81b021b2711666abc05853bea8bad76621eba131 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 02:31:37 -0300 Subject: [PATCH 15/83] feature/TAR-1-Criar-API-Motorista #comment - Foi configurado o mediatR --- src/services/Wappa.Motorista.API/Startup.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/services/Wappa.Motorista.API/Startup.cs b/src/services/Wappa.Motorista.API/Startup.cs index 680f70d3..32706d71 100644 --- a/src/services/Wappa.Motorista.API/Startup.cs +++ b/src/services/Wappa.Motorista.API/Startup.cs @@ -1,3 +1,4 @@ +using MediatR; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -34,6 +35,8 @@ public void ConfigureServices(IServiceCollection services) services.AddSwaggerConfiguration(); + services.AddMediatR(typeof(Startup)); + services.RegisterServices(); } From 5e004d6d66171a9684ed99583d3b0785c65fd64e Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 02:31:59 -0300 Subject: [PATCH 16/83] feature/TAR-1-Criar-API-Motorista #comment - Foi configurado a DI --- .../Configuration/DependencyInjectionConfig.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs index 3c0a4330..69724a07 100644 --- a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs +++ b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs @@ -1,4 +1,8 @@ -using Microsoft.Extensions.DependencyInjection; +using FluentValidation.Results; +using MediatR; +using Microsoft.Extensions.DependencyInjection; +using Wappa.Core.Mediator; +using Wappa.Motoristas.API.Application.Commands; using Wappa.Motoristas.API.Data; using Wappa.Motoristas.API.Data.Repository; using Wappa.Motoristas.API.Models; @@ -8,7 +12,14 @@ namespace Wappa.Motoristas.API.Configuration public static class DependencyInjectionConfig { public static void RegisterServices(this IServiceCollection services) - { + { + // Commands + services.AddScoped, MotoristaCommandHandler>(); + + // Application + services.AddScoped(); + + // Data services.AddScoped(); services.AddScoped(); } From 9745cc2b0bd48072dbfd8a0792ce2586e88768f2 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 02:32:26 -0300 Subject: [PATCH 17/83] feature/TAR-1-Criar-API-Motorista #comment - Foi implementado response customizado --- .../Controllers/MainController.cs | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/services/Wappa.Motorista.API/Controllers/MainController.cs diff --git a/src/services/Wappa.Motorista.API/Controllers/MainController.cs b/src/services/Wappa.Motorista.API/Controllers/MainController.cs new file mode 100644 index 00000000..9ac86c45 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Controllers/MainController.cs @@ -0,0 +1,85 @@ +using FluentValidation.Results; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ModelBinding; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Wappa.Core.Communication; + +namespace Wappa.Motoristas.API.Controllers +{ + [ApiController] + public abstract class MainController : Controller + { + protected ICollection Erros = new List(); + + protected ActionResult CustomResponse(object result = null) + { + if (OperacaoValida()) + { + return Ok(result); + } + + return BadRequest(new ValidationProblemDetails(new Dictionary + { + { "Mensagens", Erros.ToArray() } + })); + } + + protected ActionResult CustomResponse(ModelStateDictionary modelState) + { + var erros = modelState.Values.SelectMany(e => e.Errors); + foreach (var erro in erros) + { + AdicionarErroProcessamento(erro.ErrorMessage); + } + + return CustomResponse(); + } + + protected ActionResult CustomResponse(ValidationResult validationResult) + { + foreach (var erro in validationResult.Errors) + { + AdicionarErroProcessamento(erro.ErrorMessage); + } + + return CustomResponse(); + } + + protected ActionResult CustomResponse(ResponseResult resposta) + { + ResponsePossuiErros(resposta); + + return CustomResponse(); + } + + protected bool ResponsePossuiErros(ResponseResult resposta) + { + if (resposta == null || !resposta.Errors.Mensagens.Any()) return false; + + foreach (var mensagem in resposta.Errors.Mensagens) + { + AdicionarErroProcessamento(mensagem); + } + + return true; + } + + protected bool OperacaoValida() + { + return !Erros.Any(); + } + + protected void AdicionarErroProcessamento(string erro) + { + Erros.Add(erro); + } + + protected void LimparErrosProcessamento() + { + Erros.Clear(); + } + } +} From 75e521bbec85ae033dc6740d84c50795e30e5cbd Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 02:33:01 -0300 Subject: [PATCH 18/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20criado=20o=20primeiro=20m=C3=A9todo=20POST=20pa?= =?UTF-8?q?ra=20criar=20um=20motorista?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + Wappa.sln | 10 ++ .../DependencyInjectionExtensions.cs | 17 +++ .../Wappa.MessageBus/IMessageBus.cs | 37 ++++++ .../Wappa.MessageBus/MessageBus.cs | 109 ++++++++++++++++++ .../Wappa.MessageBus/Wappa.MessageBus.csproj | 17 +++ .../Controllers/MotoristaController.cs | 20 +++- .../Wappa.Motoristas.API.csproj | 7 ++ 8 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 src/building blocks/Wappa.MessageBus/DependencyInjectionExtensions.cs create mode 100644 src/building blocks/Wappa.MessageBus/IMessageBus.cs create mode 100644 src/building blocks/Wappa.MessageBus/MessageBus.cs create mode 100644 src/building blocks/Wappa.MessageBus/Wappa.MessageBus.csproj diff --git a/.gitignore b/.gitignore index dd70580a..b2152dfd 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ /obj /bin/Debug /src/services/Wappa.Motoristas.API/obj/Docker +/src/building blocks/Wappa.MessageBus/obj +/src/building blocks/Wappa.MessageBus/bin/Debug/netcoreapp3.1 diff --git a/Wappa.sln b/Wappa.sln index d6ca280a..791e88da 100644 --- a/Wappa.sln +++ b/Wappa.sln @@ -17,6 +17,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wappa.Motoristas.API", "src EndProject Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{496BCAED-C350-4AD3-AEDE-5810E67E724C}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MessageBus", "MessageBus", "{C94A4B68-ABAF-4566-8E42-3D603870A4F2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wappa.MessageBus", "src\building blocks\Wappa.MessageBus\Wappa.MessageBus.csproj", "{D4975541-0CC6-493B-90B2-AB3757D2A1B2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -35,6 +39,10 @@ Global {496BCAED-C350-4AD3-AEDE-5810E67E724C}.Debug|Any CPU.Build.0 = Debug|Any CPU {496BCAED-C350-4AD3-AEDE-5810E67E724C}.Release|Any CPU.ActiveCfg = Release|Any CPU {496BCAED-C350-4AD3-AEDE-5810E67E724C}.Release|Any CPU.Build.0 = Release|Any CPU + {D4975541-0CC6-493B-90B2-AB3757D2A1B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D4975541-0CC6-493B-90B2-AB3757D2A1B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D4975541-0CC6-493B-90B2-AB3757D2A1B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D4975541-0CC6-493B-90B2-AB3757D2A1B2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -44,6 +52,8 @@ Global {F1EF41B4-CA77-4B64-8C64-8AA0E16626A1} = {C5A6B0DC-3A32-46A4-858D-73410D1A81E9} {545ADEF2-79F6-4825-97A7-AD34D64A94EC} = {D7CC5A53-341D-41FD-9A24-0BD3C5569258} {9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60} = {545ADEF2-79F6-4825-97A7-AD34D64A94EC} + {C94A4B68-ABAF-4566-8E42-3D603870A4F2} = {DC4A0A94-B314-410C-803D-95E4A3F5C0FA} + {D4975541-0CC6-493B-90B2-AB3757D2A1B2} = {C94A4B68-ABAF-4566-8E42-3D603870A4F2} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1ABF1BAA-6091-41E7-93DE-3428D39E26BC} diff --git a/src/building blocks/Wappa.MessageBus/DependencyInjectionExtensions.cs b/src/building blocks/Wappa.MessageBus/DependencyInjectionExtensions.cs new file mode 100644 index 00000000..4cc82597 --- /dev/null +++ b/src/building blocks/Wappa.MessageBus/DependencyInjectionExtensions.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.DependencyInjection; +using System; + +namespace Wappa.MessageBus +{ + public static class DependencyInjectionExtensions + { + public static IServiceCollection AddMessageBus(this IServiceCollection services, string connection) + { + if (string.IsNullOrEmpty(connection)) throw new ArgumentNullException(); + + services.AddSingleton(new MessageBus(connection)); + + return services; + } + } +} diff --git a/src/building blocks/Wappa.MessageBus/IMessageBus.cs b/src/building blocks/Wappa.MessageBus/IMessageBus.cs new file mode 100644 index 00000000..dd0d36c0 --- /dev/null +++ b/src/building blocks/Wappa.MessageBus/IMessageBus.cs @@ -0,0 +1,37 @@ +using EasyNetQ; +using System; +using System.Threading.Tasks; +using Wappa.Core.Messages.Integration; + +namespace Wappa.MessageBus +{ + public interface IMessageBus : IDisposable + { + bool IsConnected { get; } + IAdvancedBus AdvancedBus { get; } + + void Publish(T message) where T : IntegrationEvent; + + Task PublishAsync(T message) where T : IntegrationEvent; + + void Subscribe(string subscriptionId, Action onMessage) where T : class; + + void SubscribeAsync(string subscriptionId, Func onMessage) where T : class; + + TResponse Request(TRequest request) + where TRequest : IntegrationEvent + where TResponse : ResponseMessage; + + Task RequestAsync(TRequest request) + where TRequest : IntegrationEvent + where TResponse : ResponseMessage; + + IDisposable Respond(Func responder) + where TRequest : IntegrationEvent + where TResponse : ResponseMessage; + + IDisposable RespondAsync(Func> responder) + where TRequest : IntegrationEvent + where TResponse : ResponseMessage; + } +} \ No newline at end of file diff --git a/src/building blocks/Wappa.MessageBus/MessageBus.cs b/src/building blocks/Wappa.MessageBus/MessageBus.cs new file mode 100644 index 00000000..86a5555d --- /dev/null +++ b/src/building blocks/Wappa.MessageBus/MessageBus.cs @@ -0,0 +1,109 @@ +using System; +using System.Threading.Tasks; +using EasyNetQ; +using Wappa.Core.Messages.Integration; +using Polly; +using RabbitMQ.Client.Exceptions; + +namespace Wappa.MessageBus +{ + public class MessageBus : IMessageBus + { + private IBus _bus; + private IAdvancedBus _advancedBus; + + private readonly string _connectionString; + + public MessageBus(string connectionString) + { + _connectionString = connectionString; + TryConnect(); + } + + public bool IsConnected => _bus?.IsConnected ?? false; + public IAdvancedBus AdvancedBus => _bus?.Advanced; + + public void Publish(T message) where T : IntegrationEvent + { + TryConnect(); + _bus.Publish(message); + } + + public async Task PublishAsync(T message) where T : IntegrationEvent + { + TryConnect(); + await _bus.PublishAsync(message); + } + + public void Subscribe(string subscriptionId, Action onMessage) where T : class + { + TryConnect(); + _bus.Subscribe(subscriptionId, onMessage); + } + + public void SubscribeAsync(string subscriptionId, Func onMessage) where T : class + { + TryConnect(); + _bus.SubscribeAsync(subscriptionId, onMessage); + } + + public TResponse Request(TRequest request) where TRequest : IntegrationEvent + where TResponse : ResponseMessage + { + TryConnect(); + return _bus.Request(request); + } + + public async Task RequestAsync(TRequest request) + where TRequest : IntegrationEvent where TResponse : ResponseMessage + { + TryConnect(); + return await _bus.RequestAsync(request); + } + + public IDisposable Respond(Func responder) + where TRequest : IntegrationEvent where TResponse : ResponseMessage + { + TryConnect(); + return _bus.Respond(responder); + } + + public IDisposable RespondAsync(Func> responder) + where TRequest : IntegrationEvent where TResponse : ResponseMessage + { + TryConnect(); + return _bus.RespondAsync(responder); + } + + private void TryConnect() + { + if (IsConnected) return; + + var policy = Policy.Handle() + .Or() + .WaitAndRetry(3, retryAttempt => + TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))); + + policy.Execute(() => + { + _bus = RabbitHutch.CreateBus(_connectionString); + _advancedBus = _bus.Advanced; + _advancedBus.Disconnected += OnDisconnect; + }); + } + + private void OnDisconnect(object s, EventArgs e) + { + var policy = Policy.Handle() + .Or() + .RetryForever(); + + policy.Execute(TryConnect); + } + + public void Dispose() + { + _bus.Dispose(); + } + } +} \ No newline at end of file diff --git a/src/building blocks/Wappa.MessageBus/Wappa.MessageBus.csproj b/src/building blocks/Wappa.MessageBus/Wappa.MessageBus.csproj new file mode 100644 index 00000000..e04efcb9 --- /dev/null +++ b/src/building blocks/Wappa.MessageBus/Wappa.MessageBus.csproj @@ -0,0 +1,17 @@ + + + + netcoreapp3.1 + + + + + + + + + + + + + diff --git a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs index 06dbd3d9..068eb98f 100644 --- a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs +++ b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs @@ -4,13 +4,25 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Wappa.Core.Mediator; +using Wappa.Motoristas.API.Application.Commands; namespace Wappa.Motoristas.API.Controllers { - [ApiController] - [Route("[controller]")] - public class MotoristaController : ControllerBase + [Route("api/motorista")] + public class MotoristaController : MainController { - + private readonly IMediatorHandler _mediator; + + public MotoristaController(IMediatorHandler mediator) + { + _mediator = mediator; + } + + [HttpPost] + public async Task AdicionarMotorista(AdicionarMotoristaCommand motorista) + { + return CustomResponse(await _mediator.EnviarComando(motorista)); + } } } diff --git a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj index 04fbdde8..7b5dd9fb 100644 --- a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj +++ b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj @@ -9,6 +9,7 @@ + @@ -29,6 +30,12 @@ + + + + + + From 1c1f35aaab7a3337bcae036305a9792c95a08695 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:38:40 -0300 Subject: [PATCH 19/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o PUT para atualizar dados do motorista --- .../Wappa.Motorista.API/Controllers/MotoristaController.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs index 068eb98f..45634b7a 100644 --- a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs +++ b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs @@ -24,5 +24,11 @@ public async Task AdicionarMotorista(AdicionarMotoristaCommand mo { return CustomResponse(await _mediator.EnviarComando(motorista)); } + + [HttpPut] + public async Task AtualizarMotorista(AtualizarMotoristaCommand motorista) + { + return CustomResponse(await _mediator.EnviarComando(motorista)); + } } } From d9a301aa306fdb245c664f5a7efead0206858eff Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:39:26 -0300 Subject: [PATCH 20/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20refatorado=20para=20usar=20o=20m=C3=A9todo=20ex?= =?UTF-8?q?tendido?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Application/Commands/AdicionarMotoristaCommand.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/Wappa.Motorista.API/Application/Commands/AdicionarMotoristaCommand.cs b/src/services/Wappa.Motorista.API/Application/Commands/AdicionarMotoristaCommand.cs index 7e22b618..4c7c21b8 100644 --- a/src/services/Wappa.Motorista.API/Application/Commands/AdicionarMotoristaCommand.cs +++ b/src/services/Wappa.Motorista.API/Application/Commands/AdicionarMotoristaCommand.cs @@ -2,6 +2,7 @@ using Wappa.Core.Messages; using System; using Wappa.Motoristas.API.Application.DTO; +using Wappa.Motoristas.API.Models; namespace Wappa.Motoristas.API.Application.Commands { @@ -21,7 +22,7 @@ public override bool EhValido() { ValidationResult = new AdicionarMotoristaValidation().Validate(this); return ValidationResult.IsValid; - } + } public class AdicionarMotoristaValidation : AbstractValidator { From 51387f740177c5fb750d9500d2203e709abb4aec Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:39:56 -0300 Subject: [PATCH 21/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o comando de atualizar os dados do motorista --- .../Commands/AtualizarMotoristaCommand.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/services/Wappa.Motorista.API/Application/Commands/AtualizarMotoristaCommand.cs diff --git a/src/services/Wappa.Motorista.API/Application/Commands/AtualizarMotoristaCommand.cs b/src/services/Wappa.Motorista.API/Application/Commands/AtualizarMotoristaCommand.cs new file mode 100644 index 00000000..384ccf58 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Application/Commands/AtualizarMotoristaCommand.cs @@ -0,0 +1,53 @@ +using FluentValidation; +using Wappa.Core.Messages; +using System; +using Wappa.Motoristas.API.Application.DTO; + +namespace Wappa.Motoristas.API.Application.Commands +{ + public class AtualizarMotoristaCommand : Command + { + public Guid Id { get; set; } + // Motorista + public string Nome { get; set; } + public string SobreNome { get; set; } + + // Carro + public CarroDTO Carro { get; set; } + + // Endereco + public EnderecoDTO Endereco { get; set; } + + public override bool EhValido() + { + ValidationResult = new AtualizarMotoristaValidation().Validate(this); + return ValidationResult.IsValid; + } + + public class AtualizarMotoristaValidation : AbstractValidator + { + public AtualizarMotoristaValidation() + { + RuleFor(c => c.Id) + .NotEqual(Guid.Empty) + .WithMessage("Id do motorista inválido"); + + RuleFor(c => c.Nome) + .NotNull() + .WithMessage("Inform o nome do motorista"); + + RuleFor(c => c.SobreNome) + .NotNull() + .WithMessage("Inform o sobrenome do motorista"); + + RuleFor(c => c.Carro) + .NotNull() + .WithMessage("Informe o carro do motorista"); + + RuleFor(c => c.Endereco) + .NotNull() + .WithMessage("Informe o endereço do motorista"); + } + } + } +} \ No newline at end of file From 5efa24548d6c9d795f5c1ad4d40f3bccc4adee2a Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:40:21 -0300 Subject: [PATCH 22/83] feature/TAR-1-Criar-API-Motorista #comment - Foi implementado o handler para atualizar o motorista --- .../Commands/MotoristaCommandHandler.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/services/Wappa.Motorista.API/Application/Commands/MotoristaCommandHandler.cs b/src/services/Wappa.Motorista.API/Application/Commands/MotoristaCommandHandler.cs index a2637494..29dd294a 100644 --- a/src/services/Wappa.Motorista.API/Application/Commands/MotoristaCommandHandler.cs +++ b/src/services/Wappa.Motorista.API/Application/Commands/MotoristaCommandHandler.cs @@ -6,12 +6,14 @@ using System.Threading; using System.Threading.Tasks; using Wappa.Core.Messages; +using Wappa.Motoristas.API.Application.Extensions; using Wappa.Motoristas.API.Models; namespace Wappa.Motoristas.API.Application.Commands { public class MotoristaCommandHandler : CommandHandler, - IRequestHandler + IRequestHandler, + IRequestHandler { private readonly IMotoristaRepository _motoristaRepository; @@ -24,34 +26,32 @@ public async Task Handle(AdicionarMotoristaCommand message, Ca { if (!message.EhValido()) return message.ValidationResult; - var motorista = MapearMotorista(message); + var motorista = message.MapearMotorista(); _motoristaRepository.Adicionar(motorista); return await PersistirDados(_motoristaRepository.UnitOfWork); } - private Motorista MapearMotorista(AdicionarMotoristaCommand message) + public async Task Handle(AtualizarMotoristaCommand message, CancellationToken cancellationToken) { - var endereco = new Endereco - { - Logradouro = message.Endereco.Logradouro, - Numero = message.Endereco.Numero, - Complemento = message.Endereco.Complemento, - Bairro = message.Endereco.Bairro, - Cep = message.Endereco.Cep, - Cidade = message.Endereco.Cidade, - Estado = message.Endereco.Estado - }; + if (!message.EhValido()) return message.ValidationResult; + + var motorista = await _motoristaRepository.ObterPorId(message.Id); - var carro = new Carro(message.Carro.Marca, message.Carro.Modelo, message.Carro.Placa); + if (motorista == null) + { + AdicionarErro("Motorista não foi encontrado"); + return ValidationResult; + } - var motorista = new Motorista(message.Nome, message.SobreNome); + message.MapearMotorista(motorista); - motorista.Carro = carro; - motorista.Endereco = endereco; + _motoristaRepository.Atualizar(motorista); - return motorista; + return await PersistirDados(_motoristaRepository.UnitOfWork); } + + } } From d6c385703ae155d9e67e0aacc9b0857de5abc520 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:40:43 -0300 Subject: [PATCH 23/83] feature/TAR-1-Criar-API-Motorista #comment - Ajuste propriedade --- src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs | 5 ++++- .../Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs b/src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs index 144f6e3b..4453984c 100644 --- a/src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs +++ b/src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs @@ -1,7 +1,10 @@ -namespace Wappa.Motoristas.API.Application.DTO +using System; + +namespace Wappa.Motoristas.API.Application.DTO { public class CarroDTO { + public Guid Id { get; set; } public string Marca { get; set; } public string Modelo { get; set; } public string Placa { get; set; } diff --git a/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs b/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs index 9eb30cf4..aad18a56 100644 --- a/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs +++ b/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs @@ -1,7 +1,10 @@ -namespace Wappa.Motoristas.API.Application.DTO +using System; + +namespace Wappa.Motoristas.API.Application.DTO { public class EnderecoDTO { + public Guid Id { get; set; } public string Logradouro { get; set; } public string Numero { get; set; } public string Complemento { get; set; } From ae556a7076376fa3cd75b202b25a042d1ff60943 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:41:06 -0300 Subject: [PATCH 24/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20criado=20o=20m=C3=A9otodo=20para=20mapear=20o?= =?UTF-8?q?=20comando=20adicionar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdicionarMotoristaCommandExtension.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/services/Wappa.Motorista.API/Application/Extensions/AdicionarMotoristaCommandExtension.cs diff --git a/src/services/Wappa.Motorista.API/Application/Extensions/AdicionarMotoristaCommandExtension.cs b/src/services/Wappa.Motorista.API/Application/Extensions/AdicionarMotoristaCommandExtension.cs new file mode 100644 index 00000000..021f21c7 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Application/Extensions/AdicionarMotoristaCommandExtension.cs @@ -0,0 +1,31 @@ +using Wappa.Motoristas.API.Application.Commands; +using Wappa.Motoristas.API.Models; + +namespace Wappa.Motoristas.API.Application.Extensions +{ + public static class AdicionarMotoristaCommandExtension + { + public static Motorista MapearMotorista(this AdicionarMotoristaCommand message) + { + var endereco = new Endereco + { + Logradouro = message.Endereco.Logradouro, + Numero = message.Endereco.Numero, + Complemento = message.Endereco.Complemento, + Bairro = message.Endereco.Bairro, + Cep = message.Endereco.Cep, + Cidade = message.Endereco.Cidade, + Estado = message.Endereco.Estado + }; + + var carro = new Carro(message.Carro.Marca, message.Carro.Modelo, message.Carro.Placa); + + var motorista = new Motorista(message.Nome, message.SobreNome); + + motorista.Carro = carro; + motorista.Endereco = endereco; + + return motorista; + } + } +} From 9d3062156c3957ed9531c3479b7db7d9260b445b Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:41:51 -0300 Subject: [PATCH 25/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20criado=20a=20classe=20est=C3=A1tica=20para=20us?= =?UTF-8?q?ar=20o=20m=C3=A9todo=20de=20extens=C3=A3o=20que=20mapea=20o=20c?= =?UTF-8?q?omando=20atualizar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AtualizarMotoristaCommandExtension.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/services/Wappa.Motorista.API/Application/Extensions/AtualizarMotoristaCommandExtension.cs diff --git a/src/services/Wappa.Motorista.API/Application/Extensions/AtualizarMotoristaCommandExtension.cs b/src/services/Wappa.Motorista.API/Application/Extensions/AtualizarMotoristaCommandExtension.cs new file mode 100644 index 00000000..3cf6c599 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Application/Extensions/AtualizarMotoristaCommandExtension.cs @@ -0,0 +1,28 @@ +using Wappa.Motoristas.API.Application.Commands; +using Wappa.Motoristas.API.Models; + +namespace Wappa.Motoristas.API.Application.Extensions +{ + public static class AtualizarMotoristaCommandExtension + { + public static Motorista MapearMotorista(this AtualizarMotoristaCommand message, Motorista motorista) + { + motorista.Carro.Marca = message.Carro.Marca; + motorista.Carro.Modelo = message.Carro.Modelo; + motorista.Carro.Placa = message.Carro.Placa; + + motorista.Endereco.Logradouro = message.Endereco.Logradouro; + motorista.Endereco.Numero = message.Endereco.Numero; + motorista.Endereco.Complemento = message.Endereco.Complemento; + motorista.Endereco.Bairro = message.Endereco.Bairro; + motorista.Endereco.Cep = message.Endereco.Cep; + motorista.Endereco.Cidade = message.Endereco.Cidade; + motorista.Endereco.Estado = message.Endereco.Estado; + + motorista.Nome = message.Nome; + motorista.SobreNome = message.SobreNome; + + return motorista; + } + } +} From 2bd420a4d321bbc94477b4559e7b27139f8f8ab4 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:42:07 -0300 Subject: [PATCH 26/83] feature/TAR-1-Criar-API-Motorista #comment - Foi adicionado o comando atualizar ao DI --- .../Configuration/DependencyInjectionConfig.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs index 69724a07..c558350e 100644 --- a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs +++ b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs @@ -15,6 +15,7 @@ public static void RegisterServices(this IServiceCollection services) { // Commands services.AddScoped, MotoristaCommandHandler>(); + services.AddScoped, MotoristaCommandHandler>(); // Application services.AddScoped(); From f7e2d0a8f0b42d681a0f5462f0ac8844e2606dc6 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:42:49 -0300 Subject: [PATCH 27/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20criado=20criado=20o=20m=C3=A9todo=20buscar=20mo?= =?UTF-8?q?torista=20por=20ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/Repository/MotoristaRepository.cs | 12 +++++++++++- .../Models/IMotoristaRepository.cs | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs b/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs index 2b716ddb..6f761f43 100644 --- a/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs +++ b/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Wappa.Core.Data; @@ -38,9 +39,18 @@ public void Deletar(Motorista motorista) _context.Motorista.Remove(motorista); } + public Task ObterPorId(Guid id) + { + return _context.Motorista + .Include(d => d.Carro) + .Include(f=>f.Endereco) + .FirstOrDefaultAsync(f => f.Id == id); + } + public void Dispose() { _context.Dispose(); } + } } \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs b/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs index e303058a..2bbc70bd 100644 --- a/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs +++ b/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; using Wappa.Core.Data; @@ -10,6 +11,7 @@ public interface IMotoristaRepository : IRepository void Atualizar(Motorista motorista); void Deletar(Motorista motorista); + Task ObterPorId(Guid id); Task> ObterTodos(); } } \ No newline at end of file From d3b896e4c3055d345baa23bfc982960260ae09d5 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:43:12 -0300 Subject: [PATCH 28/83] feature/TAR-1-Criar-API-Motorista #comment - Foi ajuste modificadores --- src/services/Wappa.Motorista.API/Models/Carro.cs | 8 ++++---- src/services/Wappa.Motorista.API/Models/Motorista.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/services/Wappa.Motorista.API/Models/Carro.cs b/src/services/Wappa.Motorista.API/Models/Carro.cs index 2d859b26..5df38728 100644 --- a/src/services/Wappa.Motorista.API/Models/Carro.cs +++ b/src/services/Wappa.Motorista.API/Models/Carro.cs @@ -5,11 +5,11 @@ namespace Wappa.Motoristas.API.Models { public class Carro: Entity { - public string Marca { get; private set; } - public string Modelo { get; private set; } - public string Placa { get; private set; } + public string Marca { get; set; } + public string Modelo { get; set; } + public string Placa { get; set; } - public Guid MotoristaId { get; private set; } + public Guid MotoristaId { get; set; } // EF Relation public Motorista Motorista { get; protected set; } diff --git a/src/services/Wappa.Motorista.API/Models/Motorista.cs b/src/services/Wappa.Motorista.API/Models/Motorista.cs index 3fe01d5a..620b34a6 100644 --- a/src/services/Wappa.Motorista.API/Models/Motorista.cs +++ b/src/services/Wappa.Motorista.API/Models/Motorista.cs @@ -5,8 +5,8 @@ namespace Wappa.Motoristas.API.Models { public class Motorista: Entity, IAggregateRoot { - public string Nome { get; private set; } - public string SobreNome { get; private set; } + public string Nome { get; set; } + public string SobreNome { get; set; } public Carro Carro { get; set; } public Endereco Endereco { get; set; } From fe4a493acda4d97bf7aa8bb3bc1885c0afdab594 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:55:50 -0300 Subject: [PATCH 29/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o comando deletar --- .../Commands/DeletarMotoristaCommand.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/services/Wappa.Motorista.API/Application/Commands/DeletarMotoristaCommand.cs diff --git a/src/services/Wappa.Motorista.API/Application/Commands/DeletarMotoristaCommand.cs b/src/services/Wappa.Motorista.API/Application/Commands/DeletarMotoristaCommand.cs new file mode 100644 index 00000000..56633e3a --- /dev/null +++ b/src/services/Wappa.Motorista.API/Application/Commands/DeletarMotoristaCommand.cs @@ -0,0 +1,27 @@ +using FluentValidation; +using Wappa.Core.Messages; +using System; + +namespace Wappa.Motoristas.API.Application.Commands +{ + public class DeletarMotoristaCommand : Command + { + // Motorista + public Guid Id { get; set; } + public override bool EhValido() + { + ValidationResult = new DeletarMotoristaValidation().Validate(this); + return ValidationResult.IsValid; + } + + public class DeletarMotoristaValidation : AbstractValidator + { + public DeletarMotoristaValidation() + { + RuleFor(c => c.Id) + .NotEqual(Guid.Empty) + .WithMessage("Id do motorista inválido"); + } + } + } +} \ No newline at end of file From 72a18d1c4544dd02f9e2f62531364ec4270c6c45 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:56:12 -0300 Subject: [PATCH 30/83] feature/TAR-1-Criar-API-Motorista #comment - FOi implementado o handler do comando deletar --- .../Commands/MotoristaCommandHandler.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/services/Wappa.Motorista.API/Application/Commands/MotoristaCommandHandler.cs b/src/services/Wappa.Motorista.API/Application/Commands/MotoristaCommandHandler.cs index 29dd294a..59cdecd9 100644 --- a/src/services/Wappa.Motorista.API/Application/Commands/MotoristaCommandHandler.cs +++ b/src/services/Wappa.Motorista.API/Application/Commands/MotoristaCommandHandler.cs @@ -1,8 +1,5 @@ using FluentValidation.Results; using MediatR; -using System; -using System.Collections.Generic; -using System.Linq; using System.Threading; using System.Threading.Tasks; using Wappa.Core.Messages; @@ -13,7 +10,8 @@ namespace Wappa.Motoristas.API.Application.Commands { public class MotoristaCommandHandler : CommandHandler, IRequestHandler, - IRequestHandler + IRequestHandler, + IRequestHandler { private readonly IMotoristaRepository _motoristaRepository; @@ -52,6 +50,21 @@ public async Task Handle(AtualizarMotoristaCommand message, Ca return await PersistirDados(_motoristaRepository.UnitOfWork); } - + public async Task Handle(DeletarMotoristaCommand message, CancellationToken cancellationToken) + { + if (!message.EhValido()) return message.ValidationResult; + + var motorista = await _motoristaRepository.ObterPorId(message.Id); + + if (motorista == null) + { + AdicionarErro("Motorista não foi encontrado"); + return ValidationResult; + } + + _motoristaRepository.Deletar(motorista); + + return await PersistirDados(_motoristaRepository.UnitOfWork); + } } } From 1ef1527a9e25a27246285d888e8daf839e3dcee9 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:56:22 -0300 Subject: [PATCH 31/83] feature/TAR-1-Criar-API-Motorista #comment - Foi configurado o DI --- .../Configuration/DependencyInjectionConfig.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs index c558350e..fa12954b 100644 --- a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs +++ b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs @@ -16,6 +16,7 @@ public static void RegisterServices(this IServiceCollection services) // Commands services.AddScoped, MotoristaCommandHandler>(); services.AddScoped, MotoristaCommandHandler>(); + services.AddScoped, MotoristaCommandHandler>(); // Application services.AddScoped(); From 4ed50c37eb1a84c09ee242e5a2964d6492756209 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:56:43 -0300 Subject: [PATCH 32/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o delete no controller --- .../Wappa.Motorista.API/Controllers/MotoristaController.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs index 45634b7a..5b837781 100644 --- a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs +++ b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs @@ -30,5 +30,11 @@ public async Task AtualizarMotorista(AtualizarMotoristaCommand mo { return CustomResponse(await _mediator.EnviarComando(motorista)); } + + [HttpDelete] + public async Task DeletarMotorista(DeletarMotoristaCommand motorista) + { + return CustomResponse(await _mediator.EnviarComando(motorista)); + } } } From 06ee89c9fa18e170ff8ceb798f967c59a8d00922 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 03:57:02 -0300 Subject: [PATCH 33/83] feature/TAR-1-Criar-API-Motorista #comment - Foi ignorado propriedade validationresult --- src/building blocks/Wappa.Core/Messages/Command.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/building blocks/Wappa.Core/Messages/Command.cs b/src/building blocks/Wappa.Core/Messages/Command.cs index 756e0f3e..679778e3 100644 --- a/src/building blocks/Wappa.Core/Messages/Command.cs +++ b/src/building blocks/Wappa.Core/Messages/Command.cs @@ -1,12 +1,14 @@ using FluentValidation.Results; using MediatR; using System; +using System.Text.Json.Serialization; namespace Wappa.Core.Messages { public abstract class Command : Message, IRequest { public DateTime TimeStamp { get; private set; } + [JsonIgnore] public ValidationResult ValidationResult { get; set; } protected Command() From 8cfeeb9cab771aa1ee73856f947adea4627e570c Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 20:43:44 -0300 Subject: [PATCH 34/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o dto de motoristas --- .../Application/DTO/CarroDTO.cs | 1 - .../Application/DTO/EnderecoDTO.cs | 1 - .../Application/DTO/MotoristaDTO.cs | 57 +++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/services/Wappa.Motorista.API/Application/DTO/MotoristaDTO.cs diff --git a/src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs b/src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs index 4453984c..7c9dd8ec 100644 --- a/src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs +++ b/src/services/Wappa.Motorista.API/Application/DTO/CarroDTO.cs @@ -4,7 +4,6 @@ namespace Wappa.Motoristas.API.Application.DTO { public class CarroDTO { - public Guid Id { get; set; } public string Marca { get; set; } public string Modelo { get; set; } public string Placa { get; set; } diff --git a/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs b/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs index aad18a56..c187f235 100644 --- a/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs +++ b/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs @@ -4,7 +4,6 @@ namespace Wappa.Motoristas.API.Application.DTO { public class EnderecoDTO { - public Guid Id { get; set; } public string Logradouro { get; set; } public string Numero { get; set; } public string Complemento { get; set; } diff --git a/src/services/Wappa.Motorista.API/Application/DTO/MotoristaDTO.cs b/src/services/Wappa.Motorista.API/Application/DTO/MotoristaDTO.cs new file mode 100644 index 00000000..7dda8944 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Application/DTO/MotoristaDTO.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Wappa.Motoristas.API.Models; + +namespace Wappa.Motoristas.API.Application.DTO +{ + public class MotoristaDTO + { + public Guid Id { get; set; } + public string Nome { get; set; } + public string SobreNome { get; set; } + + public EnderecoDTO Endereco { get; set; } + public CarroDTO Carro { get; set; } + + public static List ParaMotoristaDTO(dynamic motoristas) + { + var listaDeMotoristas = new List(); + + foreach (var motorista in motoristas) + { + var motoristaDTO = new MotoristaDTO + { + Id = Guid.Parse(Convert.ToString(motorista.ID)), + Nome = motorista.NOME, + SobreNome = motorista.SOBRENOME, + Carro = new CarroDTO(), + Endereco = new EnderecoDTO() + }; + + motoristaDTO.Endereco = new EnderecoDTO + { + Logradouro = motorista.LOGRADOURO, + Numero = motorista.NUMERO, + Complemento = motorista.COMPLEMENTO, + Bairro = motorista.BAIRRO, + Cep = motorista.CEP, + Cidade = motorista.CIDADE, + Estado = motorista.ESTADO, + }; + + motoristaDTO.Carro = new CarroDTO + { + Marca = motorista.MARCA, + Modelo = motorista.MODELO, + Placa = motorista.PLACA + }; + + listaDeMotoristas.Add(motoristaDTO); + + } + return listaDeMotoristas; + } + } +} From a288d519d0f476cd49d52c14a88fed1d69f66be1 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 20:44:10 -0300 Subject: [PATCH 35/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado a querie para buscar motoristas ordenado por nome --- .../Application/Queries/MotoristaQueries.cs | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/services/Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs diff --git a/src/services/Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs b/src/services/Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs new file mode 100644 index 00000000..0b83c1f1 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Dapper; +using Wappa.Motoristas.API.Application.DTO; +using Wappa.Motoristas.API.Models; + +namespace NSE.Pedidos.API.Application.Queries +{ + public interface IMotoristaQueries + { + Task> ObterListaMotoristas(); + } + + public class MotoristaQueries : IMotoristaQueries + { + #region Sql + const string _sql_Motoristas = @"SELECT + M.ID, + M.NOME, + M.SOBRENOME, + E.LOGRADOURO, + E.NUMERO, + E.BAIRRO, + E.CEP, + E.COMPLEMENTO, + E.CIDADE, + E.ESTADO, + C.MARCA, + C.MODELO, + C.PLACA + FROM + MOTORISTAS M + INNER JOIN + ENDERECOS E + ON E.MOTORISTAID = M.ID + INNER JOIN + CARROS C + ON C.MOTORISTAID = M.ID + ORDER BY M.NOME"; + #endregion + private readonly IMotoristaRepository _motoristaRepository; + + public MotoristaQueries(IMotoristaRepository motoristaRepository) + { + _motoristaRepository = motoristaRepository; + } + + public async Task> ObterListaMotoristas() + { + var motorista = await _motoristaRepository.ObterConexao() + .QueryAsync(_sql_Motoristas); + + return MotoristaDTO.ParaMotoristaDTO(motorista); + } + } +} \ No newline at end of file From b60d8c5111bbfa703dc90496a955954ad36b815d Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 20:44:26 -0300 Subject: [PATCH 36/83] feature/TAR-1-Criar-API-Motorista #comment - Foi adicionado a querie de motorista ao DI --- .../Configuration/DependencyInjectionConfig.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs index fa12954b..bfd57008 100644 --- a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs +++ b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs @@ -1,6 +1,7 @@ using FluentValidation.Results; using MediatR; using Microsoft.Extensions.DependencyInjection; +using NSE.Pedidos.API.Application.Queries; using Wappa.Core.Mediator; using Wappa.Motoristas.API.Application.Commands; using Wappa.Motoristas.API.Data; @@ -20,6 +21,7 @@ public static void RegisterServices(this IServiceCollection services) // Application services.AddScoped(); + services.AddScoped(); // Data services.AddScoped(); From dbaa31359a76aee42496991f62e026b8f18b597a Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 20:44:56 -0300 Subject: [PATCH 37/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20criado=20metodo=20para=20pegar=20a=20conex?= =?UTF-8?q?=C3=A3o=20do=20ef=20e=20passar=20para=20o=20dapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs b/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs index 6f761f43..d4d817e2 100644 --- a/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs +++ b/src/services/Wappa.Motorista.API/Data/Repository/MotoristaRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data.Common; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Wappa.Core.Data; @@ -17,6 +18,7 @@ public MotoristaRepository(MotoristaContext context) } public IUnitOfWork UnitOfWork => _context; + public DbConnection ObterConexao() => _context.Database.GetDbConnection(); public async Task> ObterTodos() { From 9fd406451534ea4ce8ba090117018ff3e7569d94 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 20:45:20 -0300 Subject: [PATCH 38/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Assinatura=20do=20metodo=20para=20pegar=20conex=C3=A3?= =?UTF-8?q?o=20do=20banco=20do=20ef=20e=20passar=20para=20o=20dapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wappa.Motorista.API/Models/IMotoristaRepository.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs b/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs index 2bbc70bd..812fec77 100644 --- a/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs +++ b/src/services/Wappa.Motorista.API/Models/IMotoristaRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data.Common; using System.Threading.Tasks; using Wappa.Core.Data; @@ -13,5 +14,7 @@ public interface IMotoristaRepository : IRepository Task ObterPorId(Guid id); Task> ObterTodos(); + + DbConnection ObterConexao(); } } \ No newline at end of file From 3bbe9d6db0c649d25442f0fa21345907df08c8e5 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 20:45:37 -0300 Subject: [PATCH 39/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o get para buscar os motoristas --- .../Controllers/MotoristaController.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs index 5b837781..9152d27d 100644 --- a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs +++ b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using NSE.Pedidos.API.Application.Queries; using System; using System.Collections.Generic; using System.Linq; @@ -13,10 +14,13 @@ namespace Wappa.Motoristas.API.Controllers public class MotoristaController : MainController { private readonly IMediatorHandler _mediator; + private readonly IMotoristaQueries _motoristaQueries; - public MotoristaController(IMediatorHandler mediator) + public MotoristaController(IMediatorHandler mediator, + IMotoristaQueries motoristaQueries) { _mediator = mediator; + _motoristaQueries = motoristaQueries; } [HttpPost] @@ -36,5 +40,13 @@ public async Task DeletarMotorista(DeletarMotoristaCommand motori { return CustomResponse(await _mediator.EnviarComando(motorista)); } + + [HttpGet] + public async Task ListarMotorista() + { + var motoristas = await _motoristaQueries.ObterListaMotoristas(); + + return motoristas == null ? NotFound() : CustomResponse(motoristas); + } } } From dd5d385b38dd78bda0f56c064329657b7f8987ed Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 20:45:53 -0300 Subject: [PATCH 40/83] feature/TAR-1-Criar-API-Motorista #comment - Foi adicionado o dapper ao projeto --- src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj index 7b5dd9fb..d005c6ec 100644 --- a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj +++ b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj @@ -9,6 +9,7 @@ + @@ -35,7 +36,6 @@ - From b083935aeeb1a6bd98bb6867107fea61edab929e Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 21:36:02 -0300 Subject: [PATCH 41/83] feature/TAR-1-Criar-API-Motorista #comment - Foi adicionado o pacote anotations do swagger para exibit os response --- src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj index d005c6ec..7ce01549 100644 --- a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj +++ b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj @@ -27,6 +27,7 @@ + From ec0b6519a0c79339f3ba56238ba780bfe9252187 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 21:36:45 -0300 Subject: [PATCH 42/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20configurado=20a=20aplica=C3=A7=C3=A3o=20para=20?= =?UTF-8?q?pegar=20coment=C3=A1rios=20da=20api=20a=20partir=20do=20xml=20g?= =?UTF-8?q?erado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wappa.Motorista.API/Configuration/SwaggerConfig.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/services/Wappa.Motorista.API/Configuration/SwaggerConfig.cs b/src/services/Wappa.Motorista.API/Configuration/SwaggerConfig.cs index 1106cba3..e1b59db2 100644 --- a/src/services/Wappa.Motorista.API/Configuration/SwaggerConfig.cs +++ b/src/services/Wappa.Motorista.API/Configuration/SwaggerConfig.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Reflection; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; @@ -11,13 +13,20 @@ public static void AddSwaggerConfiguration(this IServiceCollection services) { services.AddSwaggerGen(c => { + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + + c.IncludeXmlComments(xmlPath); c.SwaggerDoc("v1", new OpenApiInfo() { Title = "Wappa Challenge Dev Motorista API", Description = "Esta API faz controle o cadastro de motoristas.", Contact = new OpenApiContact() { Name = "Phillipe R Souza", Email = "phillrog@hotmail.com" }, + }); + c.EnableAnnotations(); + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "Insira o token JWT desta maneira: Bearer {seu token}", From 9a002443c9e8781ceea28952615bb6730a7a1834 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 21:37:02 -0300 Subject: [PATCH 43/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20colocado=20alguns=20coment=C3=A1rios=20para=20d?= =?UTF-8?q?ocumentar=20a=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/MotoristaController.cs | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs index 9152d27d..4c0957ff 100644 --- a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs +++ b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs @@ -1,15 +1,17 @@ using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; using NSE.Pedidos.API.Application.Queries; -using System; -using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using Wappa.Core.Mediator; using Wappa.Motoristas.API.Application.Commands; +using System.Net; +using FluentValidation.Results; +using Swashbuckle.AspNetCore.Annotations; namespace Wappa.Motoristas.API.Controllers { + /// + /// cadastro de motoristas + /// [Route("api/motorista")] public class MotoristaController : MainController { @@ -23,25 +25,53 @@ public MotoristaController(IMediatorHandler mediator, _motoristaQueries = motoristaQueries; } + /// + /// Adiciona um novo motorista ao sistema + /// + /// Dados do motoristas + /// Retorna um 200 ou 400 [HttpPost] + [SwaggerResponse((int)HttpStatusCode.OK, Description = "Retorna quando sucesso.")] + [SwaggerResponse((int)HttpStatusCode.BadRequest, Description = "Retorna quando ocorre alguma falha.")] public async Task AdicionarMotorista(AdicionarMotoristaCommand motorista) { return CustomResponse(await _mediator.EnviarComando(motorista)); } + /// + /// Atualiza os dados de um motorista cadastrado no sistema + /// + /// Dados do motoristas + /// Retorna um 200 ou 400 [HttpPut] + [SwaggerResponse((int)HttpStatusCode.OK, Description = "Retorna quando sucesso.")] + [SwaggerResponse((int)HttpStatusCode.BadRequest, Description = "Retorna quando ocorre alguma falha.")] public async Task AtualizarMotorista(AtualizarMotoristaCommand motorista) { return CustomResponse(await _mediator.EnviarComando(motorista)); } + /// + /// Deleta o cadastro do motorista do sistema + /// + /// Dados do motoristas + /// Retorna um 200 ou 400 [HttpDelete] + [SwaggerResponse((int)HttpStatusCode.OK, Description = "Retorna quando sucesso.", Type = typeof(ValidationResult))] + [SwaggerResponse((int)HttpStatusCode.BadRequest, Description = "Retorna quando ocorre alguma falha.", Type = typeof(ValidationResult))] public async Task DeletarMotorista(DeletarMotoristaCommand motorista) { return CustomResponse(await _mediator.EnviarComando(motorista)); } + /// + /// Busca todos os motoristas cadastrados no sistema + /// + /// Retorna um 200 ou 400 ou 404 [HttpGet] + [SwaggerResponse((int)HttpStatusCode.OK, Description = "Retorna quando sucesso.")] + [SwaggerResponse((int)HttpStatusCode.BadRequest, Description = "Retorna quando ocorre alguma falha.")] + [SwaggerResponse((int)HttpStatusCode.NotFound, Description = "Retorna quando ocorre alguma falha.")] public async Task ListarMotorista() { var motoristas = await _motoristaQueries.ObterListaMotoristas(); From 7c59630dcce9ebd3eb89eb43e4a3fca126a14867 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 22:01:08 -0300 Subject: [PATCH 44/83] feature/TAR-1-Criar-API-Motorista #comment - Ajuste --- .../Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs | 2 +- .../Configuration/DependencyInjectionConfig.cs | 2 +- .../Wappa.Motorista.API/Controllers/MotoristaController.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs b/src/services/Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs index 0b83c1f1..017b013a 100644 --- a/src/services/Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs +++ b/src/services/Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs @@ -6,7 +6,7 @@ using Wappa.Motoristas.API.Application.DTO; using Wappa.Motoristas.API.Models; -namespace NSE.Pedidos.API.Application.Queries +namespace Wappa.Motoristas.API.Application.Queries { public interface IMotoristaQueries { diff --git a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs index bfd57008..16621cbd 100644 --- a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs +++ b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs @@ -1,9 +1,9 @@ using FluentValidation.Results; using MediatR; using Microsoft.Extensions.DependencyInjection; -using NSE.Pedidos.API.Application.Queries; using Wappa.Core.Mediator; using Wappa.Motoristas.API.Application.Commands; +using Wappa.Motoristas.API.Application.Queries; using Wappa.Motoristas.API.Data; using Wappa.Motoristas.API.Data.Repository; using Wappa.Motoristas.API.Models; diff --git a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs index 4c0957ff..24ce69e4 100644 --- a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs +++ b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs @@ -1,11 +1,11 @@ using Microsoft.AspNetCore.Mvc; -using NSE.Pedidos.API.Application.Queries; using System.Threading.Tasks; using Wappa.Core.Mediator; using Wappa.Motoristas.API.Application.Commands; using System.Net; using FluentValidation.Results; using Swashbuckle.AspNetCore.Annotations; +using Wappa.Motoristas.API.Application.Queries; namespace Wappa.Motoristas.API.Controllers { From a3bfc9666211ab3d8b8e6a590f4963b5ea105120 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 23:19:45 -0300 Subject: [PATCH 45/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Cria=C3=A7=C3=A3o=20da=20api=20de=20coordenada=20geog?= =?UTF-8?q?rafica?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++ Wappa.sln | 12 ++++- .../CoordenadaGeograficaController.cs | 11 ++++ .../Dockerfile | 22 ++++++++ .../Program.cs | 26 ++++++++++ .../Properties/launchSettings.json | 37 ++++++++++++++ .../Startup.cs | 51 +++++++++++++++++++ .../Wappa.CoordenadasGeograficas.API.csproj | 15 ++++++ ...ppa.CoordenadasGeograficas.API.csproj.user | 6 +++ .../appsettings.Development.json | 9 ++++ .../appsettings.json | 10 ++++ 11 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Controllers/CoordenadaGeograficaController.cs create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Dockerfile create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Program.cs create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Properties/launchSettings.json create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Startup.cs create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj.user create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/appsettings.json diff --git a/.gitignore b/.gitignore index b2152dfd..8dfc4ebb 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,7 @@ /src/services/Wappa.Motoristas.API/obj/Docker /src/building blocks/Wappa.MessageBus/obj /src/building blocks/Wappa.MessageBus/bin/Debug/netcoreapp3.1 +/src/services/Wappa.Geolocalizacao.API/bin/Debug/netcoreapp3.1 +/src/services/Wappa.Geolocalizacao.API/obj +/src/services/Wappa.CoordenadasGeograficas.API/bin/Debug/netcoreapp3.1 +/src/services/Wappa.CoordenadasGeograficas.API/obj diff --git a/Wappa.sln b/Wappa.sln index 791e88da..c73822b8 100644 --- a/Wappa.sln +++ b/Wappa.sln @@ -19,7 +19,11 @@ Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-co EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MessageBus", "MessageBus", "{C94A4B68-ABAF-4566-8E42-3D603870A4F2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wappa.MessageBus", "src\building blocks\Wappa.MessageBus\Wappa.MessageBus.csproj", "{D4975541-0CC6-493B-90B2-AB3757D2A1B2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wappa.MessageBus", "src\building blocks\Wappa.MessageBus\Wappa.MessageBus.csproj", "{D4975541-0CC6-493B-90B2-AB3757D2A1B2}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Geolocalizacao", "Geolocalizacao", "{951C0702-1109-463A-8FB3-276221ADB711}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wappa.CoordenadasGeograficas.API", "src\services\Wappa.CoordenadasGeograficas.API\Wappa.CoordenadasGeograficas.API.csproj", "{B6B9227F-7CBE-426E-90C6-53D015B86357}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -43,6 +47,10 @@ Global {D4975541-0CC6-493B-90B2-AB3757D2A1B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {D4975541-0CC6-493B-90B2-AB3757D2A1B2}.Release|Any CPU.ActiveCfg = Release|Any CPU {D4975541-0CC6-493B-90B2-AB3757D2A1B2}.Release|Any CPU.Build.0 = Release|Any CPU + {B6B9227F-7CBE-426E-90C6-53D015B86357}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B6B9227F-7CBE-426E-90C6-53D015B86357}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B6B9227F-7CBE-426E-90C6-53D015B86357}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B6B9227F-7CBE-426E-90C6-53D015B86357}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -54,6 +62,8 @@ Global {9AB883F8-6E98-41BF-87A0-F7AA0B0F3C60} = {545ADEF2-79F6-4825-97A7-AD34D64A94EC} {C94A4B68-ABAF-4566-8E42-3D603870A4F2} = {DC4A0A94-B314-410C-803D-95E4A3F5C0FA} {D4975541-0CC6-493B-90B2-AB3757D2A1B2} = {C94A4B68-ABAF-4566-8E42-3D603870A4F2} + {951C0702-1109-463A-8FB3-276221ADB711} = {D7CC5A53-341D-41FD-9A24-0BD3C5569258} + {B6B9227F-7CBE-426E-90C6-53D015B86357} = {951C0702-1109-463A-8FB3-276221ADB711} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1ABF1BAA-6091-41E7-93DE-3428D39E26BC} diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Controllers/CoordenadaGeograficaController.cs b/src/services/Wappa.CoordenadasGeograficas.API/Controllers/CoordenadaGeograficaController.cs new file mode 100644 index 00000000..66ee20b7 --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Controllers/CoordenadaGeograficaController.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Wappa.CoordenadasGeograficas.API.Controllers +{ + [ApiController] + [Route("[controller]")] + public class CoordenadaGeograficaController : ControllerBase + { + + } +} diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Dockerfile b/src/services/Wappa.CoordenadasGeograficas.API/Dockerfile new file mode 100644 index 00000000..8050b09d --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Dockerfile @@ -0,0 +1,22 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build +WORKDIR /src +COPY ["src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj", "src/services/Wappa.CoordenadasGeograficas.API/"] +RUN dotnet restore "src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj" +COPY . . +WORKDIR "/src/src/services/Wappa.CoordenadasGeograficas.API" +RUN dotnet build "Wappa.CoordenadasGeograficas.API.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "Wappa.CoordenadasGeograficas.API.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Wappa.CoordenadasGeograficas.API.dll"] \ No newline at end of file diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Program.cs b/src/services/Wappa.CoordenadasGeograficas.API/Program.cs new file mode 100644 index 00000000..cba3f716 --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Program.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Wappa.CoordenadasGeograficas.API +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Properties/launchSettings.json b/src/services/Wappa.CoordenadasGeograficas.API/Properties/launchSettings.json new file mode 100644 index 00000000..025f15f3 --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Properties/launchSettings.json @@ -0,0 +1,37 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:52127", + "sslPort": 44381 + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Wappa.CoordenadasGeograficas.API": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000" + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast", + "publishAllPorts": true, + "useSSL": true + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs b/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs new file mode 100644 index 00000000..e1768772 --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs @@ -0,0 +1,51 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Wappa.CoordenadasGeograficas.API +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj b/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj new file mode 100644 index 00000000..e6047fa2 --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + 0a6d6e79-de6b-4994-9749-aeaa7f18fc1b + Linux + ..\..\.. + + + + + + + + diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj.user b/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj.user new file mode 100644 index 00000000..e681dafe --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj.user @@ -0,0 +1,6 @@ + + + + Docker + + \ No newline at end of file diff --git a/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json b/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/src/services/Wappa.CoordenadasGeograficas.API/appsettings.json b/src/services/Wappa.CoordenadasGeograficas.API/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} From 6bf9185e1b8724c1f603d1c29c355968483479c6 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Tue, 9 Mar 2021 23:58:50 -0300 Subject: [PATCH 46/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Refatora=C3=A7=C3=A3o=20para=20reutilizar=20maincontr?= =?UTF-8?q?oller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/MainController.cs | 83 +++++++++++++++++++ .../Wappa.WebAPI.Core.csproj | 15 ++++ 2 files changed, 98 insertions(+) create mode 100644 src/building blocks/Wappa.WebAPI.Core/Controllers/MainController.cs create mode 100644 src/building blocks/Wappa.WebAPI.Core/Wappa.WebAPI.Core.csproj diff --git a/src/building blocks/Wappa.WebAPI.Core/Controllers/MainController.cs b/src/building blocks/Wappa.WebAPI.Core/Controllers/MainController.cs new file mode 100644 index 00000000..790bbf23 --- /dev/null +++ b/src/building blocks/Wappa.WebAPI.Core/Controllers/MainController.cs @@ -0,0 +1,83 @@ +using FluentValidation.Results; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ModelBinding; +using System.Collections.Generic; +using System.Linq; +using Wappa.Core.Communication; + +namespace Wappa.WebAPI.Core.Controllers +{ + [ApiController] + public abstract class MainController : ControllerBase + { + protected ICollection Erros = new List(); + + protected ActionResult CustomResponse(object result = null) + { + if (OperacaoValida()) + { + return Ok(result); + } + + return BadRequest(new ValidationProblemDetails(new Dictionary + { + { "Mensagens", Erros.ToArray() } + })); + } + + protected ActionResult CustomResponse(ModelStateDictionary modelState) + { + var erros = modelState.Values.SelectMany(e => e.Errors); + foreach (var erro in erros) + { + AdicionarErroProcessamento(erro.ErrorMessage); + } + + return CustomResponse(); + } + + protected ActionResult CustomResponse(ValidationResult validationResult) + { + foreach (var erro in validationResult.Errors) + { + AdicionarErroProcessamento(erro.ErrorMessage); + } + + return CustomResponse(); + } + + protected ActionResult CustomResponse(ResponseResult resposta) + { + ResponsePossuiErros(resposta); + + return CustomResponse(); + } + + protected bool ResponsePossuiErros(ResponseResult resposta) + { + if (resposta == null || !resposta.Errors.Mensagens.Any()) return false; + + foreach (var mensagem in resposta.Errors.Mensagens) + { + AdicionarErroProcessamento(mensagem); + } + + return true; + } + + protected bool OperacaoValida() + { + return !Erros.Any(); + } + + protected void AdicionarErroProcessamento(string erro) + { + Erros.Add(erro); + } + + protected void LimparErrosProcessamento() + { + Erros.Clear(); + } + } +} diff --git a/src/building blocks/Wappa.WebAPI.Core/Wappa.WebAPI.Core.csproj b/src/building blocks/Wappa.WebAPI.Core/Wappa.WebAPI.Core.csproj new file mode 100644 index 00000000..94c25438 --- /dev/null +++ b/src/building blocks/Wappa.WebAPI.Core/Wappa.WebAPI.Core.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + + + + + + + + + + + From 7316548931796b38da8f9c29a1b2330effe0e60d Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 00:00:07 -0300 Subject: [PATCH 47/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Refatora=C3=A7=C3=A3o=20para=20reutilizar=20main=20co?= =?UTF-8?q?ntroller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/MainController.cs | 85 ------------------- .../Controllers/MotoristaController.cs | 2 + 2 files changed, 2 insertions(+), 85 deletions(-) delete mode 100644 src/services/Wappa.Motorista.API/Controllers/MainController.cs diff --git a/src/services/Wappa.Motorista.API/Controllers/MainController.cs b/src/services/Wappa.Motorista.API/Controllers/MainController.cs deleted file mode 100644 index 9ac86c45..00000000 --- a/src/services/Wappa.Motorista.API/Controllers/MainController.cs +++ /dev/null @@ -1,85 +0,0 @@ -using FluentValidation.Results; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Wappa.Core.Communication; - -namespace Wappa.Motoristas.API.Controllers -{ - [ApiController] - public abstract class MainController : Controller - { - protected ICollection Erros = new List(); - - protected ActionResult CustomResponse(object result = null) - { - if (OperacaoValida()) - { - return Ok(result); - } - - return BadRequest(new ValidationProblemDetails(new Dictionary - { - { "Mensagens", Erros.ToArray() } - })); - } - - protected ActionResult CustomResponse(ModelStateDictionary modelState) - { - var erros = modelState.Values.SelectMany(e => e.Errors); - foreach (var erro in erros) - { - AdicionarErroProcessamento(erro.ErrorMessage); - } - - return CustomResponse(); - } - - protected ActionResult CustomResponse(ValidationResult validationResult) - { - foreach (var erro in validationResult.Errors) - { - AdicionarErroProcessamento(erro.ErrorMessage); - } - - return CustomResponse(); - } - - protected ActionResult CustomResponse(ResponseResult resposta) - { - ResponsePossuiErros(resposta); - - return CustomResponse(); - } - - protected bool ResponsePossuiErros(ResponseResult resposta) - { - if (resposta == null || !resposta.Errors.Mensagens.Any()) return false; - - foreach (var mensagem in resposta.Errors.Mensagens) - { - AdicionarErroProcessamento(mensagem); - } - - return true; - } - - protected bool OperacaoValida() - { - return !Erros.Any(); - } - - protected void AdicionarErroProcessamento(string erro) - { - Erros.Add(erro); - } - - protected void LimparErrosProcessamento() - { - Erros.Clear(); - } - } -} diff --git a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs index 24ce69e4..f1e98a9d 100644 --- a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs +++ b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs @@ -6,6 +6,8 @@ using FluentValidation.Results; using Swashbuckle.AspNetCore.Annotations; using Wappa.Motoristas.API.Application.Queries; +using Wappa.Motoristas.API.Services; +using Wappa.WebAPI.Core.Controllers; namespace Wappa.Motoristas.API.Controllers { From ecce55c1cf34f893b500f71cabbb27da22fba140 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 00:00:55 -0300 Subject: [PATCH 48/83] feature/TAR-1-Criar-API-Motorista #comment - Foi dockerizado a API de coordeandas --- .gitignore | 2 + Wappa.sln | 12 ++- docker-compose.override.yml | 13 ++++ docker-compose.yml | 6 ++ .../Configuration/ApiConfig.cs | 44 +++++++++++ .../Configuration/SwaggerConfig.cs | 67 +++++++++++++++++ .../CoordenadaGeograficaController.cs | 27 ++++++- .../Dockerfile | 4 +- .../Models/Endereco.cs | 15 ++++ .../Properties/launchSettings.json | 31 ++++++-- .../Startup.cs | 75 +++++++++---------- .../Wappa.CoordenadasGeograficas.API.csproj | 16 +++- .../Wappa.Motoristas.API.csproj | 1 + 13 files changed, 258 insertions(+), 55 deletions(-) create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Configuration/ApiConfig.cs create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Configuration/SwaggerConfig.cs create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs diff --git a/.gitignore b/.gitignore index 8dfc4ebb..505cb0e6 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ /src/services/Wappa.Geolocalizacao.API/obj /src/services/Wappa.CoordenadasGeograficas.API/bin/Debug/netcoreapp3.1 /src/services/Wappa.CoordenadasGeograficas.API/obj +/src/building blocks/Wappa.WebAPI.Core/bin/Debug/netcoreapp3.1 +/src/building blocks/Wappa.WebAPI.Core/obj diff --git a/Wappa.sln b/Wappa.sln index c73822b8..fd81d85a 100644 --- a/Wappa.sln +++ b/Wappa.sln @@ -21,10 +21,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MessageBus", "MessageBus", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wappa.MessageBus", "src\building blocks\Wappa.MessageBus\Wappa.MessageBus.csproj", "{D4975541-0CC6-493B-90B2-AB3757D2A1B2}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Geolocalizacao", "Geolocalizacao", "{951C0702-1109-463A-8FB3-276221ADB711}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Coordenadas Geograficas", "Coordenadas Geograficas", "{951C0702-1109-463A-8FB3-276221ADB711}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wappa.CoordenadasGeograficas.API", "src\services\Wappa.CoordenadasGeograficas.API\Wappa.CoordenadasGeograficas.API.csproj", "{B6B9227F-7CBE-426E-90C6-53D015B86357}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{DC09A6A3-F2B1-48A3-B3ED-268E650A7EB0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wappa.WebAPI.Core", "src\building blocks\Wappa.WebAPI.Core\Wappa.WebAPI.Core.csproj", "{8155999B-3EB8-44D2-BA43-86C97F42AE38}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +55,10 @@ Global {B6B9227F-7CBE-426E-90C6-53D015B86357}.Debug|Any CPU.Build.0 = Debug|Any CPU {B6B9227F-7CBE-426E-90C6-53D015B86357}.Release|Any CPU.ActiveCfg = Release|Any CPU {B6B9227F-7CBE-426E-90C6-53D015B86357}.Release|Any CPU.Build.0 = Release|Any CPU + {8155999B-3EB8-44D2-BA43-86C97F42AE38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8155999B-3EB8-44D2-BA43-86C97F42AE38}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8155999B-3EB8-44D2-BA43-86C97F42AE38}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8155999B-3EB8-44D2-BA43-86C97F42AE38}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -64,6 +72,8 @@ Global {D4975541-0CC6-493B-90B2-AB3757D2A1B2} = {C94A4B68-ABAF-4566-8E42-3D603870A4F2} {951C0702-1109-463A-8FB3-276221ADB711} = {D7CC5A53-341D-41FD-9A24-0BD3C5569258} {B6B9227F-7CBE-426E-90C6-53D015B86357} = {951C0702-1109-463A-8FB3-276221ADB711} + {DC09A6A3-F2B1-48A3-B3ED-268E650A7EB0} = {DC4A0A94-B314-410C-803D-95E4A3F5C0FA} + {8155999B-3EB8-44D2-BA43-86C97F42AE38} = {DC09A6A3-F2B1-48A3-B3ED-268E650A7EB0} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1ABF1BAA-6091-41E7-93DE-3428D39E26BC} diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 57392a0a..2e101b74 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -53,6 +53,19 @@ services: networks: - local + wappa.coordenadasgeograficas.api: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=https://+:5002;http://+:4002 + ports: + - "4002:4002" + - "5002:5002" + volumes: + - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro + - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro + networks: + - local + networks: local: driver: bridge diff --git a/docker-compose.yml b/docker-compose.yml index 6dbdefd6..bb66042f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,3 +15,9 @@ services: build: context: . dockerfile: src/services/Wappa.Motorista.API/Dockerfile + + wappa.coordenadasgeograficas.api: + image: ${DOCKER_REGISTRY-}coordenadasgeograficasapi + build: + context: . + dockerfile: src/services/Wappa.CoordenadasGeograficas.API/Dockerfile \ No newline at end of file diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Configuration/ApiConfig.cs b/src/services/Wappa.CoordenadasGeograficas.API/Configuration/ApiConfig.cs new file mode 100644 index 00000000..34cd73d4 --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Configuration/ApiConfig.cs @@ -0,0 +1,44 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + + +namespace Wappa.CoordenadasGeograficas.API.Configuration +{ + public static class ApiConfig + { + public static void AddApiConfiguration(this IServiceCollection services, IConfiguration configuration) + { + services.AddControllers(); + + services.AddCors(options => + { + options.AddPolicy("Total", + builder => + builder + .AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader()); + }); + } + + public static void UseApiConfiguration(this IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseCors("Total"); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Configuration/SwaggerConfig.cs b/src/services/Wappa.CoordenadasGeograficas.API/Configuration/SwaggerConfig.cs new file mode 100644 index 00000000..1fd95a0a --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Configuration/SwaggerConfig.cs @@ -0,0 +1,67 @@ +using System; +using System.IO; +using System.Reflection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.OpenApi.Models; + +namespace Wappa.CoordenadasGeograficas.API.Configuration +{ + public static class SwaggerConfig + { + public static void AddSwaggerConfiguration(this IServiceCollection services) + { + services.AddSwaggerGen(c => + { + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + + c.IncludeXmlComments(xmlPath); + c.SwaggerDoc("v1", new OpenApiInfo() + { + Title = "Wappa Coordenadas Geográficas API", + Description = "Esta API faz a consulta de do endereõ do motorista e retorna sua coordenada geográfica.", + Contact = new OpenApiContact() { Name = "Phillipe R Souza", Email = "phillrog@hotmail.com" }, + + }); + + c.EnableAnnotations(); + + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + Description = "Insira o token JWT desta maneira: Bearer {seu token}", + Name = "Authorization", + Scheme = "Bearer", + BearerFormat = "JWT", + In = ParameterLocation.Header, + Type = SecuritySchemeType.ApiKey + }); + + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + new string[] {} + } + }); + + }); + } + + public static void UseSwaggerConfiguration(this IApplicationBuilder app) + { + app.UseSwagger(); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); + }); + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Controllers/CoordenadaGeograficaController.cs b/src/services/Wappa.CoordenadasGeograficas.API/Controllers/CoordenadaGeograficaController.cs index 66ee20b7..61117b8a 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Controllers/CoordenadaGeograficaController.cs +++ b/src/services/Wappa.CoordenadasGeograficas.API/Controllers/CoordenadaGeograficaController.cs @@ -1,11 +1,30 @@ using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; +using System.Net; +using System.Threading.Tasks; +using Wappa.CoordenadasGeograficas.API.Models; +using Wappa.WebAPI.Core.Controllers; namespace Wappa.CoordenadasGeograficas.API.Controllers { - [ApiController] - [Route("[controller]")] - public class CoordenadaGeograficaController : ControllerBase + /// + /// API para consultar coordenadas geográficas + /// + [Route("api/geocoordenada")] + public class CoordenadaGeograficaController : MainController { - + /// + /// Busca coordenada geográfica de um endereço + /// + /// Dados do endereço + /// 200 ou 400 ou 404 + [HttpGet] + [SwaggerResponse((int)HttpStatusCode.OK, Description = "Retorna quando sucesso.")] + [SwaggerResponse((int)HttpStatusCode.BadRequest, Description = "Retorna quando ocorre alguma falha.")] + [SwaggerResponse((int)HttpStatusCode.NotFound, Description = "Retorna quando ocorre alguma falha.")] + public async Task BuscarCoordenadaPorEndereco(Endereco endereco) + { + return Ok(); + } } } diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Dockerfile b/src/services/Wappa.CoordenadasGeograficas.API/Dockerfile index 8050b09d..c7a32fab 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Dockerfile +++ b/src/services/Wappa.CoordenadasGeograficas.API/Dockerfile @@ -2,8 +2,8 @@ FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base WORKDIR /app -EXPOSE 80 -EXPOSE 443 +EXPOSE 4002 +EXPOSE 5002 FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build WORKDIR /src diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs b/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs new file mode 100644 index 00000000..83fa977f --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs @@ -0,0 +1,15 @@ +using System; + +namespace Wappa.CoordenadasGeograficas.API.Models +{ + public class Endereco + { + public string Logradouro { get; set; } + public string Numero { get; set; } + public string Complemento { get; set; } + public string Bairro { get; set; } + public string Cep { get; set; } + public string Cidade { get; set; } + public string Estado { get; set; } + } +} \ No newline at end of file diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Properties/launchSettings.json b/src/services/Wappa.CoordenadasGeograficas.API/Properties/launchSettings.json index 025f15f3..a52f1d55 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Properties/launchSettings.json +++ b/src/services/Wappa.CoordenadasGeograficas.API/Properties/launchSettings.json @@ -9,27 +9,46 @@ }, "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { - "IIS Express": { + "IIS Development": { "commandName": "IISExpress", "launchBrowser": true, - "launchUrl": "weatherforecast", + "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, - "Wappa.CoordenadasGeograficas.API": { + "IIS Staging": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Staging" + } + }, + "IIS Production": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Production" + } + }, + "SelfHosting - Development": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "weatherforecast", + "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "https://localhost:5001;http://localhost:5000" + "applicationUrl": "https://localhost:5002;http://localhost:4002" }, "Docker": { "commandName": "Docker", "launchBrowser": true, - "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast", + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, "publishAllPorts": true, "useSSL": true } diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs b/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs index e1768772..bd44f738 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs +++ b/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs @@ -1,51 +1,44 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using Wappa.CoordenadasGeograficas.API.Configuration; namespace Wappa.CoordenadasGeograficas.API { public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddControllers(); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - - app.UseHttpsRedirection(); - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - } - } + { + public IConfiguration Configuration { get; } + + public Startup(IHostEnvironment hostEnvironment) + { + var builder = new ConfigurationBuilder() + .SetBasePath(hostEnvironment.ContentRootPath) + .AddJsonFile("appsettings.json", true, true) + .AddJsonFile($"appsettings.{hostEnvironment.EnvironmentName}.json", true, true) + .AddEnvironmentVariables(); + + if (hostEnvironment.IsDevelopment()) + { + builder.AddUserSecrets(); + } + + Configuration = builder.Build(); + } + + public void ConfigureServices(IServiceCollection services) + { + services.AddApiConfiguration(Configuration); + + services.AddSwaggerConfiguration(); + } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + app.UseSwaggerConfiguration(); + + app.UseApiConfiguration(env); + } + } } diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj b/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj index e6047fa2..5c94f9f8 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj +++ b/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj @@ -7,8 +7,22 @@ ..\..\.. + + bin\Debug\netcoreapp3.1\Wappa.CoordenadasGeograficas.API.xml + bin\Debug\netcoreapp3.1\ + 1701;1702;1591 + + + + + + + + + + - + diff --git a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj index 7ce01549..d3d615be 100644 --- a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj +++ b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj @@ -33,6 +33,7 @@ + From 6ee0bc7c492f11f56c62bcb7137382dcbc15d482 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 00:58:57 -0300 Subject: [PATCH 49/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Corre=C3=A7=C3=A3o=20namespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wappa.Motorista.API/Controllers/MotoristaController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs index f1e98a9d..c671255c 100644 --- a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs +++ b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs @@ -6,7 +6,6 @@ using FluentValidation.Results; using Swashbuckle.AspNetCore.Annotations; using Wappa.Motoristas.API.Application.Queries; -using Wappa.Motoristas.API.Services; using Wappa.WebAPI.Core.Controllers; namespace Wappa.Motoristas.API.Controllers From 5b1f977d4d4711f136e55543a6960484bf696f7e Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 00:59:27 -0300 Subject: [PATCH 50/83] feature/TAR-1-Criar-API-Motorista - Foi criado o modelo endereco --- .../Models/Endereco.cs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs b/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs index 83fa977f..8b75cb54 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs +++ b/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs @@ -2,14 +2,19 @@ namespace Wappa.CoordenadasGeograficas.API.Models { - public class Endereco - { - public string Logradouro { get; set; } - public string Numero { get; set; } - public string Complemento { get; set; } - public string Bairro { get; set; } - public string Cep { get; set; } - public string Cidade { get; set; } - public string Estado { get; set; } - } + public class Endereco + { + public string Logradouro { get; set; } + public string Numero { get; set; } + public string Complemento { get; set; } + public string Bairro { get; set; } + public string Cep { get; set; } + public string Cidade { get; set; } + public string Estado { get; set; } + + public string Consultar() + { + return string.Join(Logradouro, "+", Numero, "+", Complemento, "+", Bairro, "+", Cep, "+", Cidade, "+", Estado); + } + } } \ No newline at end of file From c20e4a7c23306b29514db7d61c2cadfa7b9f83ac Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 00:59:51 -0300 Subject: [PATCH 51/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o modelo coordenada --- .../Models/Coordenadas.cs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Models/Coordenadas.cs diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Models/Coordenadas.cs b/src/services/Wappa.CoordenadasGeograficas.API/Models/Coordenadas.cs new file mode 100644 index 00000000..7def8402 --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Models/Coordenadas.cs @@ -0,0 +1,8 @@ +namespace Wappa.CoordenadasGeograficas.API.Models +{ + public class Coordenadas + { + public decimal Longitude { get; set; } + public decimal Latitude { get; set; } + } +} From 75587b0a93d3ae1a604179c6c057690c1037b8e7 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 01:13:25 -0300 Subject: [PATCH 52/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20criado=20um=20appsettings=20para=20guardar=20in?= =?UTF-8?q?forma=C3=A7=C3=B5es=20da=20consulta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/building blocks/Wappa.Core/Extensions/AppSettings.cs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/building blocks/Wappa.Core/Extensions/AppSettings.cs diff --git a/src/building blocks/Wappa.Core/Extensions/AppSettings.cs b/src/building blocks/Wappa.Core/Extensions/AppSettings.cs new file mode 100644 index 00000000..e0fb101a --- /dev/null +++ b/src/building blocks/Wappa.Core/Extensions/AppSettings.cs @@ -0,0 +1,8 @@ +namespace Wappa.Core.Extensions +{ + public class AppSettings + { + public string GoogleGeocodingUrl { get; set; } + public string GoogleAPiKey { get; set; } + } +} From 4042a506bf4f0dbe68a933415ede4add94f2d284 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 01:14:15 -0300 Subject: [PATCH 53/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20criado=20o=20servi=C3=A7o=20para=20consultar=20?= =?UTF-8?q?as=20coordeandas=20do=20endere=C3=A7o=20com=20a=20api=20do=20go?= =?UTF-8?q?ogle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/GoogleGeocondingService.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Services/GoogleGeocondingService.cs diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Services/GoogleGeocondingService.cs b/src/services/Wappa.CoordenadasGeograficas.API/Services/GoogleGeocondingService.cs new file mode 100644 index 00000000..9f9d2e7c --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Services/GoogleGeocondingService.cs @@ -0,0 +1,55 @@ +using Microsoft.Extensions.Options; +using Newtonsoft.Json; +using System; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using Wappa.CoordenadasGeograficas.API.Models; +using Wappa.Core.Extensions; + +namespace Wappa.CoordenadasGeograficas.API.Services +{ + public interface IGoogleGeocondingService + { + public Task BuscarCoordenadas(Endereco endereco); + } + + public class GoogleGeocondingService : IGoogleGeocondingService + { + private readonly HttpClient _httpClient; + private readonly string _key; + + public GoogleGeocondingService(HttpClient httpClient, + IOptions settings) + { + _httpClient = httpClient; + _httpClient.BaseAddress = new Uri(settings.Value.GoogleGeocodingUrl); + _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + _key = settings.Value.GoogleAPiKey; + } + + public async Task BuscarCoordenadas(Endereco endereco) + { + var response = await _httpClient.GetAsync($"?address={endereco.Consultar()}&key={_key}"); + var coordeandas = new Coordenadas(); + + if (response.IsSuccessStatusCode) + { + string result = response.Content.ReadAsStringAsync().Result; + + var data = JsonConvert.DeserializeObject(result); + + foreach (var item in data.results) + { + coordeandas.Latitude = (decimal)(item.geometry.location.lat); + coordeandas.Longitude = (decimal)(item.geometry.location.lng); + + if (coordeandas.EhValido()) + break; + } + } + + return coordeandas; + } + } +} From ccb7b5f4482cdfbf0e402bca51460a55e4ed95c1 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 01:14:38 -0300 Subject: [PATCH 54/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20criado=20o=20m=C3=A9todo=20e=20injetado=20o=20s?= =?UTF-8?q?ervi=C3=A7o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CoordenadaGeograficaController.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Controllers/CoordenadaGeograficaController.cs b/src/services/Wappa.CoordenadasGeograficas.API/Controllers/CoordenadaGeograficaController.cs index 61117b8a..23eca6af 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Controllers/CoordenadaGeograficaController.cs +++ b/src/services/Wappa.CoordenadasGeograficas.API/Controllers/CoordenadaGeograficaController.cs @@ -3,6 +3,7 @@ using System.Net; using System.Threading.Tasks; using Wappa.CoordenadasGeograficas.API.Models; +using Wappa.CoordenadasGeograficas.API.Services; using Wappa.WebAPI.Core.Controllers; namespace Wappa.CoordenadasGeograficas.API.Controllers @@ -13,18 +14,25 @@ namespace Wappa.CoordenadasGeograficas.API.Controllers [Route("api/geocoordenada")] public class CoordenadaGeograficaController : MainController { + private readonly IGoogleGeocondingService _googleGeocondingService; + + public CoordenadaGeograficaController(IGoogleGeocondingService googleGeocondingService) + { + _googleGeocondingService = googleGeocondingService; + } + /// /// Busca coordenada geográfica de um endereço /// /// Dados do endereço /// 200 ou 400 ou 404 - [HttpGet] + [HttpPost] [SwaggerResponse((int)HttpStatusCode.OK, Description = "Retorna quando sucesso.")] [SwaggerResponse((int)HttpStatusCode.BadRequest, Description = "Retorna quando ocorre alguma falha.")] [SwaggerResponse((int)HttpStatusCode.NotFound, Description = "Retorna quando ocorre alguma falha.")] public async Task BuscarCoordenadaPorEndereco(Endereco endereco) { - return Ok(); + return CustomResponse(await _googleGeocondingService.BuscarCoordenadas(endereco)); } } } From 558bf015df5d53d8501276838dab907e55ca0fa4 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 01:15:16 -0300 Subject: [PATCH 55/83] feature/TAR-1-Criar-API-Motorista #comment - Foi setado o config --- .../DependencyInjectionConfig.cs | 43 +++++++++++++++++++ .../Models/Coordenadas.cs | 7 ++- .../Startup.cs | 5 +++ .../Wappa.CoordenadasGeograficas.API.csproj | 3 +- .../appsettings.Development.json | 4 +- 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Configuration/DependencyInjectionConfig.cs diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Configuration/DependencyInjectionConfig.cs b/src/services/Wappa.CoordenadasGeograficas.API/Configuration/DependencyInjectionConfig.cs new file mode 100644 index 00000000..03127f71 --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Configuration/DependencyInjectionConfig.cs @@ -0,0 +1,43 @@ +using Microsoft.Extensions.DependencyInjection; +using Polly; +using Polly.Extensions.Http; +using Polly.Retry; +using System; +using System.Net.Http; +using Wappa.CoordenadasGeograficas.API.Services; + +namespace Wappa.CoordenadasGeograficas.API.Configuration +{ + public static class DependencyInjectionConfig + { + public static void RegisterServices(this IServiceCollection services) + { + services.AddHttpClient() + .AddPolicyHandler(PollyExtensions.EsperarTentar()) + .AddTransientHttpErrorPolicy( + p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); + } + } + + public class PollyExtensions + { + public static AsyncRetryPolicy EsperarTentar() + { + var retry = HttpPolicyExtensions + .HandleTransientHttpError() + .WaitAndRetryAsync(new[] + { + TimeSpan.FromSeconds(1), + TimeSpan.FromSeconds(5), + TimeSpan.FromSeconds(10), + }, (outcome, timespan, retryCount, context) => + { + Console.ForegroundColor = ConsoleColor.Blue; + Console.WriteLine($"Tentando pela {retryCount} vez!"); + Console.ForegroundColor = ConsoleColor.White; + }); + + return retry; + } + } +} \ No newline at end of file diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Models/Coordenadas.cs b/src/services/Wappa.CoordenadasGeograficas.API/Models/Coordenadas.cs index 7def8402..abc0d287 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Models/Coordenadas.cs +++ b/src/services/Wappa.CoordenadasGeograficas.API/Models/Coordenadas.cs @@ -3,6 +3,11 @@ public class Coordenadas { public decimal Longitude { get; set; } - public decimal Latitude { get; set; } + public decimal Latitude { get; set; } + + public bool EhValido() + { + return Longitude != 0 && Latitude != 0; + } } } diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs b/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs index bd44f738..56c14a6c 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs +++ b/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Wappa.CoordenadasGeograficas.API.Configuration; +using Wappa.Core.Extensions; namespace Wappa.CoordenadasGeograficas.API { @@ -32,6 +33,10 @@ public void ConfigureServices(IServiceCollection services) services.AddApiConfiguration(Configuration); services.AddSwaggerConfiguration(); + + services.RegisterServices(); + + services.Configure(Configuration); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj b/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj index 5c94f9f8..65dd901e 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj +++ b/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 @@ -17,6 +17,7 @@ + diff --git a/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json b/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json index 8983e0fc..928aaaa8 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json +++ b/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json @@ -5,5 +5,7 @@ "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } - } + }, + "GoogleGeocodingUrl": "https://maps.googleapis.com/maps/api/geocode/json?", + "GoogleAPiKey": "" } From c7e110fc9e6993e3cabab3ba80d9c6dcf85c8f20 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 02:30:08 -0300 Subject: [PATCH 56/83] feature/TAR-1-Criar-API-Motorista #comment - Foi adicionado o config do rabbit --- .../appsettings.Development.json | 5 ++++- .../Wappa.Motorista.API/appsettings.Development.json | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json b/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json index 928aaaa8..e1368247 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json +++ b/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json @@ -7,5 +7,8 @@ } }, "GoogleGeocodingUrl": "https://maps.googleapis.com/maps/api/geocode/json?", - "GoogleAPiKey": "" + "GoogleAPiKey": "", + "MessageQueueConnection": { + "MessageBus": "host=rabbit:5672;publisherConfirms=true;timeout=10" + } } diff --git a/src/services/Wappa.Motorista.API/appsettings.Development.json b/src/services/Wappa.Motorista.API/appsettings.Development.json index 187cc577..a27611d5 100644 --- a/src/services/Wappa.Motorista.API/appsettings.Development.json +++ b/src/services/Wappa.Motorista.API/appsettings.Development.json @@ -15,5 +15,8 @@ "ConnectionStrings": { "Container": "Server=banco_sql,1433;Database=WappaDev; User=sa; Password=yourStrong(!)Password;Trusted_Connection=False;MultipleActiveResultSets=true", "Localhost": "Server=localhost,1435;Database=WappaDev; User=sa; Password=yourStrong(!)Password;Trusted_Connection=False;MultipleActiveResultSets=true" + }, + "MessageQueueConnection": { + "MessageBus": "host=rabbit:5672;publisherConfirms=true;timeout=10" } } From a2c16ecae252afa7a0e7136552fd68198ccfa491 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 02:31:40 -0300 Subject: [PATCH 57/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o eventhandler para buscar coordeanda --- .../Application/Events/CoordenadaEventHandler.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Application/Events/CoordenadaEventHandler.cs diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Application/Events/CoordenadaEventHandler.cs b/src/services/Wappa.CoordenadasGeograficas.API/Application/Events/CoordenadaEventHandler.cs new file mode 100644 index 00000000..0633012f --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Application/Events/CoordenadaEventHandler.cs @@ -0,0 +1,14 @@ +using MediatR; +using System.Threading; +using System.Threading.Tasks; + +namespace Wappa.CoordenadasGeograficas.API.Application.Events +{ + public class CoordenadaEventHandler : INotificationHandler + { + public Task Handle(SolicitouCadastroMotoristaEvent notification, CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + } +} From df3c5a5a976713f71f337fb66e550e46b97ee8a5 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 02:32:47 -0300 Subject: [PATCH 58/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20criado=20o=20evento=20que=20transmitira=20o=20e?= =?UTF-8?q?ndere=C3=A7o=20para=20consultar=20no=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Events/SolicitouCadastroMotoristaEvent.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Application/Events/SolicitouCadastroMotoristaEvent.cs diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Application/Events/SolicitouCadastroMotoristaEvent.cs b/src/services/Wappa.CoordenadasGeograficas.API/Application/Events/SolicitouCadastroMotoristaEvent.cs new file mode 100644 index 00000000..2ccf0e81 --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Application/Events/SolicitouCadastroMotoristaEvent.cs @@ -0,0 +1,10 @@ +using Wappa.CoordenadasGeograficas.API.Models; +using Wappa.Core.Messages; + +namespace Wappa.CoordenadasGeograficas.API.Application.Events +{ + public class SolicitouCadastroMotoristaEvent : Event + { + public Endereco Endereco { get; set; } + } +} From d2782d7dae199f8fcbef173ee9d23edd13d1b5a3 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 02:33:34 -0300 Subject: [PATCH 59/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20criado=20o=20evento=20de=20integra=C3=A7=C3=A3o?= =?UTF-8?q?=20para=20solicitar=20coordenada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...icitouCadastroMotoristaIntegrationEvent.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/building blocks/Wappa.Core/Messages/Integration/SolicitouCadastroMotoristaIntegrationEvent.cs diff --git a/src/building blocks/Wappa.Core/Messages/Integration/SolicitouCadastroMotoristaIntegrationEvent.cs b/src/building blocks/Wappa.Core/Messages/Integration/SolicitouCadastroMotoristaIntegrationEvent.cs new file mode 100644 index 00000000..0f012306 --- /dev/null +++ b/src/building blocks/Wappa.Core/Messages/Integration/SolicitouCadastroMotoristaIntegrationEvent.cs @@ -0,0 +1,56 @@ +using FluentValidation; +using FluentValidation.Results; + +namespace Wappa.Core.Messages.Integration +{ + public class SolicitouCadastroMotoristaIntegrationEvent : IntegrationEvent + { + public SolicitouCadastroMotoristaIntegrationEvent(string logradouro, string numero, string complemento, string bairro, string cep, string cidade, string estado) + { + Logradouro = logradouro; + Numero = numero; + Complemento = complemento; + Bairro = bairro; + Cep = cep; + Cidade = cidade; + Estado = estado; + } + + public string Logradouro { get; set; } + public string Numero { get; set; } + public string Complemento { get; set; } + public string Bairro { get; set; } + public string Cep { get; set; } + public string Cidade { get; set; } + public string Estado { get; set; } + + public ValidationResult ValidationResult { get; protected set; } + + public bool EhValido() + { + var erros = new SolicitouCadastroMotoristaIntegrationEventValidation().Validate(this).Errors; + + ValidationResult = new ValidationResult(erros); + + return ValidationResult.IsValid; + } + + public class SolicitouCadastroMotoristaIntegrationEventValidation : AbstractValidator + { + public SolicitouCadastroMotoristaIntegrationEventValidation() + { + RuleFor(c => c.Logradouro) + .NotNull() + .WithMessage("Informe o logradouro"); + + RuleFor(c => c.Cidade) + .NotNull() + .WithMessage("Informe a cidade"); + + RuleFor(c => c.Estado) + .NotNull() + .WithMessage("Informe o estado"); + } + } + } +} From 97b3c9cb56491c994233f2543146d6316ec2f3f1 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 02:34:05 -0300 Subject: [PATCH 60/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20M=C3=A9todo=20de=20extens=C3=A3o=20para=20pegar=20o?= =?UTF-8?q?=20config=20connectionstring=20do=20rabbit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wappa.Core/Utils/ConfigurationExtensions.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/building blocks/Wappa.Core/Utils/ConfigurationExtensions.cs diff --git a/src/building blocks/Wappa.Core/Utils/ConfigurationExtensions.cs b/src/building blocks/Wappa.Core/Utils/ConfigurationExtensions.cs new file mode 100644 index 00000000..45d122e0 --- /dev/null +++ b/src/building blocks/Wappa.Core/Utils/ConfigurationExtensions.cs @@ -0,0 +1,12 @@ +using Microsoft.Extensions.Configuration; + +namespace Wappa.Core.Utils +{ + public static class ConfigurationExtensions + { + public static string GetMessageQueueConnection(this IConfiguration configuration, string name) + { + return configuration?.GetSection("MessageQueueConnection")?[name]; + } + } +} From f4fb9c0a815f25c896acedb0ea36d7b4ca1d389b Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 02:34:55 -0300 Subject: [PATCH 61/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o config messagebus setando o handler --- .../Wappa.Core/Wappa.Core.csproj | 1 + .../Configuration/MessageBusConfig.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Configuration/MessageBusConfig.cs diff --git a/src/building blocks/Wappa.Core/Wappa.Core.csproj b/src/building blocks/Wappa.Core/Wappa.Core.csproj index 822a4959..c41a7514 100644 --- a/src/building blocks/Wappa.Core/Wappa.Core.csproj +++ b/src/building blocks/Wappa.Core/Wappa.Core.csproj @@ -7,6 +7,7 @@ + diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Configuration/MessageBusConfig.cs b/src/services/Wappa.CoordenadasGeograficas.API/Configuration/MessageBusConfig.cs new file mode 100644 index 00000000..176e7991 --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Configuration/MessageBusConfig.cs @@ -0,0 +1,18 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Wappa.CoordenadasGeograficas.API.Services; +using Wappa.Core.Utils; +using Wappa.MessageBus; + +namespace Wappa.CoordenadasGeograficas.API.Configuration +{ + public static class MessageBusConfig + { + public static void AddMessageBusConfiguration(this IServiceCollection services, + IConfiguration configuration) + { + services.AddMessageBus(configuration.GetMessageQueueConnection("MessageBus")) + .AddHostedService(); + } + } +} \ No newline at end of file From c972ac8063cef737324e7b34de9456689983acc7 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 02:38:01 -0300 Subject: [PATCH 62/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o handler para assinar o respond --- .../Services/CoordenadasIntegrationHandler.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/services/Wappa.CoordenadasGeograficas.API/Services/CoordenadasIntegrationHandler.cs diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Services/CoordenadasIntegrationHandler.cs b/src/services/Wappa.CoordenadasGeograficas.API/Services/CoordenadasIntegrationHandler.cs new file mode 100644 index 00000000..0caae6f8 --- /dev/null +++ b/src/services/Wappa.CoordenadasGeograficas.API/Services/CoordenadasIntegrationHandler.cs @@ -0,0 +1,36 @@ +using Microsoft.Extensions.Hosting; +using System; +using System.Threading; +using System.Threading.Tasks; +using Wappa.Core.Messages.Integration; +using Wappa.MessageBus; + +namespace Wappa.CoordenadasGeograficas.API.Services +{ + public class CoordenadasIntegrationHandler : BackgroundService + { + private readonly IMessageBus _bus; + + public CoordenadasIntegrationHandler(IMessageBus bus, IServiceProvider serviceProvider) + { + _bus = bus; + } + + private void SetResponder() + { + _bus.RespondAsync(async request => + await ConsultarCoordenada(request)); + } + + private Task ConsultarCoordenada(SolicitouCadastroMotoristaIntegrationEvent request) + { + return Task.FromResult(new ResponseMessage(null)); + } + + protected override Task ExecuteAsync(CancellationToken stoppingToken) + { + SetResponder(); + return Task.CompletedTask; + } + } +} From afb509e0b3525a7930ad6e4081a9af52dee5ee7c Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 02:38:16 -0300 Subject: [PATCH 63/83] feature/TAR-1-Criar-API-Motorista #comment - Foi adicionado o config messagebus --- src/services/Wappa.CoordenadasGeograficas.API/Startup.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs b/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs index 56c14a6c..78215000 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs +++ b/src/services/Wappa.CoordenadasGeograficas.API/Startup.cs @@ -32,10 +32,12 @@ public void ConfigureServices(IServiceCollection services) { services.AddApiConfiguration(Configuration); - services.AddSwaggerConfiguration(); + services.AddSwaggerConfiguration(); services.RegisterServices(); + services.AddMessageBusConfiguration(Configuration); + services.Configure(Configuration); } From d4ac8978a8db76994b808a98e774b27f03c1433f Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 02:38:58 -0300 Subject: [PATCH 64/83] feature/TAR-1-Criar-API-Motorista #comment - Configurado DI --- .../Wappa.CoordenadasGeograficas.API.csproj | 1 + .../Configuration/DependencyInjectionConfig.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj b/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj index 65dd901e..e4f3aa69 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj +++ b/src/services/Wappa.CoordenadasGeograficas.API/Wappa.CoordenadasGeograficas.API.csproj @@ -23,6 +23,7 @@ + diff --git a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs index 16621cbd..ea8e0d34 100644 --- a/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs +++ b/src/services/Wappa.Motorista.API/Configuration/DependencyInjectionConfig.cs @@ -19,6 +19,8 @@ public static void RegisterServices(this IServiceCollection services) services.AddScoped, MotoristaCommandHandler>(); services.AddScoped, MotoristaCommandHandler>(); + services.AddScoped(); + // Application services.AddScoped(); services.AddScoped(); From f663f48a0b936fe64896f1c7fc119fe0a90f2939 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 02:39:12 -0300 Subject: [PATCH 65/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Configurado=20conex=C3=A3o=20com=20rabbit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Configuration/MessageBusConfig.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/services/Wappa.Motorista.API/Configuration/MessageBusConfig.cs diff --git a/src/services/Wappa.Motorista.API/Configuration/MessageBusConfig.cs b/src/services/Wappa.Motorista.API/Configuration/MessageBusConfig.cs new file mode 100644 index 00000000..889ec5db --- /dev/null +++ b/src/services/Wappa.Motorista.API/Configuration/MessageBusConfig.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Wappa.Core.Utils; +using Wappa.MessageBus; + +namespace Wappa.Motoristas.API.Configuration +{ + public static class MessageBusConfig + { + public static void AddMessageBusConfiguration(this IServiceCollection services, IConfiguration configuration) + { + services.AddMessageBus(configuration.GetMessageQueueConnection("MessageBus")); + } + } +} From 05f9b81221901842234498aa79af6ea226200a08 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 02:39:54 -0300 Subject: [PATCH 66/83] feature/TAR-1-Criar-API-Motorista #comment - Foi implementado o envio do evento para consultar coordenada --- .../Controllers/MotoristaController.cs | 20 ++++++++++++++++++- src/services/Wappa.Motorista.API/Startup.cs | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs index c671255c..b5ce3b5a 100644 --- a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs +++ b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs @@ -7,6 +7,8 @@ using Swashbuckle.AspNetCore.Annotations; using Wappa.Motoristas.API.Application.Queries; using Wappa.WebAPI.Core.Controllers; +using Wappa.MessageBus; +using Wappa.Core.Messages.Integration; namespace Wappa.Motoristas.API.Controllers { @@ -18,12 +20,15 @@ public class MotoristaController : MainController { private readonly IMediatorHandler _mediator; private readonly IMotoristaQueries _motoristaQueries; + private readonly IMessageBus _bus; public MotoristaController(IMediatorHandler mediator, - IMotoristaQueries motoristaQueries) + IMotoristaQueries motoristaQueries, + IMessageBus bus) { _mediator = mediator; _motoristaQueries = motoristaQueries; + _bus = bus; } /// @@ -36,6 +41,19 @@ public MotoristaController(IMediatorHandler mediator, [SwaggerResponse((int)HttpStatusCode.BadRequest, Description = "Retorna quando ocorre alguma falha.")] public async Task AdicionarMotorista(AdicionarMotoristaCommand motorista) { + var solicitacaoCoordenadaEvent = new SolicitouCadastroMotoristaIntegrationEvent(motorista.Endereco.Logradouro, + motorista.Endereco.Numero, + motorista.Endereco.Complemento, + motorista.Endereco.Bairro, + motorista.Endereco.Cep, + motorista.Endereco.Cidade, + motorista.Endereco.Estado); + + if (!solicitacaoCoordenadaEvent.EhValido()) + return CustomResponse(solicitacaoCoordenadaEvent.ValidationResult); + + var coordeandas = await _bus.RequestAsync(solicitacaoCoordenadaEvent); + return CustomResponse(await _mediator.EnviarComando(motorista)); } diff --git a/src/services/Wappa.Motorista.API/Startup.cs b/src/services/Wappa.Motorista.API/Startup.cs index 32706d71..4a802e90 100644 --- a/src/services/Wappa.Motorista.API/Startup.cs +++ b/src/services/Wappa.Motorista.API/Startup.cs @@ -38,6 +38,8 @@ public void ConfigureServices(IServiceCollection services) services.AddMediatR(typeof(Startup)); services.RegisterServices(); + + services.AddMessageBusConfiguration(Configuration); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MotoristaContext motoristaContext) From 11a03edd2f292bc6610094058fa4ca1d79fe3a60 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 02:40:20 -0300 Subject: [PATCH 67/83] feature/TAR-1-Criar-API-Motorista #comment - Limpeza --- .../Wappa.Motorista.API/Models/Motorista.cs | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/services/Wappa.Motorista.API/Models/Motorista.cs b/src/services/Wappa.Motorista.API/Models/Motorista.cs index 620b34a6..502894ab 100644 --- a/src/services/Wappa.Motorista.API/Models/Motorista.cs +++ b/src/services/Wappa.Motorista.API/Models/Motorista.cs @@ -1,21 +1,22 @@ using Wappa.Core.DomainObjects; using System; +using FluentValidation; namespace Wappa.Motoristas.API.Models { - public class Motorista: Entity, IAggregateRoot - { - public string Nome { get; set; } - public string SobreNome { get; set; } - public Carro Carro { get; set; } - public Endereco Endereco { get; set; } + public class Motorista : Entity, IAggregateRoot + { + public string Nome { get; set; } + public string SobreNome { get; set; } + public Carro Carro { get; set; } + public Endereco Endereco { get; set; } - protected Motorista() { } + protected Motorista() { } - public Motorista(string nome, string sobreNome) - { - Nome = nome; - SobreNome = sobreNome; - } - } + public Motorista(string nome, string sobreNome) + { + Nome = nome; + SobreNome = sobreNome; + } + } } From a77f43efe4ae5d8fa4d2dc2b4bde1a61a82b6997 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 04:54:50 -0300 Subject: [PATCH 68/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20adicionado=20o=20dto=20de=20coordenadas=20ao=20?= =?UTF-8?q?endere=C3=A7o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Application/Commands/AdicionarMotoristaCommand.cs | 3 ++- .../Application/Commands/AtualizarMotoristaCommand.cs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/services/Wappa.Motorista.API/Application/Commands/AdicionarMotoristaCommand.cs b/src/services/Wappa.Motorista.API/Application/Commands/AdicionarMotoristaCommand.cs index 4c7c21b8..30f0700f 100644 --- a/src/services/Wappa.Motorista.API/Application/Commands/AdicionarMotoristaCommand.cs +++ b/src/services/Wappa.Motorista.API/Application/Commands/AdicionarMotoristaCommand.cs @@ -3,6 +3,7 @@ using System; using Wappa.Motoristas.API.Application.DTO; using Wappa.Motoristas.API.Models; +using System.Text.Json.Serialization; namespace Wappa.Motoristas.API.Application.Commands { @@ -17,7 +18,7 @@ public class AdicionarMotoristaCommand : Command // Endereco public EnderecoDTO Endereco { get; set; } - + public override bool EhValido() { ValidationResult = new AdicionarMotoristaValidation().Validate(this); diff --git a/src/services/Wappa.Motorista.API/Application/Commands/AtualizarMotoristaCommand.cs b/src/services/Wappa.Motorista.API/Application/Commands/AtualizarMotoristaCommand.cs index 384ccf58..00f3cc87 100644 --- a/src/services/Wappa.Motorista.API/Application/Commands/AtualizarMotoristaCommand.cs +++ b/src/services/Wappa.Motorista.API/Application/Commands/AtualizarMotoristaCommand.cs @@ -2,6 +2,7 @@ using Wappa.Core.Messages; using System; using Wappa.Motoristas.API.Application.DTO; +using System.Text.Json.Serialization; namespace Wappa.Motoristas.API.Application.Commands { From 96caae04c8b92a9735221ea4b26aaafcee3828c2 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 04:55:22 -0300 Subject: [PATCH 69/83] feature/TAR-1-Criar-API-Motorista #comment - Foi criado o dto de coordenadas --- .../Application/DTO/CoordenadasDTO.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/services/Wappa.Motorista.API/Application/DTO/CoordenadasDTO.cs diff --git a/src/services/Wappa.Motorista.API/Application/DTO/CoordenadasDTO.cs b/src/services/Wappa.Motorista.API/Application/DTO/CoordenadasDTO.cs new file mode 100644 index 00000000..9babd92c --- /dev/null +++ b/src/services/Wappa.Motorista.API/Application/DTO/CoordenadasDTO.cs @@ -0,0 +1,14 @@ +namespace Wappa.Motoristas.API.Application.DTO +{ + public class CoordenadasDTO + { + public CoordenadasDTO(decimal longitude, decimal latitude) + { + Longitude = longitude; + Latitude = latitude; + } + + public decimal Longitude { get; set; } + public decimal Latitude { get; set; } + } +} From e45ce86c44c16767e5443b34b02be1c5a17e1c1b Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 04:56:17 -0300 Subject: [PATCH 70/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20adicioando=20o=20dto=20de=20coordenadas=20ao=20?= =?UTF-8?q?endere=C3=A7o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs | 2 ++ .../Wappa.Motorista.API/Application/DTO/MotoristaDTO.cs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs b/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs index c187f235..b2abcbf6 100644 --- a/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs +++ b/src/services/Wappa.Motorista.API/Application/DTO/EnderecoDTO.cs @@ -1,4 +1,5 @@ using System; +using System.Text.Json.Serialization; namespace Wappa.Motoristas.API.Application.DTO { @@ -11,5 +12,6 @@ public class EnderecoDTO public string Cep { get; set; } public string Cidade { get; set; } public string Estado { get; set; } + public CoordenadasDTO Coordenadas { get; set; } } } \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Application/DTO/MotoristaDTO.cs b/src/services/Wappa.Motorista.API/Application/DTO/MotoristaDTO.cs index 7dda8944..0a5f1964 100644 --- a/src/services/Wappa.Motorista.API/Application/DTO/MotoristaDTO.cs +++ b/src/services/Wappa.Motorista.API/Application/DTO/MotoristaDTO.cs @@ -13,7 +13,7 @@ public class MotoristaDTO public string SobreNome { get; set; } public EnderecoDTO Endereco { get; set; } - public CarroDTO Carro { get; set; } + public CarroDTO Carro { get; set; } public static List ParaMotoristaDTO(dynamic motoristas) { @@ -39,6 +39,7 @@ public static List ParaMotoristaDTO(dynamic motoristas) Cep = motorista.CEP, Cidade = motorista.CIDADE, Estado = motorista.ESTADO, + Coordenadas = new CoordenadasDTO(motorista.LONGITUDE, motorista.LATITUDE) }; motoristaDTO.Carro = new CarroDTO From 49ed79beee164a4cc88bf24e6d3f7ad3ea312518 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 04:56:50 -0300 Subject: [PATCH 71/83] feature/TAR-1-Criar-API-Motorista #comment - Foi adicionado as coordenadas --- .../Extensions/AdicionarMotoristaCommandExtension.cs | 4 +++- .../Extensions/AtualizarMotoristaCommandExtension.cs | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/services/Wappa.Motorista.API/Application/Extensions/AdicionarMotoristaCommandExtension.cs b/src/services/Wappa.Motorista.API/Application/Extensions/AdicionarMotoristaCommandExtension.cs index 021f21c7..3a5fb572 100644 --- a/src/services/Wappa.Motorista.API/Application/Extensions/AdicionarMotoristaCommandExtension.cs +++ b/src/services/Wappa.Motorista.API/Application/Extensions/AdicionarMotoristaCommandExtension.cs @@ -15,7 +15,9 @@ public static Motorista MapearMotorista(this AdicionarMotoristaCommand message) Bairro = message.Endereco.Bairro, Cep = message.Endereco.Cep, Cidade = message.Endereco.Cidade, - Estado = message.Endereco.Estado + Estado = message.Endereco.Estado, + Latitude = message.Endereco.Coordenadas.Latitude, + Longitude = message.Endereco.Coordenadas.Longitude, }; var carro = new Carro(message.Carro.Marca, message.Carro.Modelo, message.Carro.Placa); diff --git a/src/services/Wappa.Motorista.API/Application/Extensions/AtualizarMotoristaCommandExtension.cs b/src/services/Wappa.Motorista.API/Application/Extensions/AtualizarMotoristaCommandExtension.cs index 3cf6c599..9dce2d32 100644 --- a/src/services/Wappa.Motorista.API/Application/Extensions/AtualizarMotoristaCommandExtension.cs +++ b/src/services/Wappa.Motorista.API/Application/Extensions/AtualizarMotoristaCommandExtension.cs @@ -19,6 +19,9 @@ public static Motorista MapearMotorista(this AtualizarMotoristaCommand message, motorista.Endereco.Cidade = message.Endereco.Cidade; motorista.Endereco.Estado = message.Endereco.Estado; + motorista.Endereco.Longitude = message.Endereco.Coordenadas.Longitude; + motorista.Endereco.Latitude = message.Endereco.Coordenadas.Latitude; + motorista.Nome = message.Nome; motorista.SobreNome = message.SobreNome; From eb2378af28b34fda4eabcfcbe14ebfbf465c131b Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 04:57:10 -0300 Subject: [PATCH 72/83] feature/TAR-1-Criar-API-Motorista #comment - Foi adicioando as colunas de coordenadas a query --- .../Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/services/Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs b/src/services/Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs index 017b013a..cf292fd8 100644 --- a/src/services/Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs +++ b/src/services/Wappa.Motorista.API/Application/Queries/MotoristaQueries.cs @@ -27,6 +27,8 @@ public class MotoristaQueries : IMotoristaQueries E.COMPLEMENTO, E.CIDADE, E.ESTADO, + E.LATITUDE, + E.LONGITUDE, C.MARCA, C.MODELO, C.PLACA From 82380ba2c906c2168aaca4dd1f810a3545d36afe Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 04:58:30 -0300 Subject: [PATCH 73/83] feature/TAR-1-Criar-API-Motorista #comment - Adicionado as coordenadas --- .../Wappa.Core/Messages/Integration/ResponseMessage.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/building blocks/Wappa.Core/Messages/Integration/ResponseMessage.cs b/src/building blocks/Wappa.Core/Messages/Integration/ResponseMessage.cs index 92812b0c..034d0a1a 100644 --- a/src/building blocks/Wappa.Core/Messages/Integration/ResponseMessage.cs +++ b/src/building blocks/Wappa.Core/Messages/Integration/ResponseMessage.cs @@ -5,10 +5,14 @@ namespace Wappa.Core.Messages.Integration public class ResponseMessage : Message { public ValidationResult ValidationResult { get; set; } + public decimal Longitude { get; set; } + public decimal Latitude { get; set; } - public ResponseMessage(ValidationResult validationResult) + public ResponseMessage(ValidationResult validationResult, decimal longitude, decimal latitude) { ValidationResult = validationResult; + Longitude = longitude; + Latitude = latitude; } } } From 199616a7d95cf1d52619068ffe04a051feefbbe3 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 04:58:47 -0300 Subject: [PATCH 74/83] feature/TAR-1-Criar-API-Motorista #comment - Criado construtor --- .../Models/Endereco.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs b/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs index 8b75cb54..816bbd2f 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs +++ b/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs @@ -4,6 +4,17 @@ namespace Wappa.CoordenadasGeograficas.API.Models { public class Endereco { + public Endereco(string logradouro, string numero, string complemento, string bairro, string cep, string cidade, string estado) + { + Logradouro = logradouro; + Numero = numero; + Complemento = complemento; + Bairro = bairro; + Cep = cep; + Cidade = cidade; + Estado = estado; + } + public string Logradouro { get; set; } public string Numero { get; set; } public string Complemento { get; set; } @@ -12,6 +23,7 @@ public class Endereco public string Cidade { get; set; } public string Estado { get; set; } + public string Consultar() { return string.Join(Logradouro, "+", Numero, "+", Complemento, "+", Bairro, "+", Cep, "+", Cidade, "+", Estado); From 1a41b6294b8c364274b3da17cf53ff53870182de Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 04:59:55 -0300 Subject: [PATCH 75/83] feature/TAR-1-Criar-API-Motorista #comment - Foi implementado o integration handler para consultar as coordenadas ao receber request --- .../Services/CoordenadasIntegrationHandler.cs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Services/CoordenadasIntegrationHandler.cs b/src/services/Wappa.CoordenadasGeograficas.API/Services/CoordenadasIntegrationHandler.cs index 0caae6f8..763dde1d 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Services/CoordenadasIntegrationHandler.cs +++ b/src/services/Wappa.CoordenadasGeograficas.API/Services/CoordenadasIntegrationHandler.cs @@ -1,7 +1,9 @@ -using Microsoft.Extensions.Hosting; +using FluentValidation.Results; +using Microsoft.Extensions.Hosting; using System; using System.Threading; using System.Threading.Tasks; +using Wappa.CoordenadasGeograficas.API.Models; using Wappa.Core.Messages.Integration; using Wappa.MessageBus; @@ -10,10 +12,12 @@ namespace Wappa.CoordenadasGeograficas.API.Services public class CoordenadasIntegrationHandler : BackgroundService { private readonly IMessageBus _bus; + private readonly IGoogleGeocondingService _googleGeocondingService; - public CoordenadasIntegrationHandler(IMessageBus bus, IServiceProvider serviceProvider) + public CoordenadasIntegrationHandler(IMessageBus bus, IGoogleGeocondingService googleGeocondingService) { - _bus = bus; + _bus = bus; + _googleGeocondingService = googleGeocondingService; } private void SetResponder() @@ -22,9 +26,21 @@ private void SetResponder() await ConsultarCoordenada(request)); } - private Task ConsultarCoordenada(SolicitouCadastroMotoristaIntegrationEvent request) + private async Task ConsultarCoordenada(SolicitouCadastroMotoristaIntegrationEvent request) { - return Task.FromResult(new ResponseMessage(null)); + var enderecoConsultar = new Endereco(request.Logradouro, + request.Numero, + request.Complemento, + request.Bairro, + request.Cep, + request.Cidade, + request.Estado); + + var result = await _googleGeocondingService.BuscarCoordenadas(enderecoConsultar); + + var coordenadaResponse = new ResponseMessage(new ValidationResult(), result.Longitude, result.Latitude); + + return coordenadaResponse; } protected override Task ExecuteAsync(CancellationToken stoppingToken) From c6d17c656b63351a4908b5b8fe0c64038f18de57 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 05:00:37 -0300 Subject: [PATCH 76/83] feature/TAR-1-Criar-API-Motorista #comment - Foi implementado a consulta das coordeandas ao adicionar e atualizar --- .../Controllers/MotoristaController.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs index b5ce3b5a..b46deb66 100644 --- a/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs +++ b/src/services/Wappa.Motorista.API/Controllers/MotoristaController.cs @@ -9,6 +9,7 @@ using Wappa.WebAPI.Core.Controllers; using Wappa.MessageBus; using Wappa.Core.Messages.Integration; +using Wappa.Motoristas.API.Application.DTO; namespace Wappa.Motoristas.API.Controllers { @@ -52,7 +53,9 @@ public async Task AdicionarMotorista(AdicionarMotoristaCommand mo if (!solicitacaoCoordenadaEvent.EhValido()) return CustomResponse(solicitacaoCoordenadaEvent.ValidationResult); - var coordeandas = await _bus.RequestAsync(solicitacaoCoordenadaEvent); + var coordenadas = await _bus.RequestAsync(solicitacaoCoordenadaEvent); + + motorista.Endereco.Coordenadas = new CoordenadasDTO(coordenadas.Longitude, coordenadas.Latitude); return CustomResponse(await _mediator.EnviarComando(motorista)); } @@ -67,6 +70,21 @@ public async Task AdicionarMotorista(AdicionarMotoristaCommand mo [SwaggerResponse((int)HttpStatusCode.BadRequest, Description = "Retorna quando ocorre alguma falha.")] public async Task AtualizarMotorista(AtualizarMotoristaCommand motorista) { + var solicitacaoCoordenadaEvent = new SolicitouCadastroMotoristaIntegrationEvent(motorista.Endereco.Logradouro, + motorista.Endereco.Numero, + motorista.Endereco.Complemento, + motorista.Endereco.Bairro, + motorista.Endereco.Cep, + motorista.Endereco.Cidade, + motorista.Endereco.Estado); + + if (!solicitacaoCoordenadaEvent.EhValido()) + return CustomResponse(solicitacaoCoordenadaEvent.ValidationResult); + + var coordenadas = await _bus.RequestAsync(solicitacaoCoordenadaEvent); + + motorista.Endereco.Coordenadas = new CoordenadasDTO(coordenadas.Longitude, coordenadas.Latitude); + return CustomResponse(await _mediator.EnviarComando(motorista)); } From 8db73b539b70ef036c4a9e54a7cc9bad63ddcadf Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 05:01:20 -0300 Subject: [PATCH 77/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Foi=20adicioando=20as=20coordenadas=20ao=20mapeamento?= =?UTF-8?q?=20da=20entidade=20endere=C3=A7o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/Mappings/EnderecoMapping.cs | 6 +++ .../Data/MotoristaContext.cs | 48 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/services/Wappa.Motorista.API/Data/MotoristaContext.cs diff --git a/src/services/Wappa.Motorista.API/Data/Mappings/EnderecoMapping.cs b/src/services/Wappa.Motorista.API/Data/Mappings/EnderecoMapping.cs index ff63ddc8..a5cd1fbf 100644 --- a/src/services/Wappa.Motorista.API/Data/Mappings/EnderecoMapping.cs +++ b/src/services/Wappa.Motorista.API/Data/Mappings/EnderecoMapping.cs @@ -37,6 +37,12 @@ public void Configure(EntityTypeBuilder builder) .IsRequired() .HasColumnType("varchar(50)"); + builder.Property(c => c.Longitude) + .HasColumnType("decimal(18)"); + + builder.Property(c => c.Latitude) + .HasColumnType("decimal(18)"); + builder.ToTable("Enderecos"); } } diff --git a/src/services/Wappa.Motorista.API/Data/MotoristaContext.cs b/src/services/Wappa.Motorista.API/Data/MotoristaContext.cs new file mode 100644 index 00000000..01d8b56d --- /dev/null +++ b/src/services/Wappa.Motorista.API/Data/MotoristaContext.cs @@ -0,0 +1,48 @@ +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Wappa.Motoristas.API.Models; +using Wappa.Core.Data; +using Wappa.Core.DomainObjects; +using FluentValidation.Results; + +namespace Wappa.Motoristas.API.Data +{ + public sealed class MotoristaContext : DbContext, IUnitOfWork + { + + public MotoristaContext(DbContextOptions options) + : base(options) + { + ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; + ChangeTracker.AutoDetectChangesEnabled = false; + } + + public DbSet Motorista { get; set; } + public DbSet Enderecos { get; set; } + public DbSet Carros { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Ignore(); + + foreach (var property in modelBuilder.Model.GetEntityTypes().SelectMany( + e => e.GetProperties().Where(p => p.ClrType == typeof(string)))) + property.SetColumnType("varchar(100)"); + + foreach (var relationship in modelBuilder.Model.GetEntityTypes() + .SelectMany(e => e.GetForeignKeys())) relationship.DeleteBehavior = DeleteBehavior.Cascade; + + modelBuilder.ApplyConfigurationsFromAssembly(typeof(MotoristaContext).Assembly); + + base.OnModelCreating(modelBuilder); + } + + public async Task Commit() + { + var sucesso = await base.SaveChangesAsync() > 0; + + return sucesso; + } + } +} \ No newline at end of file From acb682b7c3ffdcb3e3e646b04d448ab3512e3642 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 05:01:53 -0300 Subject: [PATCH 78/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Migrations=20das=20novas=20propriedades=20da=20entida?= =?UTF-8?q?de=20endere=C3=A7o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/MotoristsContext.cs | 48 ------ .../20210310071419_Coordenadas.Designer.cs | 142 ++++++++++++++++++ .../Migrations/20210310071419_Coordenadas.cs | 35 +++++ .../MotoristaContextModelSnapshot.cs | 6 + 4 files changed, 183 insertions(+), 48 deletions(-) delete mode 100644 src/services/Wappa.Motorista.API/Data/MotoristsContext.cs create mode 100644 src/services/Wappa.Motorista.API/Migrations/20210310071419_Coordenadas.Designer.cs create mode 100644 src/services/Wappa.Motorista.API/Migrations/20210310071419_Coordenadas.cs diff --git a/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs b/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs deleted file mode 100644 index 01d8b56d..00000000 --- a/src/services/Wappa.Motorista.API/Data/MotoristsContext.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Wappa.Motoristas.API.Models; -using Wappa.Core.Data; -using Wappa.Core.DomainObjects; -using FluentValidation.Results; - -namespace Wappa.Motoristas.API.Data -{ - public sealed class MotoristaContext : DbContext, IUnitOfWork - { - - public MotoristaContext(DbContextOptions options) - : base(options) - { - ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; - ChangeTracker.AutoDetectChangesEnabled = false; - } - - public DbSet Motorista { get; set; } - public DbSet Enderecos { get; set; } - public DbSet Carros { get; set; } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Ignore(); - - foreach (var property in modelBuilder.Model.GetEntityTypes().SelectMany( - e => e.GetProperties().Where(p => p.ClrType == typeof(string)))) - property.SetColumnType("varchar(100)"); - - foreach (var relationship in modelBuilder.Model.GetEntityTypes() - .SelectMany(e => e.GetForeignKeys())) relationship.DeleteBehavior = DeleteBehavior.Cascade; - - modelBuilder.ApplyConfigurationsFromAssembly(typeof(MotoristaContext).Assembly); - - base.OnModelCreating(modelBuilder); - } - - public async Task Commit() - { - var sucesso = await base.SaveChangesAsync() > 0; - - return sucesso; - } - } -} \ No newline at end of file diff --git a/src/services/Wappa.Motorista.API/Migrations/20210310071419_Coordenadas.Designer.cs b/src/services/Wappa.Motorista.API/Migrations/20210310071419_Coordenadas.Designer.cs new file mode 100644 index 00000000..8357b0ad --- /dev/null +++ b/src/services/Wappa.Motorista.API/Migrations/20210310071419_Coordenadas.Designer.cs @@ -0,0 +1,142 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Wappa.Motoristas.API.Data; + +namespace Wappa.Motoristas.API.Migrations +{ + [DbContext(typeof(MotoristaContext))] + [Migration("20210310071419_Coordenadas")] + partial class Coordenadas + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Carro", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Marca") + .IsRequired() + .HasColumnType("varchar(200)"); + + b.Property("Modelo") + .IsRequired() + .HasColumnType("varchar(100)"); + + b.Property("MotoristaId") + .HasColumnType("uniqueidentifier"); + + b.Property("Placa") + .IsRequired() + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex("MotoristaId") + .IsUnique(); + + b.ToTable("Carros"); + }); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Endereco", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Bairro") + .IsRequired() + .HasColumnType("varchar(100)"); + + b.Property("Cep") + .IsRequired() + .HasColumnType("varchar(20)"); + + b.Property("Cidade") + .IsRequired() + .HasColumnType("varchar(100)"); + + b.Property("Complemento") + .HasColumnType("varchar(250)"); + + b.Property("Estado") + .IsRequired() + .HasColumnType("varchar(50)"); + + b.Property("Latitude") + .HasColumnType("decimal(18)"); + + b.Property("Logradouro") + .IsRequired() + .HasColumnType("varchar(200)"); + + b.Property("Longitute") + .HasColumnType("decimal(18)"); + + b.Property("MotoristaId") + .HasColumnType("uniqueidentifier"); + + b.Property("Numero") + .IsRequired() + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("MotoristaId") + .IsUnique(); + + b.ToTable("Enderecos"); + }); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Motorista", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Nome") + .IsRequired() + .HasColumnType("varchar(200)"); + + b.Property("SobreNome") + .IsRequired() + .HasColumnType("varchar(200)"); + + b.HasKey("Id"); + + b.ToTable("Motoristas"); + }); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Carro", b => + { + b.HasOne("Wappa.Motoristas.API.Models.Motorista", "Motorista") + .WithOne("Carro") + .HasForeignKey("Wappa.Motoristas.API.Models.Carro", "MotoristaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Wappa.Motoristas.API.Models.Endereco", b => + { + b.HasOne("Wappa.Motoristas.API.Models.Motorista", "Motorista") + .WithOne("Endereco") + .HasForeignKey("Wappa.Motoristas.API.Models.Endereco", "MotoristaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/services/Wappa.Motorista.API/Migrations/20210310071419_Coordenadas.cs b/src/services/Wappa.Motorista.API/Migrations/20210310071419_Coordenadas.cs new file mode 100644 index 00000000..52770ae0 --- /dev/null +++ b/src/services/Wappa.Motorista.API/Migrations/20210310071419_Coordenadas.cs @@ -0,0 +1,35 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Wappa.Motoristas.API.Migrations +{ + public partial class Coordenadas : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Latitude", + table: "Enderecos", + type: "decimal(18,10)", + nullable: false, + defaultValue: 0m); + + migrationBuilder.AddColumn( + name: "Longitude", + table: "Enderecos", + type: "decimal(18,10)", + nullable: false, + defaultValue: 0m); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Latitude", + table: "Enderecos"); + + migrationBuilder.DropColumn( + name: "Longitude", + table: "Enderecos"); + } + } +} diff --git a/src/services/Wappa.Motorista.API/Migrations/MotoristaContextModelSnapshot.cs b/src/services/Wappa.Motorista.API/Migrations/MotoristaContextModelSnapshot.cs index 57567704..7644ec5d 100644 --- a/src/services/Wappa.Motorista.API/Migrations/MotoristaContextModelSnapshot.cs +++ b/src/services/Wappa.Motorista.API/Migrations/MotoristaContextModelSnapshot.cs @@ -73,10 +73,16 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("varchar(50)"); + b.Property("Latitude") + .HasColumnType("decimal(18,10)"); + b.Property("Logradouro") .IsRequired() .HasColumnType("varchar(200)"); + b.Property("Longitude") + .HasColumnType("decimal(18,10)"); + b.Property("MotoristaId") .HasColumnType("uniqueidentifier"); From 52c6d8e51b84e99fc1040a580a34aba6eeb6cc8b Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 05:03:37 -0300 Subject: [PATCH 79/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Adi=C3=A7=C3=A3o=20das=20propriedades=20de=20coordena?= =?UTF-8?q?das?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + src/services/Wappa.Motorista.API/Models/Endereco.cs | 3 +++ .../Wappa.Motorista.API/Wappa.Motoristas.API.csproj | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 505cb0e6..a49cfb28 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ /src/services/Wappa.CoordenadasGeograficas.API/obj /src/building blocks/Wappa.WebAPI.Core/bin/Debug/netcoreapp3.1 /src/building blocks/Wappa.WebAPI.Core/obj +/src/services/Wappa.Motorista.API/bin/Debug diff --git a/src/services/Wappa.Motorista.API/Models/Endereco.cs b/src/services/Wappa.Motorista.API/Models/Endereco.cs index 083a0f38..22798946 100644 --- a/src/services/Wappa.Motorista.API/Models/Endereco.cs +++ b/src/services/Wappa.Motorista.API/Models/Endereco.cs @@ -13,6 +13,9 @@ public class Endereco: Entity public string Cidade { get; set; } public string Estado { get; set; } public Guid MotoristaId { get; set; } + public decimal Longitude { get; set; } + public decimal Latitude{ get; set; } + public Motorista Motorista { get; protected set; } diff --git a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj index d3d615be..df418c10 100644 --- a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj +++ b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj @@ -8,11 +8,16 @@ ..\..\..\docker-compose.dcproj + + bin\Debug\netcoreapp3.1\Wappa.Motoristas.API.xml + bin\Debug\netcoreapp3.1\ + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -26,7 +31,7 @@ - + From 9be32a74d3a419251acef88ec149e655760ae33c Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 05:44:31 -0300 Subject: [PATCH 80/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20suppress=201591=20para=20parar=20de=20avisar=20sobre=20co?= =?UTF-8?q?ment=C3=A1rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj index df418c10..069a7c8d 100644 --- a/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj +++ b/src/services/Wappa.Motorista.API/Wappa.Motoristas.API.csproj @@ -11,6 +11,7 @@ bin\Debug\netcoreapp3.1\Wappa.Motoristas.API.xml bin\Debug\netcoreapp3.1\ + 1701;1702;1591 From b1dec8cd2705fe119a3f792ca09ce12d6f2e73ca Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 07:09:31 -0300 Subject: [PATCH 81/83] feature/TAR-1-Criar-API-Motorista #comment - a chave para consultar --- .../appsettings.Development.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json b/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json index e1368247..a8c18945 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json +++ b/src/services/Wappa.CoordenadasGeograficas.API/appsettings.Development.json @@ -7,7 +7,7 @@ } }, "GoogleGeocodingUrl": "https://maps.googleapis.com/maps/api/geocode/json?", - "GoogleAPiKey": "", + "GoogleAPiKey": "AIzaSyDMoSwDGKl0QsrzjD3U3IVD8sLdRGtmOxQ", "MessageQueueConnection": { "MessageBus": "host=rabbit:5672;publisherConfirms=true;timeout=10" } From c1f50b6bafa1a9f436db09aaae263c3b764b3ad8 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 07:31:55 -0300 Subject: [PATCH 82/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Ajuste=20para=20mostrar=20200=20e=20n=C3=A3o=20mais?= =?UTF-8?q?=20no-content?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wappa.WebAPI.Core/Controllers/MainController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/building blocks/Wappa.WebAPI.Core/Controllers/MainController.cs b/src/building blocks/Wappa.WebAPI.Core/Controllers/MainController.cs index 790bbf23..c82a502c 100644 --- a/src/building blocks/Wappa.WebAPI.Core/Controllers/MainController.cs +++ b/src/building blocks/Wappa.WebAPI.Core/Controllers/MainController.cs @@ -16,7 +16,7 @@ protected ActionResult CustomResponse(object result = null) { if (OperacaoValida()) { - return Ok(result); + return Ok(result ?? new { sucesso = true}); } return BadRequest(new ValidationProblemDetails(new Dictionary From 0ba95288190d1377c7743a1407d9c53335cb7e31 Mon Sep 17 00:00:00 2001 From: Phillipe Roger Souza Date: Wed, 10 Mar 2021 08:03:13 -0300 Subject: [PATCH 83/83] =?UTF-8?q?feature/TAR-1-Criar-API-Motorista=20#comm?= =?UTF-8?q?ent=20-=20Corre=C3=A7=C3=A3o=20desserializa=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Endereco.cs | 11 ----------- .../Services/CoordenadasIntegrationHandler.cs | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs b/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs index 816bbd2f..fd3b2f9a 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs +++ b/src/services/Wappa.CoordenadasGeograficas.API/Models/Endereco.cs @@ -4,17 +4,6 @@ namespace Wappa.CoordenadasGeograficas.API.Models { public class Endereco { - public Endereco(string logradouro, string numero, string complemento, string bairro, string cep, string cidade, string estado) - { - Logradouro = logradouro; - Numero = numero; - Complemento = complemento; - Bairro = bairro; - Cep = cep; - Cidade = cidade; - Estado = estado; - } - public string Logradouro { get; set; } public string Numero { get; set; } public string Complemento { get; set; } diff --git a/src/services/Wappa.CoordenadasGeograficas.API/Services/CoordenadasIntegrationHandler.cs b/src/services/Wappa.CoordenadasGeograficas.API/Services/CoordenadasIntegrationHandler.cs index 763dde1d..47b30bdd 100644 --- a/src/services/Wappa.CoordenadasGeograficas.API/Services/CoordenadasIntegrationHandler.cs +++ b/src/services/Wappa.CoordenadasGeograficas.API/Services/CoordenadasIntegrationHandler.cs @@ -28,17 +28,19 @@ private void SetResponder() private async Task ConsultarCoordenada(SolicitouCadastroMotoristaIntegrationEvent request) { - var enderecoConsultar = new Endereco(request.Logradouro, - request.Numero, - request.Complemento, - request.Bairro, - request.Cep, - request.Cidade, - request.Estado); + var enderecoConsultar = new Endereco(); + + enderecoConsultar.Logradouro = request.Logradouro; + enderecoConsultar.Numero = request.Numero; + enderecoConsultar.Complemento = request.Complemento; + enderecoConsultar.Bairro = request.Bairro; + enderecoConsultar.Cep = request.Cep; + enderecoConsultar.Cidade = request.Cidade; + enderecoConsultar.Estado = request.Estado; var result = await _googleGeocondingService.BuscarCoordenadas(enderecoConsultar); - var coordenadaResponse = new ResponseMessage(new ValidationResult(), result.Longitude, result.Latitude); + var coordenadaResponse = new ResponseMessage(new ValidationResult(), result.Longitude, result.Latitude); return coordenadaResponse; }