diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..154e1272 --- /dev/null +++ b/.gitignore @@ -0,0 +1,477 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk diff --git a/dev/OliSaude/OliSaude.Application/Clientes/CreateCliente/ClienteResponse.cs b/dev/OliSaude/OliSaude.Application/Clientes/CreateCliente/ClienteResponse.cs new file mode 100644 index 00000000..5dd9f708 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Clientes/CreateCliente/ClienteResponse.cs @@ -0,0 +1,26 @@ +using OliSaude.Application.Commom; + +namespace OliSaude.Application.Clientes.CreateCliente +{ + public class ClienteResponse : Response + { + public ClienteResponse() + { + + } + public ClienteResponse(ResponseData obj, string mensagem) + { + Data = obj; + Mensagem = mensagem; + StatusCode = 201; + } + public ClienteResponse(string mensagem, int status) + { + Mensagem = mensagem; + StatusCode=status; + } + public ResponseData? Data { get; set; } + } + + public record ResponseData(int Id, string Nome); +} diff --git a/dev/OliSaude/OliSaude.Application/Clientes/CreateCliente/CreateClienteCommand.cs b/dev/OliSaude/OliSaude.Application/Clientes/CreateCliente/CreateClienteCommand.cs new file mode 100644 index 00000000..1fc638c3 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Clientes/CreateCliente/CreateClienteCommand.cs @@ -0,0 +1,15 @@ +using MediatR; +using OliSaude.Domain.Enums; + +namespace OliSaude.Application.Clientes.CreateCliente +{ + public class CreateClienteCommand : IRequest + { + public string Nome { get; set; } + public DateTime DataNascimento { get; set; } + public ESexo Sexo { get; set; } + public string NomeProblema { get; set; } + public int GrauProblema { get; set; } + + } +} diff --git a/dev/OliSaude/OliSaude.Application/Clientes/CreateCliente/CreateClienteHandler.cs b/dev/OliSaude/OliSaude.Application/Clientes/CreateCliente/CreateClienteHandler.cs new file mode 100644 index 00000000..75782c39 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Clientes/CreateCliente/CreateClienteHandler.cs @@ -0,0 +1,38 @@ +using MediatR; +using OliSaude.Application.Interfaces; +using OliSaude.Domain.Entities; +using OliSaude.Domain.ValueObject; + +namespace OliSaude.Application.Clientes.CreateCliente +{ + public class CreateClienteHandler : IRequestHandler + { + private readonly IClienteRepositorio _repositorio; + + public CreateClienteHandler(IClienteRepositorio repositorio) + { + _repositorio = repositorio; + } + + public async Task Handle(CreateClienteCommand request, CancellationToken cancellationToken) + { + try + { + var problema = new ProblemaSaude(request.NomeProblema, request.GrauProblema); + var cliente = new Cliente(request.Nome, request.DataNascimento, request.Sexo, problema); + await _repositorio.SaveAsync(cliente, cancellationToken); + + if (cliente.Id == 0) + return new ClienteResponse("Não foi possivel salvar o cliente", 404); + + var obj = new ResponseData(cliente.Id, cliente.Nome); + + return new ClienteResponse(obj, "Cliente Salvo com sucesso"); + + }catch (Exception ex) + { + return new ClienteResponse(ex.Message, 500); + } + } + } +} diff --git a/dev/OliSaude/OliSaude.Application/Clientes/DeleteCliente/DeleteClienteCommand.cs b/dev/OliSaude/OliSaude.Application/Clientes/DeleteCliente/DeleteClienteCommand.cs new file mode 100644 index 00000000..093d20c2 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Clientes/DeleteCliente/DeleteClienteCommand.cs @@ -0,0 +1,9 @@ +using MediatR; + +namespace OliSaude.Application.Clientes.DeleteCliente +{ + public class DeleteClienteCommand : IRequest + { + public int Id { get; set; } + } +} diff --git a/dev/OliSaude/OliSaude.Application/Clientes/DeleteCliente/DeleteClienteHandler.cs b/dev/OliSaude/OliSaude.Application/Clientes/DeleteCliente/DeleteClienteHandler.cs new file mode 100644 index 00000000..be3e57d2 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Clientes/DeleteCliente/DeleteClienteHandler.cs @@ -0,0 +1,34 @@ +using MediatR; +using OliSaude.Application.Interfaces; + +namespace OliSaude.Application.Clientes.DeleteCliente +{ + public class DeleteClienteHandler : IRequestHandler + { + private readonly IClienteRepositorio _repositorio; + + public DeleteClienteHandler(IClienteRepositorio repositorio) + { + _repositorio = repositorio; + } + + public async Task Handle(DeleteClienteCommand request, CancellationToken cancellationToken) + { + try + { + var cliente = await _repositorio.GetClienteAsync(request.Id); + if (cliente is null) + return new DeleteResponse("Não foi encontrado um cliente com esse Id", 400); + _repositorio.DeleteCliente(cliente); + + var data = new DeleteData(cliente.Id, cliente.Nome, cliente.ProblemaDeSaude.Nome); + + return new DeleteResponse(data, "Cliente Removido com sucesso"); + }catch (Exception ex) + { + return new DeleteResponse(ex.Message, 500); + } + + } + } +} diff --git a/dev/OliSaude/OliSaude.Application/Clientes/DeleteCliente/DeleteResponse.cs b/dev/OliSaude/OliSaude.Application/Clientes/DeleteCliente/DeleteResponse.cs new file mode 100644 index 00000000..b37b99d2 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Clientes/DeleteCliente/DeleteResponse.cs @@ -0,0 +1,29 @@ +using OliSaude.Application.Commom; + +namespace OliSaude.Application.Clientes.DeleteCliente +{ + public class DeleteResponse : Response + { + public DeleteResponse() + { + + } + public DeleteResponse(string mensagem, int status) + { + Mensagem = mensagem; + StatusCode = status; + } + + public DeleteResponse(DeleteData data, string mensagem) + { + Data = data; + Mensagem = mensagem; + StatusCode = 200; + } + + public DeleteData? Data { get; set; } + + } + + public record DeleteData(int Id, string Name, string Problema); +} diff --git a/dev/OliSaude/OliSaude.Application/Clientes/Queries/GetAllClienteQuery.cs b/dev/OliSaude/OliSaude.Application/Clientes/Queries/GetAllClienteQuery.cs new file mode 100644 index 00000000..5931916c --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Clientes/Queries/GetAllClienteQuery.cs @@ -0,0 +1,44 @@ +using AutoMapper; +using MediatR; +using OliSaude.Application.Dto; +using OliSaude.Application.Interfaces; + +namespace OliSaude.Application.Clientes.Queries +{ + public class GetAllClienteQuery : IRequest> + { + public static bool TryParse(string value, out GetAllClienteQuery result) + { + if (!string.IsNullOrWhiteSpace(value)) + { + result = new GetAllClienteQuery(); + return true; + } + result = null; + return false; + + } + } + + public class GetAllClienteHandler : IRequestHandler> + { + private readonly IClienteRepositorio _repositorio; + private readonly IMapper _mapper; + + public GetAllClienteHandler(IClienteRepositorio repositorio, IMapper mapper) + { + _repositorio = repositorio; + _mapper = mapper; + } + + + public async Task> Handle(GetAllClienteQuery request, CancellationToken cancellationToken) + { + await Task.CompletedTask; + var clientes = _repositorio.GetAllClientes(); + var clientesDto = _mapper.Map>(clientes); + + return clientesDto; + } + } +} diff --git a/dev/OliSaude/OliSaude.Application/Clientes/Queries/GetClienteByIdQuery.cs b/dev/OliSaude/OliSaude.Application/Clientes/Queries/GetClienteByIdQuery.cs new file mode 100644 index 00000000..8568d613 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Clientes/Queries/GetClienteByIdQuery.cs @@ -0,0 +1,44 @@ +using AutoMapper; +using MediatR; +using OliSaude.Application.Dto; +using OliSaude.Application.Interfaces; +using OliSaude.Domain.Entities; + +namespace OliSaude.Application.Clientes.Queries +{ + public class GetClienteByIdQuery: IRequest + { + public int Id { get; set; } + + public static bool TryParse(string value, out GetClienteByIdQuery query) + { + if(value is null) + { + query = default; + return false; + } + query = new GetClienteByIdQuery { Id = int.Parse(value)}; + return true; + } + + } + + public class GetClienteByIdHandler : IRequestHandler + { + private readonly IMapper _mapper; + private readonly IClienteRepositorio _repositorio; + + public GetClienteByIdHandler(IMapper mapper, IClienteRepositorio repositorio) + { + _mapper = mapper; + _repositorio = repositorio; + } + + public async Task Handle(GetClienteByIdQuery request, CancellationToken cancellationToken) + { + var cliente = await _repositorio.GetClienteAsync(request.Id); + var clienteDto = _mapper.Map(cliente); + return clienteDto; + } + } +} diff --git a/dev/OliSaude/OliSaude.Application/Clientes/Queries/GetClienteMaiorRiscoQuery.cs b/dev/OliSaude/OliSaude.Application/Clientes/Queries/GetClienteMaiorRiscoQuery.cs new file mode 100644 index 00000000..398f87ac --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Clientes/Queries/GetClienteMaiorRiscoQuery.cs @@ -0,0 +1,40 @@ +using AutoMapper; +using MediatR; +using OliSaude.Application.Dto; +using OliSaude.Application.Interfaces; +using OliSaude.Domain.Entities; + +namespace OliSaude.Application.Clientes.Queries +{ + public class GetClienteMaiorRiscoQuery : IRequest> + { + + } + + public class GetClienteMaiorRiscoHandler : IRequestHandler> + { + private readonly IClienteRepositorio _repo; + private readonly IMapper _mapper; + + public GetClienteMaiorRiscoHandler(IClienteRepositorio repo, IMapper mapper) + { + _repo = repo; + _mapper = mapper; + } + + public async Task> Handle(GetClienteMaiorRiscoQuery request, CancellationToken cancellationToken) + { + await Task.CompletedTask; + var clientes = _repo.GetAllClientes().OrderByDescending(cliente => CalculoScore(cliente)).Take(10); + + return _mapper.Map>(clientes); + } + private double CalculoScore(Cliente cliente) + { + var sd = cliente.ProblemaDeSaude.Grau; + var denominador = 1 + Math.Pow(Math.E, -(-2.8 + sd)); + var score = (1 / denominador) * 100; + return score; + } + } +} diff --git a/dev/OliSaude/OliSaude.Application/Clientes/UpdateCliente/UpdateClienteCommand.cs b/dev/OliSaude/OliSaude.Application/Clientes/UpdateCliente/UpdateClienteCommand.cs new file mode 100644 index 00000000..3b36c3de --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Clientes/UpdateCliente/UpdateClienteCommand.cs @@ -0,0 +1,13 @@ +using MediatR; +using OliSaude.Application.Clientes.UpdateCliente; + +namespace OliSaude.Application.Clientes.UpdateUser; + +public class UpdateClienteCommand : IRequest +{ + public int Id { get; set; } + public string Nome { get; set; } + public DateTime DataNascimento { get; set; } + public string NomeProblema { get; set; } + public int GrauProblema { get; set; } +} diff --git a/dev/OliSaude/OliSaude.Application/Clientes/UpdateCliente/UpdateClienteHandler.cs b/dev/OliSaude/OliSaude.Application/Clientes/UpdateCliente/UpdateClienteHandler.cs new file mode 100644 index 00000000..7d8bd459 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Clientes/UpdateCliente/UpdateClienteHandler.cs @@ -0,0 +1,47 @@ +using MediatR; +using OliSaude.Application.Clientes.UpdateUser; +using OliSaude.Application.Interfaces; +using OliSaude.Domain.ValueObject; + +namespace OliSaude.Application.Clientes.UpdateCliente +{ + public class UpdateClienteHandler : IRequestHandler + { + private readonly IClienteRepositorio _repositoio; + + public UpdateClienteHandler(IClienteRepositorio repositorio) + { + _repositoio = repositorio; + } + + public async Task Handle(UpdateClienteCommand request, CancellationToken cancellationToken) + { + try + { + var cliente = await _repositoio.GetClienteAsync(request.Id); + + if (cliente is null) + return new UpdateResponse("Cliente invalido", 400); + + var problema = new ProblemaSaude(request.NomeProblema, request.GrauProblema); + cliente.UpdateCliente(request.Nome, request.DataNascimento, problema); + await _repositoio.UpdateClienteAsync(cliente, cancellationToken); + + var data = new UpdateData(cliente.Id, + cliente.Nome, + Enum.GetName(cliente.Sexo), + cliente.DataNascimento, + cliente.ProblemaDeSaude.Nome, + cliente.ProblemaDeSaude.Grau, + cliente.DataCriacao, + cliente.DataActualizacao); + + return new UpdateResponse(data, "Cliente actualizado com sucesso"); + }catch (Exception ex) + { + return new UpdateResponse(ex.Message, 500); + } + + } + } +} diff --git a/dev/OliSaude/OliSaude.Application/Clientes/UpdateCliente/UpdateResponse.cs b/dev/OliSaude/OliSaude.Application/Clientes/UpdateCliente/UpdateResponse.cs new file mode 100644 index 00000000..3ff993f3 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Clientes/UpdateCliente/UpdateResponse.cs @@ -0,0 +1,35 @@ +using OliSaude.Application.Commom; + +namespace OliSaude.Application.Clientes.UpdateCliente +{ + public class UpdateResponse : Response + { + public UpdateResponse() + { + + } + public UpdateResponse(string mensagem, int status) + { + Mensagem = mensagem; + StatusCode = status; + } + + public UpdateResponse(UpdateData data, string mensagem) + { + Data = data; + Mensagem = mensagem; + StatusCode = 200; + } + + public UpdateData? Data { get; set; } + } + + public record UpdateData(int Id, + string Name, + string Sexo, + DateTime DataNascimento, + string Problema, + int Grau, + DateTime DataCriacao, + DateTime DataActualizacao); +} diff --git a/dev/OliSaude/OliSaude.Application/Commom/Response.cs b/dev/OliSaude/OliSaude.Application/Commom/Response.cs new file mode 100644 index 00000000..5118d7c7 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Commom/Response.cs @@ -0,0 +1,10 @@ +namespace OliSaude.Application.Commom +{ + public abstract class Response + { + public string Mensagem { get; set; } = string.Empty; + public int StatusCode { get; set; } = 400; + public bool IsSucess => StatusCode >= 200 && StatusCode <= 299; + + } +} diff --git a/dev/OliSaude/OliSaude.Application/Dto/ClienteDto.cs b/dev/OliSaude/OliSaude.Application/Dto/ClienteDto.cs new file mode 100644 index 00000000..dc2559c5 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Dto/ClienteDto.cs @@ -0,0 +1,16 @@ +using OliSaude.Domain.Enums; + +namespace OliSaude.Application.Dto +{ + public class ClienteDto + { + public int Id { get; set; } + public string Nome { get; set; } = string.Empty; + public DateTime DataNascimento { get; set; } + public ESexo Sexo { get; set; } + public DateTime DataRegisto { get; set; } + public DateTime DataActualizacao { get; set; } + public string NomeProblema { get; set; } = string.Empty; + public int GrauProblema { get; set; } + } +} diff --git a/dev/OliSaude/OliSaude.Application/Dto/Mapper/ProfileMaping.cs b/dev/OliSaude/OliSaude.Application/Dto/Mapper/ProfileMaping.cs new file mode 100644 index 00000000..2a14fc06 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Dto/Mapper/ProfileMaping.cs @@ -0,0 +1,17 @@ +using AutoMapper; +using OliSaude.Domain.Entities; + +namespace OliSaude.Application.Dto.Mapper +{ + public class ProfileMaping : Profile + { + public ProfileMaping() + { + + CreateMap() + .ForMember(c=>c.NomeProblema, opt =>opt.MapFrom(ob=>ob.ProblemaDeSaude.Nome)) + .ForMember(c => c.GrauProblema, opt => opt.MapFrom(ob => ob.ProblemaDeSaude.Grau)) + .ForMember(c=>c.DataRegisto, opt=>opt.MapFrom(ob=>ob.DataCriacao)).ReverseMap(); + } + } +} diff --git a/dev/OliSaude/OliSaude.Application/Interfaces/IAdapter.cs b/dev/OliSaude/OliSaude.Application/Interfaces/IAdapter.cs new file mode 100644 index 00000000..08513912 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Interfaces/IAdapter.cs @@ -0,0 +1,7 @@ +namespace OliSaude.Application.Interfaces +{ + public interface IAdapter + { + TDestiny Adapte(TSource source); + } +} diff --git a/dev/OliSaude/OliSaude.Application/Interfaces/IClienteRepositorio.cs b/dev/OliSaude/OliSaude.Application/Interfaces/IClienteRepositorio.cs new file mode 100644 index 00000000..dbd88e06 --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/Interfaces/IClienteRepositorio.cs @@ -0,0 +1,13 @@ +using OliSaude.Domain.Entities; + +namespace OliSaude.Application.Interfaces +{ + public interface IClienteRepositorio + { + Task SaveAsync(Cliente cliente, CancellationToken cancellationToken); + IEnumerable GetAllClientes(); + Task GetClienteAsync(int id); + Task UpdateClienteAsync(Cliente cliente, CancellationToken cancellationToken); + void DeleteCliente(Cliente cliente); + } +} diff --git a/dev/OliSaude/OliSaude.Application/OliSaude.Application.csproj b/dev/OliSaude/OliSaude.Application/OliSaude.Application.csproj new file mode 100644 index 00000000..5ff404ba --- /dev/null +++ b/dev/OliSaude/OliSaude.Application/OliSaude.Application.csproj @@ -0,0 +1,19 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + + + diff --git a/dev/OliSaude/OliSaude.Domain/Entities/Cliente.cs b/dev/OliSaude/OliSaude.Domain/Entities/Cliente.cs new file mode 100644 index 00000000..b2d360e3 --- /dev/null +++ b/dev/OliSaude/OliSaude.Domain/Entities/Cliente.cs @@ -0,0 +1,39 @@ +using OliSaude.Domain.Enums; +using OliSaude.Domain.ValueObject; + +namespace OliSaude.Domain.Entities; + +public class Cliente : Entity +{ + private Cliente() + { + + } + public Cliente(string nome, DateTime + dataNascimento, + ESexo sexo, + ProblemaSaude problemaDeSaude) + { + Nome = nome; + DataNascimento = dataNascimento; + Sexo = sexo; + ProblemaDeSaude = problemaDeSaude; + DataActualizacao = DateTime.UtcNow; + } + + public string Nome { get; private set; } + public DateTime DataNascimento { get; private set; } + public ESexo Sexo { get; private set; } + public ProblemaSaude ProblemaDeSaude { get; private set; } + public DateTime DataActualizacao { get; private set; } + + public void UpdateCliente(string nome, + DateTime dataNascimento, + ProblemaSaude problemaDeSaude) + { + Nome =nome; + DataNascimento=dataNascimento; + ProblemaDeSaude =problemaDeSaude; + DataActualizacao = DateTime.UtcNow; + } +} diff --git a/dev/OliSaude/OliSaude.Domain/Entities/Entity.cs b/dev/OliSaude/OliSaude.Domain/Entities/Entity.cs new file mode 100644 index 00000000..92775b0b --- /dev/null +++ b/dev/OliSaude/OliSaude.Domain/Entities/Entity.cs @@ -0,0 +1,12 @@ +namespace OliSaude.Domain.Entities +{ + public abstract class Entity + { + protected Entity() + { + DataCriacao = DateTime.UtcNow; + } + public int Id { get; private set; } + public DateTime DataCriacao { get; private set; } + } +} diff --git a/dev/OliSaude/OliSaude.Domain/Enums/ESexo.cs b/dev/OliSaude/OliSaude.Domain/Enums/ESexo.cs new file mode 100644 index 00000000..54f64a8c --- /dev/null +++ b/dev/OliSaude/OliSaude.Domain/Enums/ESexo.cs @@ -0,0 +1,8 @@ +namespace OliSaude.Domain.Enums +{ + public enum ESexo + { + Mascolino = 1, + Femenino = 2 + } +} diff --git a/dev/OliSaude/OliSaude.Domain/OliSaude.Domain.csproj b/dev/OliSaude/OliSaude.Domain/OliSaude.Domain.csproj new file mode 100644 index 00000000..cfadb03d --- /dev/null +++ b/dev/OliSaude/OliSaude.Domain/OliSaude.Domain.csproj @@ -0,0 +1,9 @@ + + + + net7.0 + enable + enable + + + diff --git a/dev/OliSaude/OliSaude.Domain/ValueObject/ProblemaSaude.cs b/dev/OliSaude/OliSaude.Domain/ValueObject/ProblemaSaude.cs new file mode 100644 index 00000000..460653f3 --- /dev/null +++ b/dev/OliSaude/OliSaude.Domain/ValueObject/ProblemaSaude.cs @@ -0,0 +1,12 @@ +namespace OliSaude.Domain.ValueObject; +public class ProblemaSaude : ValeuObject +{ + public ProblemaSaude(string nome, int grau) + { + Nome = nome; + Grau = grau; + } + + public string Nome { get; private set; } + public int Grau { get; private set; } +} diff --git a/dev/OliSaude/OliSaude.Domain/ValueObject/ValeuObject.cs b/dev/OliSaude/OliSaude.Domain/ValueObject/ValeuObject.cs new file mode 100644 index 00000000..44cf98a8 --- /dev/null +++ b/dev/OliSaude/OliSaude.Domain/ValueObject/ValeuObject.cs @@ -0,0 +1,6 @@ +namespace OliSaude.Domain.ValueObject +{ + public abstract class ValeuObject + { + } +} diff --git a/dev/OliSaude/OliSaude.Infra/Data/ClienteConfiguration.cs b/dev/OliSaude/OliSaude.Infra/Data/ClienteConfiguration.cs new file mode 100644 index 00000000..52f5ea49 --- /dev/null +++ b/dev/OliSaude/OliSaude.Infra/Data/ClienteConfiguration.cs @@ -0,0 +1,49 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using OliSaude.Domain.Entities; + +namespace OliSaude.Infra.Data +{ + public class ClienteConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(nameof(Cliente)); + + builder.HasKey(x => x.Id); + + builder.Property(x => x.Id) + .IsRequired() + .ValueGeneratedOnAdd(); + + builder.Property(x => x.Nome) + .IsRequired() + .HasColumnName("Nome_Cliente") + .HasMaxLength(500); + + builder.Property(x => x.DataNascimento) + .IsRequired() + .HasColumnName("DataNascimento"); + + builder.Property(x => x.Sexo) + .IsRequired(); + + builder.OwnsOne(x => x.ProblemaDeSaude) + .Property(p => p.Nome) + .IsRequired() + .HasColumnName("Problema") + .HasMaxLength(200); + + builder.OwnsOne(x => x.ProblemaDeSaude) + .Property(p => p.Grau) + .IsRequired() + .HasColumnName("Grau"); + + builder.Property(x => x.DataCriacao) + .IsRequired(); + + builder.Property(x => x.DataActualizacao) + .IsRequired(); + } + } +} diff --git a/dev/OliSaude/OliSaude.Infra/Data/OliSaudeContext.cs b/dev/OliSaude/OliSaude.Infra/Data/OliSaudeContext.cs new file mode 100644 index 00000000..3a41fcf8 --- /dev/null +++ b/dev/OliSaude/OliSaude.Infra/Data/OliSaudeContext.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; +using OliSaude.Domain.Entities; +using System.Reflection; + +namespace OliSaude.Infra.Data; + +public class OliSaudeContext : DbContext +{ + public DbSet Clientes { get; set; } + public OliSaudeContext(DbContextOptions options ) + : base(options) + { + + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); + } +} diff --git a/dev/OliSaude/OliSaude.Infra/DbOliSaude.db b/dev/OliSaude/OliSaude.Infra/DbOliSaude.db new file mode 100644 index 00000000..8133100d Binary files /dev/null and b/dev/OliSaude/OliSaude.Infra/DbOliSaude.db differ diff --git a/dev/OliSaude/OliSaude.Infra/DbOliSaude.db-shm b/dev/OliSaude/OliSaude.Infra/DbOliSaude.db-shm new file mode 100644 index 00000000..fe9ac284 Binary files /dev/null and b/dev/OliSaude/OliSaude.Infra/DbOliSaude.db-shm differ diff --git a/dev/OliSaude/OliSaude.Infra/DbOliSaude.db-wal b/dev/OliSaude/OliSaude.Infra/DbOliSaude.db-wal new file mode 100644 index 00000000..e69de29b diff --git a/dev/OliSaude/OliSaude.Infra/Extensions/ConnectionsExtension.cs b/dev/OliSaude/OliSaude.Infra/Extensions/ConnectionsExtension.cs new file mode 100644 index 00000000..601b53fd --- /dev/null +++ b/dev/OliSaude/OliSaude.Infra/Extensions/ConnectionsExtension.cs @@ -0,0 +1,42 @@ +using MediatR; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using OliSaude.Application.Clientes.CreateCliente; +using OliSaude.Application.Clientes.DeleteCliente; +using OliSaude.Application.Clientes.Queries; +using OliSaude.Application.Clientes.UpdateCliente; +using OliSaude.Application.Clientes.UpdateUser; +using OliSaude.Application.Dto; +using OliSaude.Application.Dto.Mapper; +using OliSaude.Application.Interfaces; +using OliSaude.Infra.Data; +using OliSaude.Infra.Repostorio; +using System.Reflection; + +namespace OliSaude.Infra.Extensions +{ + public static class ConnectionsExtension + { + public static IServiceCollection AddDependece(this IServiceCollection services, IConfiguration configuration) + { + services.AddDbContext(options => + options.UseSqlite(configuration.GetConnectionString("DefaultConnetion"))); + services.AddMediatR(cfg => + cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())); + services.AddAutoMapper(Assembly.GetExecutingAssembly()) + .AddAutoMapper(typeof(ProfileMaping)); + + services.AddScoped(); + services.AddScoped>,GetAllClienteHandler>(); + services.AddScoped,GetClienteByIdHandler >(); + services.AddScoped>, GetClienteMaiorRiscoHandler >(); + + services.AddScoped< IRequestHandler, CreateClienteHandler >(); + services.AddScoped< IRequestHandler < UpdateClienteCommand, UpdateResponse >, UpdateClienteHandler >(); + services.AddScoped< IRequestHandler < DeleteClienteCommand, DeleteResponse >, DeleteClienteHandler >(); + + return services; + } + } +} diff --git a/dev/OliSaude/OliSaude.Infra/Migrations/20231103192400_v1.Designer.cs b/dev/OliSaude/OliSaude.Infra/Migrations/20231103192400_v1.Designer.cs new file mode 100644 index 00000000..554c56e7 --- /dev/null +++ b/dev/OliSaude/OliSaude.Infra/Migrations/20231103192400_v1.Designer.cs @@ -0,0 +1,84 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OliSaude.Infra.Data; + +#nullable disable + +namespace OliSaude.Infra.Migrations +{ + [DbContext(typeof(OliSaudeContext))] + [Migration("20231103192400_v1")] + partial class v1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.13"); + + modelBuilder.Entity("OliSaude.Domain.Entities.Cliente", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DataActualizacao") + .HasColumnType("TEXT"); + + b.Property("DataCriacao") + .HasColumnType("TEXT"); + + b.Property("DataNascimento") + .HasColumnType("TEXT") + .HasColumnName("DataNascimento"); + + b.Property("Nome") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT") + .HasColumnName("Nome_Cliente"); + + b.Property("Sexo") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Cliente", (string)null); + }); + + modelBuilder.Entity("OliSaude.Domain.Entities.Cliente", b => + { + b.OwnsOne("OliSaude.Domain.ValueObject.ProblemaSaude", "ProblemaDeSaude", b1 => + { + b1.Property("ClienteId") + .HasColumnType("INTEGER"); + + b1.Property("Grau") + .HasColumnType("INTEGER") + .HasColumnName("Grau"); + + b1.Property("Nome") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT") + .HasColumnName("Problema"); + + b1.HasKey("ClienteId"); + + b1.ToTable("Cliente"); + + b1.WithOwner() + .HasForeignKey("ClienteId"); + }); + + b.Navigation("ProblemaDeSaude") + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/dev/OliSaude/OliSaude.Infra/Migrations/20231103192400_v1.cs b/dev/OliSaude/OliSaude.Infra/Migrations/20231103192400_v1.cs new file mode 100644 index 00000000..12ace98d --- /dev/null +++ b/dev/OliSaude/OliSaude.Infra/Migrations/20231103192400_v1.cs @@ -0,0 +1,41 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace OliSaude.Infra.Migrations +{ + /// + public partial class v1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Cliente", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Nome_Cliente = table.Column(type: "TEXT", maxLength: 500, nullable: false), + DataNascimento = table.Column(type: "TEXT", nullable: false), + Sexo = table.Column(type: "INTEGER", nullable: false), + Problema = table.Column(type: "TEXT", maxLength: 200, nullable: false), + Grau = table.Column(type: "INTEGER", nullable: false), + DataActualizacao = table.Column(type: "TEXT", nullable: false), + DataCriacao = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Cliente", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Cliente"); + } + } +} diff --git a/dev/OliSaude/OliSaude.Infra/Migrations/OliSaudeContextModelSnapshot.cs b/dev/OliSaude/OliSaude.Infra/Migrations/OliSaudeContextModelSnapshot.cs new file mode 100644 index 00000000..24e32bf7 --- /dev/null +++ b/dev/OliSaude/OliSaude.Infra/Migrations/OliSaudeContextModelSnapshot.cs @@ -0,0 +1,81 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OliSaude.Infra.Data; + +#nullable disable + +namespace OliSaude.Infra.Migrations +{ + [DbContext(typeof(OliSaudeContext))] + partial class OliSaudeContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.13"); + + modelBuilder.Entity("OliSaude.Domain.Entities.Cliente", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DataActualizacao") + .HasColumnType("TEXT"); + + b.Property("DataCriacao") + .HasColumnType("TEXT"); + + b.Property("DataNascimento") + .HasColumnType("TEXT") + .HasColumnName("DataNascimento"); + + b.Property("Nome") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT") + .HasColumnName("Nome_Cliente"); + + b.Property("Sexo") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Cliente", (string)null); + }); + + modelBuilder.Entity("OliSaude.Domain.Entities.Cliente", b => + { + b.OwnsOne("OliSaude.Domain.ValueObject.ProblemaSaude", "ProblemaDeSaude", b1 => + { + b1.Property("ClienteId") + .HasColumnType("INTEGER"); + + b1.Property("Grau") + .HasColumnType("INTEGER") + .HasColumnName("Grau"); + + b1.Property("Nome") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT") + .HasColumnName("Problema"); + + b1.HasKey("ClienteId"); + + b1.ToTable("Cliente"); + + b1.WithOwner() + .HasForeignKey("ClienteId"); + }); + + b.Navigation("ProblemaDeSaude") + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/dev/OliSaude/OliSaude.Infra/OliSaude.Infra.csproj b/dev/OliSaude/OliSaude.Infra/OliSaude.Infra.csproj new file mode 100644 index 00000000..34f93476 --- /dev/null +++ b/dev/OliSaude/OliSaude.Infra/OliSaude.Infra.csproj @@ -0,0 +1,22 @@ + + + + net7.0 + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/dev/OliSaude/OliSaude.Infra/Repostorio/ClienteRepositorio.cs b/dev/OliSaude/OliSaude.Infra/Repostorio/ClienteRepositorio.cs new file mode 100644 index 00000000..b247f41d --- /dev/null +++ b/dev/OliSaude/OliSaude.Infra/Repostorio/ClienteRepositorio.cs @@ -0,0 +1,47 @@ +using Microsoft.EntityFrameworkCore; +using OliSaude.Application.Interfaces; +using OliSaude.Domain.Entities; +using OliSaude.Infra.Data; + +namespace OliSaude.Infra.Repostorio; +public class ClienteRepositorio : IClienteRepositorio +{ + private readonly OliSaudeContext _context; + + public ClienteRepositorio(OliSaudeContext context) + { + _context = context; + } + + public IEnumerable GetAllClientes() + { + return _context + .Clientes + .AsNoTracking() + .ToList(); + } + + public async Task GetClienteAsync(int id) + { + var cliente = await _context.Clientes.FirstOrDefaultAsync(c => c.Id == id); + return cliente; + } + + public async Task SaveAsync(Cliente cliente, CancellationToken cancellationToken = default) + { + _context.Add(cliente); + await _context.SaveChangesAsync(); + } + + public async Task UpdateClienteAsync(Cliente cliente, CancellationToken cancellationToken) + { + _context.Entry(cliente).State = EntityState.Modified; + await _context.SaveChangesAsync(cancellationToken); + } + + public void DeleteCliente(Cliente cliente) + { + _context.Remove(cliente); + _context.SaveChanges(); + } +} diff --git a/dev/OliSaude/OliSaude.WebApi/OliSaude.WebApi.csproj b/dev/OliSaude/OliSaude.WebApi/OliSaude.WebApi.csproj new file mode 100644 index 00000000..609a721e --- /dev/null +++ b/dev/OliSaude/OliSaude.WebApi/OliSaude.WebApi.csproj @@ -0,0 +1,22 @@ + + + + net7.0 + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/dev/OliSaude/OliSaude.WebApi/Papiline/PapelineExtension.cs b/dev/OliSaude/OliSaude.WebApi/Papiline/PapelineExtension.cs new file mode 100644 index 00000000..818893e7 --- /dev/null +++ b/dev/OliSaude/OliSaude.WebApi/Papiline/PapelineExtension.cs @@ -0,0 +1,73 @@ +using MediatR; +using Microsoft.AspNetCore.Mvc; +using OliSaude.Application.Clientes.CreateCliente; +using OliSaude.Application.Clientes.DeleteCliente; +using OliSaude.Application.Clientes.Queries; +using OliSaude.Application.Clientes.UpdateUser; + +namespace OliSaude.WebApi.Papiline +{ + public static class PapelineExtension + { + public static void Endpoints(this WebApplication app) + { + app.MapGet("/api/v1/clientes", async ([AsParameters] GetAllClienteQuery query, + [FromServices] IMediator mediator) => + { + + var result = await mediator.Send(query); + if (result is null) + return Results.NotFound("Resultado não encontrado"); + return Results.Ok(result); + }); + + app.MapGet("/api/v1/clientes/{id:int}", async ([AsParameters] GetClienteByIdQuery query, + [FromServices] IMediator mediator) => + { + + var result = await mediator.Send(query); + if (result is null) + return Results.BadRequest("Resultado não encontrado"); + return Results.Ok(result); + }); + + app.MapGet("/api/v1/clientes/maiorRisco", async ([AsParameters] GetClienteMaiorRiscoQuery query, + [FromServices] IMediator mediator) => + { + + var result =await mediator.Send(query); + if (result is null) + return Results.NotFound("Resultado não encontrado"); + return Results.Ok(result); + }); + + app.MapPost("/api/v1/clientes", async ([FromBody] CreateClienteCommand command, + [FromServices] IMediator mediator) => + { + var result = await mediator.Send(command); + if (!result.IsSucess) + return Results.BadRequest(result); + return Results.Created($"/api/v1/cliente/{result.Data.Id}", result); + }); + + app.MapPut("/api/v1/clientes", async ([FromBody] UpdateClienteCommand command, + [FromServices] IMediator mediator) => + { + var result = await mediator.Send(command); + if (!result.IsSucess) + return Results.NotFound(result); + + return Results.Ok(result); + }); + + app.MapDelete("/api/v1/clientes", async ([FromBody] DeleteClienteCommand command, + [FromServices] IMediator mediator) => + { + var result = await mediator.Send(command); + if (!result.IsSucess) + return Results.Json(result, statusCode: result.StatusCode); + return Results.Ok(result); + }); + } + } +} diff --git a/dev/OliSaude/OliSaude.WebApi/Program.cs b/dev/OliSaude/OliSaude.WebApi/Program.cs new file mode 100644 index 00000000..f141d0be --- /dev/null +++ b/dev/OliSaude/OliSaude.WebApi/Program.cs @@ -0,0 +1,26 @@ +using OliSaude.Infra.Extensions; +using OliSaude.WebApi.Papiline; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); +builder.Services.AddDependece(builder.Configuration); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.Endpoints(); + +app.Run(); + diff --git a/dev/OliSaude/OliSaude.WebApi/Properties/launchSettings.json b/dev/OliSaude/OliSaude.WebApi/Properties/launchSettings.json new file mode 100644 index 00000000..ce2bb32b --- /dev/null +++ b/dev/OliSaude/OliSaude.WebApi/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:48388", + "sslPort": 44382 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5267", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7013;http://localhost:5267", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/dev/OliSaude/OliSaude.WebApi/appsettings.Development.json b/dev/OliSaude/OliSaude.WebApi/appsettings.Development.json new file mode 100644 index 00000000..0c208ae9 --- /dev/null +++ b/dev/OliSaude/OliSaude.WebApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/dev/OliSaude/OliSaude.WebApi/appsettings.json b/dev/OliSaude/OliSaude.WebApi/appsettings.json new file mode 100644 index 00000000..15de017c --- /dev/null +++ b/dev/OliSaude/OliSaude.WebApi/appsettings.json @@ -0,0 +1,12 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "connectionStrings": { + "DefaultConnetion": "Data Source =..\\OliSaude.Infra\\DbOliSaude.db" + }, + "AllowedHosts": "*" +} diff --git a/dev/OliSaude/OliSaude.sln b/dev/OliSaude/OliSaude.sln new file mode 100644 index 00000000..615d856b --- /dev/null +++ b/dev/OliSaude/OliSaude.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34031.279 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OliSaude.Domain", "OliSaude.Domain\OliSaude.Domain.csproj", "{D57F79B2-F622-4169-B23C-4FFD250B0EE4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OliSaude.Application", "OliSaude.Application\OliSaude.Application.csproj", "{1B2FB43A-53BD-4FAC-BC09-2E8A743B1E6F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OliSaude.Infra", "OliSaude.Infra\OliSaude.Infra.csproj", "{6DBF3EFF-F3F6-4916-98E8-DCB96B4E35A5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OliSaude.WebApi", "OliSaude.WebApi\OliSaude.WebApi.csproj", "{DFEAB602-C365-4B92-911B-68B1F52AB011}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D57F79B2-F622-4169-B23C-4FFD250B0EE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D57F79B2-F622-4169-B23C-4FFD250B0EE4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D57F79B2-F622-4169-B23C-4FFD250B0EE4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D57F79B2-F622-4169-B23C-4FFD250B0EE4}.Release|Any CPU.Build.0 = Release|Any CPU + {1B2FB43A-53BD-4FAC-BC09-2E8A743B1E6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1B2FB43A-53BD-4FAC-BC09-2E8A743B1E6F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1B2FB43A-53BD-4FAC-BC09-2E8A743B1E6F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1B2FB43A-53BD-4FAC-BC09-2E8A743B1E6F}.Release|Any CPU.Build.0 = Release|Any CPU + {6DBF3EFF-F3F6-4916-98E8-DCB96B4E35A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6DBF3EFF-F3F6-4916-98E8-DCB96B4E35A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6DBF3EFF-F3F6-4916-98E8-DCB96B4E35A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6DBF3EFF-F3F6-4916-98E8-DCB96B4E35A5}.Release|Any CPU.Build.0 = Release|Any CPU + {DFEAB602-C365-4B92-911B-68B1F52AB011}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DFEAB602-C365-4B92-911B-68B1F52AB011}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DFEAB602-C365-4B92-911B-68B1F52AB011}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DFEAB602-C365-4B92-911B-68B1F52AB011}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D0547902-8B4C-46CB-8BCC-8B64D8F84653} + EndGlobalSection +EndGlobal diff --git a/dev/README.md b/dev/README.md index d2c72e69..d64df295 100644 --- a/dev/README.md +++ b/dev/README.md @@ -1 +1,75 @@ -# SEU Readme \ No newline at end of file +# Backend Developer Challenge + +## Introdução + +De Formas a testar meu conhecimento em desenvolvimento de API, alinhei no presente desafio que consiste em Desenvolver uma API de saude denominado OLisaude. + +## Modelo de dados + +### Cliente + +- Nome: Nome do cliente +- DataNascimento: data de nascimento do cliente +- Sexo: sexo do cliente +- ProblemaDeSaude: problemas de saude do Cliente +- DataCriacao: data de criação +- DataActualizacao: data de atualização + +### Problema de Saude + +- Nome: nome do problema +- Grau: Grau do problema + +## Funcionalidades + +- Cliente: Operações CRUD para gerenciar informações o Cliente. + +## EndPoints da API + +### Cliente + +- GET /api/v1/clientes : Opter todos os cliente + +* GET /api/v1/clientes/{id} : opter um cliente por Id + +* GET /api/v1/clientes/maiorRiscos : Opter os 10 clientes com maior risco + +* POST /api/v1/clientes : Criar um novo cliente + +* PUT /api/v1/clientes :Actualizar um cliente + +* DELETE /api/v1/clientes : Remover um cliente + +## como usar + +- Clone este repositório. + +- Configure o ambiente de desenvolvimento e as dependências necessárias. + +- Execute a aplicação. + +- Comece a utilizar as funcionalidades da API. + +* Acesse a documentação da API (Swagger) para entender as rotas e funcionalidades disponíveis. + +![Alt text](image.png) + +## Tecnologias Usadas + +- .NET 7. + +- Asp.Net Core 7. + +- Entity Framework core. + +- SQLite. + +- CQRS. + +- AutoMapper. + +- Clean Architecture. + +* MediatR. + +* Minimal API. diff --git a/dev/image.png b/dev/image.png new file mode 100644 index 00000000..644ac6a2 Binary files /dev/null and b/dev/image.png differ