diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 00000000..6b611411 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,6 @@ +{ + "ExpandedNodes": [ + "" + ], + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/backend-test/v17/.suo b/.vs/backend-test/v17/.suo new file mode 100644 index 00000000..a725c87c Binary files /dev/null and b/.vs/backend-test/v17/.suo differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 00000000..6b696670 Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/bookstoreManager/.gitignore b/bookstoreManager/.gitignore new file mode 100644 index 00000000..a931162f --- /dev/null +++ b/bookstoreManager/.gitignore @@ -0,0 +1,363 @@ +## 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/master/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/ +[Oo]ut/ +[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 Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# 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 +*.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 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/ + +# 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 \ No newline at end of file diff --git a/bookstoreManager/BookstoreManager.Aplication/AuthenticationService/Login/ILoginUserService.cs b/bookstoreManager/BookstoreManager.Aplication/AuthenticationService/Login/ILoginUserService.cs new file mode 100644 index 00000000..1dcc2a81 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/AuthenticationService/Login/ILoginUserService.cs @@ -0,0 +1,10 @@ +using BookstoreManager.Domain.dto.authenticationDto; + + +namespace BookstoreManager.Application.Authentication.Login +{ + public interface ILoginUserService + { + Task Login(LoginRequest request); + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/AuthenticationService/Login/LoginUserService.cs b/bookstoreManager/BookstoreManager.Aplication/AuthenticationService/Login/LoginUserService.cs new file mode 100644 index 00000000..ec895be4 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/AuthenticationService/Login/LoginUserService.cs @@ -0,0 +1,34 @@ +using BookstoreManager.Application.Interactor; +using BookstoreManager.Domain.dto.authenticationDto; +using BookstoreManager.Repository.Interface; + +namespace BookstoreManager.Application.Authentication.Login +{ + public class LoginUserService : ILoginUserService + { + private readonly IUserRepository _userRepository; + private readonly IAuthentication _authentication; + public LoginUserService(IUserRepository userRepository, IAuthentication authentication) + { + _userRepository = userRepository; + _authentication = authentication; + } + public async Task Login(LoginRequest request) + { + return await Task.Run(() => + { + + var hasUser = _userRepository.GetByEmail(request.Email); + + var passCryp = CryptographyInteractor.Encrypt(request.Password); + + if (passCryp.Equals(hasUser.Password)) + throw new Exception("senha invalida"); + + var token = _authentication.CreateToken(hasUser); + + return new LoginResponse(token); + }); + } + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/AuthenticationService/Register/IRegisterUserService.cs b/bookstoreManager/BookstoreManager.Aplication/AuthenticationService/Register/IRegisterUserService.cs new file mode 100644 index 00000000..2bf2e08e --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/AuthenticationService/Register/IRegisterUserService.cs @@ -0,0 +1,9 @@ +using BookstoreManager.Domain.dto.authenticationDto; + +namespace BookstoreManager.Application.AuthenticationService.Register +{ + public interface IRegisterUserService + { + Task Register(RegisterUserRequest request); + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/AuthenticationService/Register/RegisterUserService.cs b/bookstoreManager/BookstoreManager.Aplication/AuthenticationService/Register/RegisterUserService.cs new file mode 100644 index 00000000..bb156220 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/AuthenticationService/Register/RegisterUserService.cs @@ -0,0 +1,45 @@ +using BookstoreManager.Application.Interactor; +using BookstoreManager.Domain.dto.authenticationDto; +using BookstoreManager.Domain.Entities; +using BookstoreManager.Repository.Interface; +using FluentValidation; + +namespace BookstoreManager.Application.AuthenticationService.Register +{ + public class RegisterUserService : IRegisterUserService + { + private readonly IUserRepository _userRepository; + + private readonly IValidator _validator; + public RegisterUserService(IUserRepository userRepository, + IValidator validator) + { + _userRepository = userRepository; + + _validator = validator; + } + public async Task Register(RegisterUserRequest request) + { + #region ValidatorRequest + var validator = _validator.Validate(request); + + if (!validator.IsValid) + throw new Exception(string.Join(",", validator.Errors.Select(x => x.ErrorMessage))); + #endregion + + var passCryp = CryptographyInteractor.Encrypt(request.Password); + + var user = new User + { + Name = request.Name, + Sobrenome = request.Sobrenome, + Email = request.Email, + Password =passCryp, + Active = true + }; + await _userRepository.Add(user); + + return new RegisterUSerResponse("Usuario cadastrado com sucesso!"); + } + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Delete/IRemoveBookService.cs b/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Delete/IRemoveBookService.cs new file mode 100644 index 00000000..ddae60f2 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Delete/IRemoveBookService.cs @@ -0,0 +1,11 @@ + + +using BookstoreManager.Domain.dto.update; + +namespace BookstoreManager.Application.BookService.Command.Delete +{ + public interface IRemoveBookService + { + Task Remove(int id); + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Delete/RemoveBookService.cs b/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Delete/RemoveBookService.cs new file mode 100644 index 00000000..288bb16f --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Delete/RemoveBookService.cs @@ -0,0 +1,22 @@ +using BookstoreManager.Domain.dto.update; +using BookstoreManager.Repository.Interface; + +namespace BookstoreManager.Application.BookService.Command.Delete +{ + public class RemoveBookService : IRemoveBookService + { + private readonly IBookRepository _bookRepository; + public RemoveBookService(IBookRepository bookRepository) + { + _bookRepository = bookRepository; + } + public async Task Remove(int id) + { + var checkHas = await _bookRepository.GetByIdAsync(id); + + _bookRepository.Delete(checkHas); + + return new UpdateResponse("atualizado com sucesso !"); + } + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Register/IRegisterBookService.cs b/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Register/IRegisterBookService.cs new file mode 100644 index 00000000..c0c0a2bf --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Register/IRegisterBookService.cs @@ -0,0 +1,9 @@ +using BookstoreManager.Domain.dto.register; + +namespace BookstoreManager.Application.BookService.Command.Register +{ + public interface IRegisterBookService + { + Task Register(RegisterRequest request); + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Register/RegisterBookService.cs b/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Register/RegisterBookService.cs new file mode 100644 index 00000000..49d0cdef --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Register/RegisterBookService.cs @@ -0,0 +1,40 @@ +using BookstoreManager.Domain.dto.register; +using BookstoreManager.Repository.Interface; +using FluentValidation; + +namespace BookstoreManager.Application.BookService.Command.Register +{ + public class RegisterBookService : IRegisterBookService + { + private readonly IBookRepository _bookRepository; + private readonly IValidator _validator; + public RegisterBookService(IBookRepository bookRepository, IValidator validator) + { + _bookRepository = bookRepository; + _validator = validator; + } + + public async Task Register(RegisterRequest request) + { + #region ValidatorRequest + var validator = _validator.Validate(request); + + if (!validator.IsValid) + return new RegisterResponse(string.Join(",", validator.Errors.Select(x => x.ErrorMessage))); + #endregion + + var book = new Domain.Entities.Book + { + Name = request.Name, + Description = request.Description, + Author = request.Author, + Active = true, + CreateAt = DateTime.Now, + }; + + await _bookRepository.Add(book); + + return new RegisterResponse("cadastrado com sucesso !"); + } + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Update/IUpdateBookService.cs b/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Update/IUpdateBookService.cs new file mode 100644 index 00000000..32d5e72b --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Update/IUpdateBookService.cs @@ -0,0 +1,9 @@ +using BookstoreManager.Domain.dto.update; + +namespace BookstoreManager.Application.BookService.Command.Update +{ + public interface IUpdateBookService + { + Task Update(UpdateRequest request); + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Update/UpdateBookService.cs b/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Update/UpdateBookService.cs new file mode 100644 index 00000000..787bb5a2 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/BookService/Command/Update/UpdateBookService.cs @@ -0,0 +1,46 @@ +using BookstoreManager.Application.Validator.bookValidator; +using BookstoreManager.Domain.dto.update; +using BookstoreManager.Domain.Entities; +using BookstoreManager.Repository.Interface; +using FluentValidation; + +namespace BookstoreManager.Application.BookService.Command.Update +{ + public class UpdateBookService : IUpdateBookService + { + private readonly IBookRepository _bookRepository; + private readonly IValidator _validator; + public UpdateBookService(IBookRepository bookRepository, + IValidator validator) + { + _bookRepository = bookRepository; + _validator = validator; + } + public async Task Update(UpdateRequest request) + { + #region ValidatorRequest + var validator = _validator.Validate(new CheckhasId { Id = request.Id }); + + if (!validator.IsValid) + return new UpdateResponse(string.Join(",", validator.Errors.Select(x => x.ErrorMessage))); + #endregion + + + var checkHasBook = await _bookRepository.GetByIdAsync(request.Id); + + + checkHasBook.Name = request.Name ?? checkHasBook.Name; + checkHasBook.Description = request.Description ?? checkHasBook.Description; + checkHasBook.Author = request.Author ?? checkHasBook.Author; + checkHasBook.CreateAt = checkHasBook.CreateAt; + checkHasBook.UpdateAt = DateTime.Now; + checkHasBook.Active = request.Active ; + + + + _bookRepository.Update(checkHasBook); + + return new UpdateResponse("atualizado com sucesso"); + } + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/BookService/Querie/GetAll/GetAllBookService.cs b/bookstoreManager/BookstoreManager.Aplication/BookService/Querie/GetAll/GetAllBookService.cs new file mode 100644 index 00000000..f05e9bfd --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/BookService/Querie/GetAll/GetAllBookService.cs @@ -0,0 +1,43 @@ +using BookstoreManager.Domain.dto.GetAll; +using BookstoreManager.Repository.Interface; + +namespace BookstoreManager.Application.BookService.Querie.GetAll +{ + public class GetAllBookService : IGetAllBookService + { + + private readonly IBookRepository _bookRepository; + public GetAllBookService(IBookRepository bookRepository) + { + _bookRepository = bookRepository; + + } + public async Task> GetAll(GetAllBookRequest request) + { + return await Task.Run(() => + { + var books = _bookRepository.GetAll() + .Where(e => ((string.IsNullOrEmpty(request.Search) || + e.Name.Contains(request.Search) || + e.Author.Contains(request.Search) || + e.Description.Contains(request.Search)) && + e.Active)) + .Select(res => new GetAllBookResponse + { + Id = res.Id, + Name = res.Name, + Description = res.Description, + Genre = res.Genre, + Author = res.Author, + CreateAt = res.CreateAt, + UpdateAt = res.UpdateAt + }).Skip((request.Page - 1) * request.PageSize) + .Take(request.PageSize).ToList(); + + books.OrderBy(n => n.Name); + + return books; + }); + } + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/BookService/Querie/GetAll/IGetAllBookService.cs b/bookstoreManager/BookstoreManager.Aplication/BookService/Querie/GetAll/IGetAllBookService.cs new file mode 100644 index 00000000..43b4f1d2 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/BookService/Querie/GetAll/IGetAllBookService.cs @@ -0,0 +1,9 @@ +using BookstoreManager.Domain.dto.GetAll; + +namespace BookstoreManager.Application.BookService.Querie.GetAll +{ + public interface IGetAllBookService + { + Task> GetAll(GetAllBookRequest request); + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/BookstoreManager.Application.csproj b/bookstoreManager/BookstoreManager.Aplication/BookstoreManager.Application.csproj new file mode 100644 index 00000000..1a031cd0 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/BookstoreManager.Application.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + enable + enable + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/bookstoreManager/BookstoreManager.Aplication/DependencyInjection.cs b/bookstoreManager/BookstoreManager.Aplication/DependencyInjection.cs new file mode 100644 index 00000000..4d783743 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/DependencyInjection.cs @@ -0,0 +1,45 @@ +using BookstoreManager.Application.Authentication.Login; +using BookstoreManager.Application.AuthenticationService.Register; +using BookstoreManager.Application.BookService.Command.Delete; +using BookstoreManager.Application.BookService.Command.Register; +using BookstoreManager.Application.BookService.Command.Update; +using BookstoreManager.Application.BookService.Querie.GetAll; +using BookstoreManager.Application.LogErrorService.Command.Delete; +using BookstoreManager.Application.LogErrorService.Command.ToView; +using BookstoreManager.Application.LogErrorService.Querie.GetAll; +using BookstoreManager.Application.LogErrorService.Register; +using BookstoreManager.Application.Validator.AuthenticatorValidator; +using BookstoreManager.Application.Validator.bookValidator; +using BookstoreManager.Application.Validator.LogErrorValidator; +using BookstoreManager.Domain.dto.authenticationDto; +using BookstoreManager.Domain.dto.register; +using FluentValidation; +using Microsoft.Extensions.DependencyInjection; + +namespace BookstoreManager.Application +{ + public static class DependencyInjection + { + public static IServiceCollection AddApplication( + this IServiceCollection services) + { + services.AddScoped(); + services.AddScoped, RegisterCheckRequestValidator>(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped, RegisterCheckRequestValidators>(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped, UpdateCheckHasIdValidator>(); + services.AddScoped, DeleteCheckHasIdValidator>(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + + + return services; + } + } +} \ No newline at end of file diff --git a/bookstoreManager/BookstoreManager.Aplication/Interactor/CryptographyInteractor.cs b/bookstoreManager/BookstoreManager.Aplication/Interactor/CryptographyInteractor.cs new file mode 100644 index 00000000..de14c869 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/Interactor/CryptographyInteractor.cs @@ -0,0 +1,29 @@ +using Microsoft.AspNetCore.Cryptography.KeyDerivation; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace BookstoreManager.Application.Interactor +{ + public class CryptographyInteractor + { + public static string Encrypt(string password) + { + byte[] salt = RandomNumberGenerator.GetBytes(128 / 8); + Console.WriteLine($"Salt: {Convert.ToBase64String(salt)}"); + + string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2( + password: password!, + salt: salt, + prf: KeyDerivationPrf.HMACSHA256, + iterationCount: 100000, + numBytesRequested: 256 / 8)); + return hashed; + } + + + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/Interactor/interface/ICryptographyInteractor.cs b/bookstoreManager/BookstoreManager.Aplication/Interactor/interface/ICryptographyInteractor.cs new file mode 100644 index 00000000..361f033e --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/Interactor/interface/ICryptographyInteractor.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookstoreManager.Application.Interactor +{ + public interface ICryptographyInteractor + { + + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/Delete/DeleteErrorService.cs b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/Delete/DeleteErrorService.cs new file mode 100644 index 00000000..6822f45c --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/Delete/DeleteErrorService.cs @@ -0,0 +1,38 @@ +using BookstoreManager.Application.Validator.bookValidator; +using BookstoreManager.Application.Validator.LogErrorValidator; +using BookstoreManager.Domain.dto.ErrorDto; +using BookstoreManager.Repository.Interface; +using FluentValidation; + +namespace BookstoreManager.Application.LogErrorService.Command.Delete +{ + public class DeleteErrorService : IDeleteErrorService + { + private readonly ILogErrorRepository _logErrorRepository; + private readonly IValidator _validator; + public DeleteErrorService(ILogErrorRepository logErrorRepository, + IValidator validator) + { + _logErrorRepository = logErrorRepository; + _validator = validator; + } + + public async Task Delete(int id) + { + + #region ValidatorRequest + var validator = _validator.Validate(new CheckhasIdDeleteRequest { Id = id }); + + if (!validator.IsValid) + return new DeleteErrorResponse(string.Join(",", validator.Errors.Select(x => x.ErrorMessage))); + #endregion + + var errorLog = await _logErrorRepository.GetByIdAsync(id); + _logErrorRepository.Delete(errorLog); + + + return new DeleteErrorResponse("deletado com sucesso!"); + + } + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/Delete/IDeleteErrorService.cs b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/Delete/IDeleteErrorService.cs new file mode 100644 index 00000000..ceb520a0 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/Delete/IDeleteErrorService.cs @@ -0,0 +1,14 @@ +using BookstoreManager.Domain.dto.ErrorDto; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookstoreManager.Application.LogErrorService.Command.Delete +{ + public interface IDeleteErrorService + { + Task Delete(int id); + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/Register/IRegisterLogErrorService.cs b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/Register/IRegisterLogErrorService.cs new file mode 100644 index 00000000..06dd64e2 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/Register/IRegisterLogErrorService.cs @@ -0,0 +1,7 @@ +namespace BookstoreManager.Application.LogErrorService.Register +{ + public interface IRegisterLogErrorService + { + Task Register(string Message); + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/Register/RegisterLogErrorService.cs b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/Register/RegisterLogErrorService.cs new file mode 100644 index 00000000..7cc0438a --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/Register/RegisterLogErrorService.cs @@ -0,0 +1,25 @@ +using BookstoreManager.Domain.Entities; +using BookstoreManager.Repository.Interface; + +namespace BookstoreManager.Application.LogErrorService.Register +{ + public class RegisterLogErrorService : IRegisterLogErrorService + { + private readonly ILogErrorRepository _logErrorRepository; + public RegisterLogErrorService(ILogErrorRepository logErrorRepository) + { + _logErrorRepository = logErrorRepository; + } + public async Task Register(string Message) + { + + var error = new LogError + { + Message = Message, + Visualized = false + }; + + await _logErrorRepository.Add(error); + } + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/ToView/IViewLogErrorService.cs b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/ToView/IViewLogErrorService.cs new file mode 100644 index 00000000..69412586 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/ToView/IViewLogErrorService.cs @@ -0,0 +1,9 @@ +using BookstoreManager.Domain.dto.ErrorDto; + +namespace BookstoreManager.Application.LogErrorService.Command.ToView +{ + public interface IViewLogErrorService + { + Task ToView(int id); + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/ToView/ViewLogErrorService.cs b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/ToView/ViewLogErrorService.cs new file mode 100644 index 00000000..1094fef3 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Command/ToView/ViewLogErrorService.cs @@ -0,0 +1,27 @@ +using BookstoreManager.Domain.dto.ErrorDto; +using BookstoreManager.Repository.Interface; + +namespace BookstoreManager.Application.LogErrorService.Command.ToView +{ + public class ViewLogErrorService : IViewLogErrorService + { + private readonly ILogErrorRepository _logErrorRepository; + public ViewLogErrorService(ILogErrorRepository logErrorRepository) + { + _logErrorRepository = logErrorRepository; + } + public async Task ToView(int id) + { + + var haslog = await _logErrorRepository.GetByIdAsync(id); + + haslog.UpdateAt = DateTime.Now; + + await _logErrorRepository.Update(haslog); + + + return new ViewLogErrorResponse { Id = haslog.Id, Message = haslog.Message, CreateAt = haslog.CreateAt }; + + } + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Querie/GetAll/GetAllLogErrorService.cs b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Querie/GetAll/GetAllLogErrorService.cs new file mode 100644 index 00000000..12f71790 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Querie/GetAll/GetAllLogErrorService.cs @@ -0,0 +1,38 @@ +using BookstoreManager.Domain.dto.ErrorDto; +using BookstoreManager.Repository.Interface; + +namespace BookstoreManager.Application.LogErrorService.Querie.GetAll +{ + public class GetAllLogErrorService : IGetAllLogErrorService + { + + private readonly ILogErrorRepository _logErrorRepository; + public GetAllLogErrorService(ILogErrorRepository logErrorRepository) + { + _logErrorRepository = logErrorRepository; + } + + public async Task> GetAll(GetAllErrorLogRequest request) + { + + return await Task.Run(() => + { + var logs = _logErrorRepository.GetAll() + .Where(log => (string.IsNullOrEmpty(request.Search) || + log.Message.Contains(request.Search)) && + !log.Visualized) + .Select(res => new GetAllLogErrorResponse + { + Id = res.Id, + Message = res.Message, + CreateAt = res.CreateAt, + UpdateAt = res.UpdateAt + + }).Skip((request.Page - 1) * request.PageSize) + .Take(request.PageSize).ToList(); + + return logs.ToList(); + }); + } + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Querie/GetAll/IGetAllLogErrorService.cs b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Querie/GetAll/IGetAllLogErrorService.cs new file mode 100644 index 00000000..d29bde94 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/LogErrorService/Querie/GetAll/IGetAllLogErrorService.cs @@ -0,0 +1,9 @@ +using BookstoreManager.Domain.dto.ErrorDto; + +namespace BookstoreManager.Application.LogErrorService.Querie.GetAll +{ + public interface IGetAllLogErrorService + { + Task> GetAll(GetAllErrorLogRequest request); + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/Validator/AuthenticatorValidator/RegisterCheckRequestValidators.cs b/bookstoreManager/BookstoreManager.Aplication/Validator/AuthenticatorValidator/RegisterCheckRequestValidators.cs new file mode 100644 index 00000000..5ea71cd4 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/Validator/AuthenticatorValidator/RegisterCheckRequestValidators.cs @@ -0,0 +1,42 @@ +using BookstoreManager.Domain.dto.authenticationDto; +using BookstoreManager.Repository.Interface; +using FluentValidation; + +namespace BookstoreManager.Application.Validator.AuthenticatorValidator +{ + public class RegisterCheckRequestValidators : AbstractValidator + { + private readonly IUserRepository _userRespository; + public RegisterCheckRequestValidators(IUserRepository userRespository) + { + _userRespository = userRespository; + + RuleFor(e => e.Name) + .NotEmpty().WithMessage("preencha o nome ") + .NotNull().WithMessage("preencha o nome"); + + RuleFor(e => e.Sobrenome) + .NotEmpty().WithMessage("preencha o sobrenome ") + .NotNull().WithMessage("preencha o sobrenome "); + + RuleFor(e => e.Password) + .NotEmpty().WithMessage("preencha o password ") + .NotNull().WithMessage("preencha o password "); + + RuleFor(e => e.Email) + .NotNull().WithMessage("preencha o email ") + .NotEmpty().WithMessage("preencha o email ") + .Must(CheckEmail).WithMessage("email ja existente"); + + RuleFor(e => e.ConfirmPassword) + .Equal(e => e.Password); + } + + public bool CheckEmail(string email) + { + var result = _userRespository.GetByEmail(email); + + return result != null; + } + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/Validator/LogErrorValidator/DeleteCheckHasIdValidator.cs b/bookstoreManager/BookstoreManager.Aplication/Validator/LogErrorValidator/DeleteCheckHasIdValidator.cs new file mode 100644 index 00000000..332b04a2 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/Validator/LogErrorValidator/DeleteCheckHasIdValidator.cs @@ -0,0 +1,33 @@ +using BookstoreManager.Repository.Interface; +using FluentValidation; + +namespace BookstoreManager.Application.Validator.LogErrorValidator +{ + public class CheckhasIdDeleteRequest + { + public int Id { get; set; } + } + public class DeleteCheckHasIdValidator : AbstractValidator + { + private readonly ILogErrorRepository _logErrorRepository; + public DeleteCheckHasIdValidator(ILogErrorRepository logErrorRepository) + { + _logErrorRepository = logErrorRepository; + + RuleFor(e => e.Id) + .NotEmpty() + .NotEqual(0) + .Must(chekHasBook).WithMessage("error não existente"); + } + + public bool chekHasBook(int id) + { + var result = _logErrorRepository.GetById(id); + + if (result == null) + return false; + + return true; + } + } +} diff --git a/bookstoreManager/BookstoreManager.Aplication/Validator/bookValidator/RegisterCheckRequestValidator.cs b/bookstoreManager/BookstoreManager.Aplication/Validator/bookValidator/RegisterCheckRequestValidator.cs new file mode 100644 index 00000000..85d88d00 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/Validator/bookValidator/RegisterCheckRequestValidator.cs @@ -0,0 +1,35 @@ +using BookstoreManager.Domain.dto.register; +using BookstoreManager.Repository.Interface; +using FluentValidation; + +namespace BookstoreManager.Application.Validator.bookValidator +{ + public class RegisterCheckRequestValidator : AbstractValidator + { + private readonly IBookRepository _bookRepository; + public RegisterCheckRequestValidator(IBookRepository bookRepository) + { + _bookRepository = bookRepository; + + RuleFor(n => n.Name) + .NotNull().WithMessage("Preencha o campo") + .Must(CheckHasName).WithMessage("Categoria já existente"); + + RuleFor(n => n.Description) + .NotNull().WithMessage("preencha o campo Descricão"); + + RuleFor(n => n.Genre) + .NotNull().WithMessage("preencha o campo genero"); + + RuleFor(n => n.Author) + .NotNull().WithMessage("preencha o campo autor"); + } + + public bool CheckHasName(string name) + { + var book = _bookRepository.GetByName(name); + + return book == null; + } + } +} \ No newline at end of file diff --git a/bookstoreManager/BookstoreManager.Aplication/Validator/bookValidator/UpdateCheckHasIdValidator.cs b/bookstoreManager/BookstoreManager.Aplication/Validator/bookValidator/UpdateCheckHasIdValidator.cs new file mode 100644 index 00000000..e2e0b6c8 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Aplication/Validator/bookValidator/UpdateCheckHasIdValidator.cs @@ -0,0 +1,34 @@ +using BookstoreManager.Repository.Interface; +using FluentValidation; + +namespace BookstoreManager.Application.Validator.bookValidator +{ + public class CheckhasId + { + public int Id { get; set; } + } + public class UpdateCheckHasIdValidator: AbstractValidator + { + private readonly IBookRepository _bookRepository; + public UpdateCheckHasIdValidator(IBookRepository bookRepository) + { + _bookRepository = bookRepository; + + RuleFor(e => e.Id) + .NotEmpty() + .NotEqual(0) + .Must(chekHasBook).WithMessage("book nao existente"); + + } + + public bool chekHasBook(int id) + { + var result = _bookRepository.GetById(id); + + if (result == null) + return false; + + return true; + } + } +} diff --git a/bookstoreManager/BookstoreManager.Domain/BookstoreManager.Domain.csproj b/bookstoreManager/BookstoreManager.Domain/BookstoreManager.Domain.csproj new file mode 100644 index 00000000..1225a98e --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/BookstoreManager.Domain.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/bookstoreManager/BookstoreManager.Domain/Entities/Book.cs b/bookstoreManager/BookstoreManager.Domain/Entities/Book.cs new file mode 100644 index 00000000..d45b8170 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/Entities/Book.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations; + +namespace BookstoreManager.Domain.Entities +{ + public class Book + { + [Key] + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; + public string Genre { get; set; } = string.Empty; + public string Author { get; set; } = string.Empty; + public bool Active { get; set; } + public DateTime CreateAt { get; set; } + public DateTime? UpdateAt { get; set; } + } +} diff --git a/bookstoreManager/BookstoreManager.Domain/Entities/LogError.cs b/bookstoreManager/BookstoreManager.Domain/Entities/LogError.cs new file mode 100644 index 00000000..84ed08f8 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/Entities/LogError.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; + +namespace BookstoreManager.Domain.Entities +{ + public class LogError + { + [Key] + public int Id { get; set; } + public string Message { get; set; } = String.Empty; + public int? UserId { get; set; } + public DateTime CreateAt { get; set; } + public DateTime? UpdateAt { get; set; } + public bool Visualized { get; set; } + } +} diff --git a/bookstoreManager/BookstoreManager.Domain/Entities/User.cs b/bookstoreManager/BookstoreManager.Domain/Entities/User.cs new file mode 100644 index 00000000..31afbfde --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/Entities/User.cs @@ -0,0 +1,18 @@ + using System.ComponentModel.DataAnnotations; + +namespace BookstoreManager.Domain.Entities +{ + public class User + { + [Key] + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + public string Sobrenome { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public bool Active { get; set; } + public DateTime CreateAt { get; set; } + public DateTime UpdateAt { get; set; } + + } +} \ No newline at end of file diff --git a/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/GetAll/GetAllBookRequest.cs b/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/GetAll/GetAllBookRequest.cs new file mode 100644 index 00000000..7fa4d37a --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/GetAll/GetAllBookRequest.cs @@ -0,0 +1,10 @@ +namespace BookstoreManager.Domain.dto.GetAll +{ + public class GetAllBookRequest + { + public string? Search { get; set; } + public int Page { get; set; } + public int PageSize { get; set; } + } + +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/GetAll/GetAllBookResponse.cs b/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/GetAll/GetAllBookResponse.cs new file mode 100644 index 00000000..2311af0c --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/GetAll/GetAllBookResponse.cs @@ -0,0 +1,14 @@ +namespace BookstoreManager.Domain.dto.GetAll +{ + public class GetAllBookResponse + { + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; + public string Genre { get; set; } = string.Empty; + public string Author { get; set; } = string.Empty; + public bool Active { get; set; } + public DateTime CreateAt { get; set; } + public DateTime? UpdateAt { get; set; } + } +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/register/RegisterRequest.cs b/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/register/RegisterRequest.cs new file mode 100644 index 00000000..213f3fb1 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/register/RegisterRequest.cs @@ -0,0 +1,6 @@ +namespace BookstoreManager.Domain.dto.register +{ + public record RegisterRequest(string Name, string Description, string Genre, string Author); + + +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/register/RegisterResponse.cs b/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/register/RegisterResponse.cs new file mode 100644 index 00000000..96ff9914 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/register/RegisterResponse.cs @@ -0,0 +1,7 @@ + + +namespace BookstoreManager.Domain.dto.register +{ + public record RegisterResponse(string Message); + +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/update/UpdateRequest.cs b/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/update/UpdateRequest.cs new file mode 100644 index 00000000..1004e2cb --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/update/UpdateRequest.cs @@ -0,0 +1,10 @@ +namespace BookstoreManager.Domain.dto.update +{ + public record UpdateRequest(int Id , + string Name, + string Description, + string Genre, + string Author, + bool Active); + +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/update/UpdateResponse.cs b/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/update/UpdateResponse.cs new file mode 100644 index 00000000..0c30831f --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/BookDtos/update/UpdateResponse.cs @@ -0,0 +1,5 @@ +namespace BookstoreManager.Domain.dto.update +{ + public record UpdateResponse(string Message); + +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/ErrorDto/DeleteErrorResponse.cs b/bookstoreManager/BookstoreManager.Domain/dto/ErrorDto/DeleteErrorResponse.cs new file mode 100644 index 00000000..0841f62d --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/ErrorDto/DeleteErrorResponse.cs @@ -0,0 +1,5 @@ +namespace BookstoreManager.Domain.dto.ErrorDto +{ + public record DeleteErrorResponse(string Message); + +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/ErrorDto/GetAllErrorLogRequest.cs b/bookstoreManager/BookstoreManager.Domain/dto/ErrorDto/GetAllErrorLogRequest.cs new file mode 100644 index 00000000..5db0329c --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/ErrorDto/GetAllErrorLogRequest.cs @@ -0,0 +1,9 @@ +namespace BookstoreManager.Domain.dto.ErrorDto +{ + public class GetAllErrorLogRequest + { + public string? Search { get; set; } + public int Page { get; set; } + public int PageSize { get; set; } + } +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/ErrorDto/GetAllLogErrorResponse.cs b/bookstoreManager/BookstoreManager.Domain/dto/ErrorDto/GetAllLogErrorResponse.cs new file mode 100644 index 00000000..44d5a1c8 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/ErrorDto/GetAllLogErrorResponse.cs @@ -0,0 +1,10 @@ +namespace BookstoreManager.Domain.dto.ErrorDto +{ + public class GetAllLogErrorResponse + { + public int Id { get; set; } + public string Message { get; set; } = String.Empty; + public DateTime CreateAt { get; set; } + public DateTime? UpdateAt { get; set; } + } +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/ErrorDto/ViewLogErrorResponse.cs b/bookstoreManager/BookstoreManager.Domain/dto/ErrorDto/ViewLogErrorResponse.cs new file mode 100644 index 00000000..7b8e9b8d --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/ErrorDto/ViewLogErrorResponse.cs @@ -0,0 +1,10 @@ +namespace BookstoreManager.Domain.dto.ErrorDto +{ + public class ViewLogErrorResponse + { + public int Id { get; set; } + public string Message { get; set; } = String.Empty; + public DateTime CreateAt { get; set; } + }; + +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/authenticationDto/LoginRequest.cs b/bookstoreManager/BookstoreManager.Domain/dto/authenticationDto/LoginRequest.cs new file mode 100644 index 00000000..6484ddbb --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/authenticationDto/LoginRequest.cs @@ -0,0 +1,14 @@ +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace BookstoreManager.Domain.dto.authenticationDto +{ + public class LoginRequest + { + public string Email { get; set; }= string.Empty; + public string Password{ get; set; }= string.Empty; + [DataType(DataType.Password)] + [DisplayName("Confirm Password:")] + public string ConfirmPassword{ get; set; }= string.Empty; + } +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/authenticationDto/LoginResponse.cs b/bookstoreManager/BookstoreManager.Domain/dto/authenticationDto/LoginResponse.cs new file mode 100644 index 00000000..224a2d53 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/authenticationDto/LoginResponse.cs @@ -0,0 +1,5 @@ +namespace BookstoreManager.Domain.dto.authenticationDto +{ + public record LoginResponse(string Token); + +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/authenticationDto/RegisterUSerResponse.cs b/bookstoreManager/BookstoreManager.Domain/dto/authenticationDto/RegisterUSerResponse.cs new file mode 100644 index 00000000..54aa3025 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/authenticationDto/RegisterUSerResponse.cs @@ -0,0 +1,5 @@ +namespace BookstoreManager.Domain.dto.authenticationDto +{ + public record RegisterUSerResponse(string Message); + +} diff --git a/bookstoreManager/BookstoreManager.Domain/dto/authenticationDto/RegisterUserRequest.cs b/bookstoreManager/BookstoreManager.Domain/dto/authenticationDto/RegisterUserRequest.cs new file mode 100644 index 00000000..9e74ca99 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Domain/dto/authenticationDto/RegisterUserRequest.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookstoreManager.Domain.dto.authenticationDto +{ + public class RegisterUserRequest + { + public string Name { get; set; } = string.Empty; + public string Sobrenome { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public string ConfirmPassword { get; set; } = string.Empty; + + } +} diff --git a/bookstoreManager/BookstoreManager.Repository/BookstoreManager.Repository.csproj b/bookstoreManager/BookstoreManager.Repository/BookstoreManager.Repository.csproj new file mode 100644 index 00000000..9979921c --- /dev/null +++ b/bookstoreManager/BookstoreManager.Repository/BookstoreManager.Repository.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/bookstoreManager/BookstoreManager.Repository/DependencyInjection.cs b/bookstoreManager/BookstoreManager.Repository/DependencyInjection.cs new file mode 100644 index 00000000..8576cb38 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Repository/DependencyInjection.cs @@ -0,0 +1,18 @@ +using BookstoreManager.Repository.Interface; +using BookstoreManager.Repository.Repositories; +using Microsoft.Extensions.DependencyInjection; + +namespace BookstoreManager.Repository +{ + public static class DependencyInjection + { public static IServiceCollection AddInfrastruture( + this IServiceCollection services) + { + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddScoped(); + return services; + } + } +} \ No newline at end of file diff --git a/bookstoreManager/BookstoreManager.Repository/Interface/IAuthentication.cs b/bookstoreManager/BookstoreManager.Repository/Interface/IAuthentication.cs new file mode 100644 index 00000000..ec0703d6 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Repository/Interface/IAuthentication.cs @@ -0,0 +1,9 @@ +using BookstoreManager.Domain.Entities; + +namespace BookstoreManager.Repository.Interface +{ + public interface IAuthentication + { + public string CreateToken(User users); + } +} diff --git a/bookstoreManager/BookstoreManager.Repository/Interface/IBookRepository.cs b/bookstoreManager/BookstoreManager.Repository/Interface/IBookRepository.cs new file mode 100644 index 00000000..f77f0197 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Repository/Interface/IBookRepository.cs @@ -0,0 +1,16 @@ +using BookstoreManager.Domain.Entities; + +namespace BookstoreManager.Repository.Interface +{ + public interface IBookRepository + { + Task Add(Book book); + void Delete(Book book); + void Update(Book book); + IEnumerable GetAll(); + Task GetByIdAsync(int id); + Book GetById(int id); + Book? GetByName(string name); + + } +} diff --git a/bookstoreManager/BookstoreManager.Repository/Interface/ILogErrorRepository.cs b/bookstoreManager/BookstoreManager.Repository/Interface/ILogErrorRepository.cs new file mode 100644 index 00000000..54d3a524 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Repository/Interface/ILogErrorRepository.cs @@ -0,0 +1,14 @@ +using BookstoreManager.Domain.Entities; + +namespace BookstoreManager.Repository.Interface +{ + public interface ILogErrorRepository + { + public Task Add(LogError Error); + public Task GetByIdAsync(int id); + public IEnumerable GetAll(); + public Task Update(LogError error); + public void Delete(LogError error); + public LogError GetById(int id); + } +} diff --git a/bookstoreManager/BookstoreManager.Repository/Interface/IUserRepository.cs b/bookstoreManager/BookstoreManager.Repository/Interface/IUserRepository.cs new file mode 100644 index 00000000..b4a9a538 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Repository/Interface/IUserRepository.cs @@ -0,0 +1,14 @@ +using BookstoreManager.Domain.Entities; + +namespace BookstoreManager.Repository.Interface +{ + public interface IUserRepository + { + Task Add(User user); + void Delete(User user); + void Update(User user); + IEnumerable GetAll(User user); + Task GetById(int id); + User GetByEmail(string email); + } +} diff --git a/bookstoreManager/BookstoreManager.Repository/Repositories/BookRepository.cs b/bookstoreManager/BookstoreManager.Repository/Repositories/BookRepository.cs new file mode 100644 index 00000000..ae4b2c82 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Repository/Repositories/BookRepository.cs @@ -0,0 +1,60 @@ +using BookstoreManager.Domain.Entities; +using BookstoreManager.Repository.Interface; +using BookststorageManager.Data.Data; + +namespace BookstoreManager.Repository.Repositories +{ + public class BookRepository : IBookRepository + { + private readonly DataContext _dataContext; + public BookRepository(DataContext dataContext) + { + _dataContext = dataContext; + } + public async Task Add(Book book) + { + await _dataContext.Books.AddAsync(book); + await _dataContext.SaveChangesAsync(); + + } + + public void Delete(Book book) + { + _dataContext.Books.Remove(book); + } + + public IEnumerable GetAll() + { + var result = _dataContext.Books.AsEnumerable(); + return result; + } + + public async Task GetByIdAsync(int id) + { + var result = await _dataContext.Books.FindAsync(id); + + if(result == null) + return new Book(); + return result; + } + public Book GetById(int id) + { + var result = _dataContext.Books.Find(id); + + if (result == null) + return new Book(); + return result; + } + + public void Update(Book book) + { + _dataContext.Books.Update(book); + _dataContext.SaveChanges(); + } + public Book? GetByName(string name) + { + return _dataContext.Books.FirstOrDefault(x => x.Name.Equals(name)); + + } + } +} diff --git a/bookstoreManager/BookstoreManager.Repository/Repositories/JwtServicesRepository.cs b/bookstoreManager/BookstoreManager.Repository/Repositories/JwtServicesRepository.cs new file mode 100644 index 00000000..f4088ead --- /dev/null +++ b/bookstoreManager/BookstoreManager.Repository/Repositories/JwtServicesRepository.cs @@ -0,0 +1,42 @@ +using BookstoreManager.Domain.Entities; +using BookstoreManager.Repository.Interface; +using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using System.Text; + +namespace BookstoreManager.Repository.Repositories +{ + public class JwtServicesRepository : IAuthentication + { + private readonly IConfiguration _config; + + public JwtServicesRepository(IConfiguration config) + { + _config = config; + } + public string CreateToken(User users) + { + var secret = Encoding.ASCII.GetBytes(_config.GetSection("JwtConfigurations:Secret").Value); + var key = new SymmetricSecurityKey(secret); + var cred = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature); + var securityTokenDcptor = new SecurityTokenDescriptor + { + Subject = new ClaimsIdentity(new Claim[] + { + new Claim(ClaimTypes.NameIdentifier, users.Id.ToString()), + new Claim(ClaimTypes.Name, users.Name) + }), + Expires = DateTime.UtcNow.AddHours(4), + SigningCredentials = cred, + + }; + var tokenHandler = new JwtSecurityTokenHandler(); + var tokenGenerated = tokenHandler.CreateToken(securityTokenDcptor); + var token = tokenHandler.WriteToken(tokenGenerated); + return token; + + } + } +} diff --git a/bookstoreManager/BookstoreManager.Repository/Repositories/LogErrorRepository.cs b/bookstoreManager/BookstoreManager.Repository/Repositories/LogErrorRepository.cs new file mode 100644 index 00000000..de1ae60d --- /dev/null +++ b/bookstoreManager/BookstoreManager.Repository/Repositories/LogErrorRepository.cs @@ -0,0 +1,54 @@ +using BookstoreManager.Domain.Entities; +using BookstoreManager.Repository.Interface; +using BookststorageManager.Data.Data; + +namespace BookstoreManager.Repository.Repositories +{ + public class LogErrorRepository : ILogErrorRepository + { + private readonly DataContext _dataContext; + public LogErrorRepository(DataContext dataContext) + { + _dataContext = dataContext; + } + + public async Task Add(LogError Error) + { + await _dataContext.AddAsync(Error); + await _dataContext.SaveChangesAsync(); + + } + + public IEnumerable GetAll() + { + var result = _dataContext.LogErrors.AsEnumerable(); + return result; + } + + public async Task GetByIdAsync(int id) + { + var result = await _dataContext.LogErrors.FindAsync(id); + if (result == null) + return new LogError(); + return result; + } + public LogError GetById(int id) + { + var result = _dataContext.LogErrors.Find(id); + if (result == null) + return new LogError(); + return result; + } + + public async Task Update(LogError error) + { + _dataContext.LogErrors.Update(error); + await _dataContext.SaveChangesAsync(); + } + public void Delete(LogError error) + { + _dataContext.LogErrors.Remove(error); + + } + } +} diff --git a/bookstoreManager/BookstoreManager.Repository/Repositories/UserRepository.cs b/bookstoreManager/BookstoreManager.Repository/Repositories/UserRepository.cs new file mode 100644 index 00000000..c17bcab9 --- /dev/null +++ b/bookstoreManager/BookstoreManager.Repository/Repositories/UserRepository.cs @@ -0,0 +1,53 @@ + +using BookstoreManager.Domain.Entities; +using BookstoreManager.Repository.Interface; +using BookststorageManager.Data.Data; + +namespace BookstoreManager.Repository.Repositories +{ + public class UserRepository : IUserRepository + { + private readonly DataContext _dataContext; + public UserRepository(DataContext dataContext) + { + _dataContext = dataContext; + } + public async Task Add(User user) + { + await _dataContext.Users.AddAsync(user); + await _dataContext.SaveChangesAsync(); + } + + public void Delete(User user) + { + _dataContext.Users.Remove(user); + } + + public IEnumerable GetAll(User user) + { + var result = _dataContext.Users.AsEnumerable(); + return result; + } + + public async Task GetById(int id) + { + var result = await _dataContext.Users.FindAsync(id); + if (result == null) + return new User() ; + return result; + } + public User GetByEmail(string email) + { + + var result = _dataContext.Users.FirstOrDefault(e => e.Email.Trim().Equals(email.Trim())); + if (result == null) + return new User(); + return result; + + } + public void Update(User user) + { + _dataContext.Users.Update(user); + } + } +} diff --git a/bookstoreManager/BookststorageManager.Data/BookststorageManager.Data.csproj b/bookstoreManager/BookststorageManager.Data/BookststorageManager.Data.csproj new file mode 100644 index 00000000..decb36ea --- /dev/null +++ b/bookstoreManager/BookststorageManager.Data/BookststorageManager.Data.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/bookstoreManager/BookststorageManager.Data/Data/DataContext.cs b/bookstoreManager/BookststorageManager.Data/Data/DataContext.cs new file mode 100644 index 00000000..122694b4 --- /dev/null +++ b/bookstoreManager/BookststorageManager.Data/Data/DataContext.cs @@ -0,0 +1,22 @@ +using BookstoreManager.Domain.Entities; +using Microsoft.EntityFrameworkCore; + +namespace BookststorageManager.Data.Data +{ + public class DataContext: DbContext + { + public virtual DbSet Users { get; set; } + public virtual DbSet Books { get; set; } + public virtual DbSet LogErrors { get; set; } + public DataContext(DbContextOptions options) : base(options) { } + + protected override void OnModelCreating(ModelBuilder builder) + { + builder.Entity(); + builder.Entity(); + builder.Entity(); + + base.OnModelCreating(builder); + } + } +} diff --git a/bookstoreManager/BookststorageManager.Data/Migrations/20221116201905_initial.Designer.cs b/bookstoreManager/BookststorageManager.Data/Migrations/20221116201905_initial.Designer.cs new file mode 100644 index 00000000..0d9be678 --- /dev/null +++ b/bookstoreManager/BookststorageManager.Data/Migrations/20221116201905_initial.Designer.cs @@ -0,0 +1,135 @@ +// +using System; +using BookststorageManager.Data.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BookststorageManager.Data.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20221116201905_initial")] + partial class initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BookstoreManager.Domain.Entities.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Active") + .HasColumnType("bit"); + + b.Property("Author") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CreateAt") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Genre") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateAt") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("BookstoreManager.Domain.Entities.LogError", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreateAt") + .HasColumnType("datetime2"); + + b.Property("Message") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateAt") + .HasColumnType("datetime2"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("Visualized") + .HasColumnType("bit"); + + b.HasKey("Id"); + + b.ToTable("LogErrors"); + }); + + modelBuilder.Entity("BookstoreManager.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Active") + .HasColumnType("bit"); + + b.Property("CreateAt") + .HasColumnType("datetime2"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Sobrenome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateAt") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/bookstoreManager/BookststorageManager.Data/Migrations/20221116201905_initial.cs b/bookstoreManager/BookststorageManager.Data/Migrations/20221116201905_initial.cs new file mode 100644 index 00000000..cf5470ec --- /dev/null +++ b/bookstoreManager/BookststorageManager.Data/Migrations/20221116201905_initial.cs @@ -0,0 +1,83 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BookststorageManager.Data.Migrations +{ + /// + public partial class initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Books", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false), + Genre = table.Column(type: "nvarchar(max)", nullable: false), + Author = table.Column(type: "nvarchar(max)", nullable: false), + Active = table.Column(type: "bit", nullable: false), + CreateAt = table.Column(type: "datetime2", nullable: false), + UpdateAt = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Books", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "LogErrors", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Message = table.Column(type: "nvarchar(max)", nullable: false), + UserId = table.Column(type: "int", nullable: true), + CreateAt = table.Column(type: "datetime2", nullable: false), + UpdateAt = table.Column(type: "datetime2", nullable: true), + Visualized = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LogErrors", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Sobrenome = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Active = table.Column(type: "bit", nullable: false), + CreateAt = table.Column(type: "datetime2", nullable: false), + UpdateAt = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Books"); + + migrationBuilder.DropTable( + name: "LogErrors"); + + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/bookstoreManager/BookststorageManager.Data/Migrations/DataContextModelSnapshot.cs b/bookstoreManager/BookststorageManager.Data/Migrations/DataContextModelSnapshot.cs new file mode 100644 index 00000000..365f8a64 --- /dev/null +++ b/bookstoreManager/BookststorageManager.Data/Migrations/DataContextModelSnapshot.cs @@ -0,0 +1,132 @@ +// +using System; +using BookststorageManager.Data.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BookststorageManager.Data.Migrations +{ + [DbContext(typeof(DataContext))] + partial class DataContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BookstoreManager.Domain.Entities.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Active") + .HasColumnType("bit"); + + b.Property("Author") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CreateAt") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Genre") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateAt") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("BookstoreManager.Domain.Entities.LogError", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreateAt") + .HasColumnType("datetime2"); + + b.Property("Message") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateAt") + .HasColumnType("datetime2"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("Visualized") + .HasColumnType("bit"); + + b.HasKey("Id"); + + b.ToTable("LogErrors"); + }); + + modelBuilder.Entity("BookstoreManager.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Active") + .HasColumnType("bit"); + + b.Property("CreateAt") + .HasColumnType("datetime2"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Sobrenome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateAt") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/bookstoreManager/MuriloCurriculo (1).pdf b/bookstoreManager/MuriloCurriculo (1).pdf new file mode 100644 index 00000000..a65af6c3 Binary files /dev/null and b/bookstoreManager/MuriloCurriculo (1).pdf differ diff --git a/bookstoreManager/bookstoreManager.sln b/bookstoreManager/bookstoreManager.sln new file mode 100644 index 00000000..6d07b8df --- /dev/null +++ b/bookstoreManager/bookstoreManager.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32526.322 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookstoreManager.WebApi", "bookstoreManager\BookstoreManager.WebApi.csproj", "{C0637D84-7E7B-4931-B180-11A9C3A69D1D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookstoreManager.Application", "BookstoreManager.Aplication\BookstoreManager.Application.csproj", "{CC0B6982-6516-4305-8033-7EB5A9F8D82E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookstoreManager.Domain", "BookstoreManager.Domain\BookstoreManager.Domain.csproj", "{78A2D592-4FC1-44DB-A73C-E5CC5FD53550}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookststorageManager.Data", "BookststorageManager.Data\BookststorageManager.Data.csproj", "{09D2AFAC-8F1F-430B-AEEF-936D5FFEEB7A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookstoreManager.Repository", "BookstoreManager.Repository\BookstoreManager.Repository.csproj", "{397BDC9F-1699-4932-956B-DDE7ADECA2D8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C0637D84-7E7B-4931-B180-11A9C3A69D1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C0637D84-7E7B-4931-B180-11A9C3A69D1D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C0637D84-7E7B-4931-B180-11A9C3A69D1D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C0637D84-7E7B-4931-B180-11A9C3A69D1D}.Release|Any CPU.Build.0 = Release|Any CPU + {CC0B6982-6516-4305-8033-7EB5A9F8D82E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CC0B6982-6516-4305-8033-7EB5A9F8D82E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CC0B6982-6516-4305-8033-7EB5A9F8D82E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CC0B6982-6516-4305-8033-7EB5A9F8D82E}.Release|Any CPU.Build.0 = Release|Any CPU + {78A2D592-4FC1-44DB-A73C-E5CC5FD53550}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {78A2D592-4FC1-44DB-A73C-E5CC5FD53550}.Debug|Any CPU.Build.0 = Debug|Any CPU + {78A2D592-4FC1-44DB-A73C-E5CC5FD53550}.Release|Any CPU.ActiveCfg = Release|Any CPU + {78A2D592-4FC1-44DB-A73C-E5CC5FD53550}.Release|Any CPU.Build.0 = Release|Any CPU + {09D2AFAC-8F1F-430B-AEEF-936D5FFEEB7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {09D2AFAC-8F1F-430B-AEEF-936D5FFEEB7A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {09D2AFAC-8F1F-430B-AEEF-936D5FFEEB7A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {09D2AFAC-8F1F-430B-AEEF-936D5FFEEB7A}.Release|Any CPU.Build.0 = Release|Any CPU + {397BDC9F-1699-4932-956B-DDE7ADECA2D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {397BDC9F-1699-4932-956B-DDE7ADECA2D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {397BDC9F-1699-4932-956B-DDE7ADECA2D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {397BDC9F-1699-4932-956B-DDE7ADECA2D8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {03C6AC2D-878A-4827-BBEA-5C961FE138C9} + EndGlobalSection +EndGlobal diff --git a/bookstoreManager/bookstoreManager/BookstoreManager.WebApi.csproj b/bookstoreManager/bookstoreManager/BookstoreManager.WebApi.csproj new file mode 100644 index 00000000..18bb859a --- /dev/null +++ b/bookstoreManager/bookstoreManager/BookstoreManager.WebApi.csproj @@ -0,0 +1,31 @@ + + + + net6.0 + enable + enable + true + $(NoWarn);1591 + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + diff --git a/bookstoreManager/bookstoreManager/Controller/AuthenticationController.cs b/bookstoreManager/bookstoreManager/Controller/AuthenticationController.cs new file mode 100644 index 00000000..091716e7 --- /dev/null +++ b/bookstoreManager/bookstoreManager/Controller/AuthenticationController.cs @@ -0,0 +1,57 @@ +using BookstoreManager.Application.Authentication.Login; +using BookstoreManager.Application.AuthenticationService.Register; +using BookstoreManager.Domain.dto.authenticationDto; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace BookstoreManager.WebApi.Controller +{ + /// + /// UserController + /// + [ApiController] + [Produces("application/json")] + public class AuthenticationController : ControllerBase + { + private readonly ILoginUserService _loginService; + private readonly IRegisterUserService _registerUserService; + public AuthenticationController(ILoginUserService loginService, + IRegisterUserService registerUserService) + { + _loginService = loginService; + _registerUserService = registerUserService; + } + [HttpPost("api/[controller]/Oauth")] + public async Task Oauth([FromBody] LoginRequest request) + { + try + { + var result = await _loginService.Login(request); + + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(new { message = ex.Message }); + } + + } + + [HttpPost("api/[controller]/Register")] + + public async Task Register([FromBody] RegisterUserRequest request) + { + try + { + var result = await _registerUserService.Register(request); + + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(new { message = ex.Message }); + } + + } + } +} diff --git a/bookstoreManager/bookstoreManager/Controller/BookController.cs b/bookstoreManager/bookstoreManager/Controller/BookController.cs new file mode 100644 index 00000000..a51d2693 --- /dev/null +++ b/bookstoreManager/bookstoreManager/Controller/BookController.cs @@ -0,0 +1,136 @@ +using BookstoreManager.Application.BookService.Command.Delete; +using BookstoreManager.Application.BookService.Command.Register; +using BookstoreManager.Application.BookService.Command.Update; +using BookstoreManager.Application.BookService.Querie.GetAll; +using BookstoreManager.Application.LogErrorService.Register; +using BookstoreManager.Domain.dto.GetAll; +using BookstoreManager.Domain.dto.register; +using BookstoreManager.Domain.dto.update; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; + +namespace BookstoreManager.WebApi.Controller +{ + /// + /// UserController + /// + [ApiController] + [Produces("application/json")] + public class BookController : ControllerBase + { + private readonly IRegisterBookService _registerBookService; + private readonly IUpdateBookService _updateBookService; + private readonly IRemoveBookService _removeBookService; + private readonly IGetAllBookService _getAllBookService; + private readonly IRegisterLogErrorService _registerLogErrorService; + public BookController(IRegisterBookService registerBookService, + IUpdateBookService updateBookService, + IRemoveBookService removeBookService, + IGetAllBookService getAllBookService, + IRegisterLogErrorService registerLogErrorService) + { + _registerBookService = registerBookService; + _updateBookService = updateBookService; + _removeBookService = removeBookService; + _getAllBookService = getAllBookService; + _registerLogErrorService = registerLogErrorService; + } + + /// + /// register books + /// + [HttpPost("api/[controller]/Register")] + public async Task Register([FromBody]RegisterRequest request) + { + try + { + var result = await _registerBookService.Register(request); + + return Ok(result); + } + catch (Exception ex) + { + await _registerLogErrorService.Register(ex.Message); + + return BadRequest(new { message = ex.Message }); + } + + } + + /// + /// update books + /// + [HttpPut("api/[controller]/Update")] + [Authorize] + public async Task Update([FromBody]UpdateRequest request) + { + try + { + var result = await _updateBookService.Update(request); + + return Ok(result); + } + catch (Exception ex) + { + await _registerLogErrorService.Register(ex.Message); + return BadRequest(new { message = ex.Message }); + } + + } + + /// + /// Delete book + /// + [HttpDelete("api/[controller]/Delete")] + [Authorize] + public async Task Delete(int id) + { + try + { + var result = await _removeBookService.Remove(id); + + return Ok(result); + } + catch (Exception ex) + { + await _registerLogErrorService.Register(ex.Message); + + return BadRequest(new { message = ex.Message }); + } + + } + + /// + /// Get All books + /// + /// has default value + /// value per page + /// optional + [SwaggerResponse(statusCode: 200, type: typeof(List))] + [HttpGet("api/[controller]/GetAll")] + public async Task GetAll(string? search ,int page = 1, int pageSize = 10) + { + try + { + var result = await _getAllBookService.GetAll(new GetAllBookRequest + { + Page = page, + PageSize = pageSize, + Search = search + }); + + return Ok(result); + } + catch (Exception ex) + { + await _registerLogErrorService.Register(ex.Message); + + return BadRequest(new { message = ex.Message }); + } + + } + + + } +} diff --git a/bookstoreManager/bookstoreManager/Controller/LogErrorController.cs b/bookstoreManager/bookstoreManager/Controller/LogErrorController.cs new file mode 100644 index 00000000..9f6372ed --- /dev/null +++ b/bookstoreManager/bookstoreManager/Controller/LogErrorController.cs @@ -0,0 +1,105 @@ +using BookstoreManager.Application.LogErrorService.Command.Delete; +using BookstoreManager.Application.LogErrorService.Command.ToView; +using BookstoreManager.Application.LogErrorService.Querie.GetAll; +using BookstoreManager.Domain.dto.ErrorDto; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; + +namespace BookstoreManager.WebApi.Controller +{ + /// + /// ErrorController + /// + [ApiController] + [Produces("application/json")] + public class LogErrorController : ControllerBase + { + private readonly IGetAllLogErrorService _getAllLogErrorService; + private readonly IViewLogErrorService _viewLogErrorService; + private readonly IDeleteErrorService _deleteErrorService; + public LogErrorController(IGetAllLogErrorService getAllLogErrorService, + IViewLogErrorService viewLogErrorService, + IDeleteErrorService deleteErrorService) + { + _getAllLogErrorService = getAllLogErrorService; + _deleteErrorService = deleteErrorService; + _viewLogErrorService = viewLogErrorService; + } + + + /// + /// Get All + /// + /// has default value + /// value per page + /// optional + [HttpPost("api/[controller]/GetAll")] + [SwaggerResponse(statusCode: 200, type: typeof(List))] + public async Task GetAll(string? search, int page =1, int pageSize =10) + { + try + { + var result = await _getAllLogErrorService.GetAll(new GetAllErrorLogRequest + { + Search = search, + Page = page, + PageSize = pageSize + + }); + + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(new { message = ex.Message }); + } + + } + + /// + /// To view Logs + /// + /// get by id + [HttpPost("api/[controller]/ToView")] + [SwaggerResponse(statusCode: 200, type: typeof(ViewLogErrorResponse))] + [Authorize] + public async Task ToView(int Id) + { + + try + { + var result = await _viewLogErrorService.ToView(Id); + + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(new { message = ex.Message }); + } + + } + + /// + /// Delete by id + /// + /// get by id + [HttpDelete("api/[controller]/Delete")] + [SwaggerResponse(statusCode: 200, type: typeof(DeleteErrorResponse))] + [Authorize] + public async Task Delete([FromBody]int Id) + { + try + { + var result = await _deleteErrorService.Delete(Id); + + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(new { message = ex.Message }); + } + + } + } +} diff --git a/bookstoreManager/bookstoreManager/Program.cs b/bookstoreManager/bookstoreManager/Program.cs new file mode 100644 index 00000000..fe8ec147 --- /dev/null +++ b/bookstoreManager/bookstoreManager/Program.cs @@ -0,0 +1,98 @@ +using BookstoreManager.Application; +using BookstoreManager.Repository; +using BookststorageManager.Data.Data; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; +using Microsoft.OpenApi.Models; +using System.Reflection; +using System.Text; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddInfrastruture(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddApplication(); + +builder.Services.AddSwaggerGen(c => +{ + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + Description = "JWT Authorization header using the Bearer", + Name = "Authorization", + In = ParameterLocation.Header, + Type = SecuritySchemeType.ApiKey, + Scheme = "Bearer" + }); + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + } + + }, + Array.Empty() + } + }); + + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFile)); +}); + +string? strConnection = builder.Configuration.GetConnectionString("DefaultConnection"); + +byte[]? secret = Encoding.ASCII.GetBytes(builder.Configuration.GetSection("JwtConfigurations:Secret").Value); + +builder.Services.AddAuthentication(x => +{ + x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; +}) + .AddJwtBearer(x => + { + x.RequireHttpsMetadata = false; + x.SaveToken = true; + x.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters + { + ValidateIssuerSigningKey = true, + IssuerSigningKey = new SymmetricSecurityKey(secret), + ValidateIssuer = false, + ValidateAudience = false + + }; + }); + +builder.Services.AddDbContext(options => +{ + options.UseSqlServer(strConnection); +}); + + + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthentication(); +app.UseAuthorization(); + +app.MapControllers(); +app.UseStaticFiles(); + +app.Run(); diff --git a/bookstoreManager/bookstoreManager/Properties/launchSettings.json b/bookstoreManager/bookstoreManager/Properties/launchSettings.json new file mode 100644 index 00000000..becb1bcb --- /dev/null +++ b/bookstoreManager/bookstoreManager/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:57407", + "sslPort": 44386 + } + }, + "profiles": { + "bookstoreManager": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7262;http://localhost:5262", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/bookstoreManager/bookstoreManager/appsettings.Development.json b/bookstoreManager/bookstoreManager/appsettings.Development.json new file mode 100644 index 00000000..0c208ae9 --- /dev/null +++ b/bookstoreManager/bookstoreManager/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/bookstoreManager/bookstoreManager/appsettings.json b/bookstoreManager/bookstoreManager/appsettings.json new file mode 100644 index 00000000..2c5d32cc --- /dev/null +++ b/bookstoreManager/bookstoreManager/appsettings.json @@ -0,0 +1,16 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ConnectionStrings": { + "DefaultConnection": "Data Source=DESKTOP-HCBM0MS;Initial Catalog=database_teste;Integrated Security=True; Encrypt=False " + + }, + "JwtConfigurations": { + "Secret": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" + }, + "AllowedHosts": "*" +} diff --git a/bookstoreManager/curriculo/MuriloCurriculo (1).pdf b/bookstoreManager/curriculo/MuriloCurriculo (1).pdf new file mode 100644 index 00000000..a65af6c3 Binary files /dev/null and b/bookstoreManager/curriculo/MuriloCurriculo (1).pdf differ