From ab884ade52083eb636a4910b58e53791cb878f8f Mon Sep 17 00:00:00 2001 From: Daniela2319 Date: Thu, 4 Dec 2025 14:56:02 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20cria=C3=A7=C3=A3o=20das=20entidades=20e?= =?UTF-8?q?=20config=20contextDb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dotnet-ci.yml | 188 ++++++++++++++++++ .gitignore | 4 + diagramas/docker-compose.yml | 23 +++ ...47\303\243o (login) usando PostgreSQL.sql" | 52 +++++ .../Controllers/PersonController.cs | 67 +++++++ .../DependencyInjectionExtensions.cs | 19 ++ .../src/jwt-auth-api.Api/Program.cs | 43 ++++ .../Properties/launchSettings.json | 23 +++ .../appsettings.Development.json | 8 + .../src/jwt-auth-api.Api/appsettings.json | 12 ++ .../jwt-auth-api.Api/jwt-auth-api.Api.csproj | 27 +++ .../jwt-auth-api.Api/jwt-auth-api.Api.http | 6 + .../jwt-auth-api.Api/jwt-auth-api.Api.slnx | 7 + .../Service/BaseService.cs | 58 ++++++ .../Service/ServicePerson.cs | 13 ++ .../Service/ServiceUsuario.cs | 15 ++ .../jwt-auth-api.Application.csproj | 15 ++ .../src/jwt-auth-api.Core/BaseModel.cs | 17 ++ .../src/jwt-auth-api.Core/Permissao.cs | 12 ++ .../src/jwt-auth-api.Core/Person.cs | 13 ++ .../src/jwt-auth-api.Core/Role.cs | 12 ++ .../src/jwt-auth-api.Core/RolePermissao.cs | 12 ++ .../src/jwt-auth-api.Core/Token.cs | 14 ++ .../src/jwt-auth-api.Core/Usuario.cs | 14 ++ .../src/jwt-auth-api.Core/UsuarioRole.cs | 12 ++ .../jwt-auth-api.Domain.csproj | 10 + .../Context/ApplicationDbContext.cs | 19 ++ .../20251203120433_Initial.Designer.cs | 188 ++++++++++++++++++ .../Migrations/20251203120433_Initial.cs | 141 +++++++++++++ .../ApplicationDbContextModelSnapshot.cs | 185 +++++++++++++++++ .../Repositories/BaseRepository.cs | 62 ++++++ .../Repositories/Interfaces/IRepositoriy.cs | 13 ++ .../Repositories/RepositoryInDbPostgres.cs | 12 ++ .../Repositories/RepositoryPerson.cs | 14 ++ .../Repositories/RepositoryUsuario.cs | 11 + .../jwt-auth-api.Infrastructure.csproj | 29 +++ .../src/jwt-auth-api.Shared/Class1.cs | 7 + .../jwt-auth-api.Shared.csproj | 10 + 38 files changed, 1387 insertions(+) create mode 100644 .github/workflows/dotnet-ci.yml create mode 100644 diagramas/docker-compose.yml create mode 100644 "diagramas/scripts/API de autentica\303\247\303\243o (login) usando PostgreSQL.sql" create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Api/Controllers/PersonController.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Api/Extensions/DependencyInjectionExtensions.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Api/Program.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Api/Properties/launchSettings.json create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Api/appsettings.Development.json create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Api/appsettings.json create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Api/jwt-auth-api.Api.csproj create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Api/jwt-auth-api.Api.http create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Api/jwt-auth-api.Api.slnx create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Application/Service/BaseService.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Application/Service/ServicePerson.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Application/Service/ServiceUsuario.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Application/jwt-auth-api.Application.csproj create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Core/BaseModel.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Core/Permissao.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Core/Person.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Core/Role.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Core/RolePermissao.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Core/Token.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Core/Usuario.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Core/UsuarioRole.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Core/jwt-auth-api.Domain.csproj create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Context/ApplicationDbContext.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Migrations/20251203120433_Initial.Designer.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Migrations/20251203120433_Initial.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/BaseRepository.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/Interfaces/IRepositoriy.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/RepositoryInDbPostgres.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/RepositoryPerson.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/RepositoryUsuario.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/jwt-auth-api.Infrastructure.csproj create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Shared/Class1.cs create mode 100644 jwt-auth-api.Api/src/jwt-auth-api.Shared/jwt-auth-api.Shared.csproj diff --git a/.github/workflows/dotnet-ci.yml b/.github/workflows/dotnet-ci.yml new file mode 100644 index 0000000..46d04b9 --- /dev/null +++ b/.github/workflows/dotnet-ci.yml @@ -0,0 +1,188 @@ +name: .NET 10 CI/CD + +on: + pull_request: + branches: ["main", "homolog", "*"] + workflow_dispatch: + +jobs: + # ----------------------------- + # INSTALL (restore) + # ----------------------------- + restore: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./jwt-auth-api.Api/src/jwt-auth-api.Api + steps: + - uses: actions/checkout@v4 + + - name: Setup .NET 10 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Restore dependencies + run: dotnet restore + + # ----------------------------- + # QUALITY GATE – CommitLint + # ----------------------------- + commitlint: + runs-on: ubuntu-latest + needs: restore + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Validate Conventional Commits + run: | + echo "Checking commit messages..." + PATTERN='^(feat|fix|chore|docs|style|refactor|perf|test|build)(\(.+\))?: .+' + COMMITS=$(git log --format="%s" origin/main..HEAD) + if [ -z "$COMMITS" ]; then + echo "No commits found."; exit 0; + fi + failed=0 + while IFS= read -r msg; do + [ -z "$msg" ] && continue + if echo "$msg" | grep -Eq "^Merge"; then + echo "Skipping merge commit: $msg" + continue + fi + if echo "$msg" | grep -Eq "$PATTERN"; then + echo "OK $msg" + else + echo "ERR $msg" + failed=1 + fi + done <<< "$COMMITS" + if [ "$failed" -ne 0 ]; then + echo "Commit messages did not follow Conventional Commits." + exit 1 + fi + echo "Commit messages OK." + + # ----------------------------- + # Dotnet Format + # ----------------------------- + format: + runs-on: ubuntu-latest + needs: restore + defaults: + run: + working-directory: ./jwt-auth-api.Api/src/jwt-auth-api.Api + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Apply formatting + run: dotnet format ./jwt-auth-api.Api.csproj + + # ----------------------------- + # BUILD (warnings → errors) + # ----------------------------- + build: + runs-on: ubuntu-latest + needs: [restore, format] + defaults: + run: + working-directory: ./jwt-auth-api.Api/src/jwt-auth-api.Api + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Build with warnings as errors + run: dotnet build -warnaserror + + # ----------------------------- + # TESTS + # ----------------------------- + test: + runs-on: ubuntu-latest + needs: build + defaults: + run: + working-directory: ./jwt-auth-api.Api/src/jwt-auth-api.Api + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Run Tests + run: dotnet test --no-build --verbosity normal + + # ----------------------------- + # PUBLISH (like GitLab publish step) + # ----------------------------- + publish: + runs-on: ubuntu-latest + needs: test + defaults: + run: + working-directory: ./jwt-auth-api.Api/src/jwt-auth-api.Api + outputs: + publish_path: ${{ steps.output_step.outputs.path }} + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Publish API + run: dotnet publish -c Release -o ./publish + + - id: output_step + run: echo "path=./jwt-auth-api.Api/src/jwt-auth-api.Api/publish" >> $GITHUB_OUTPUT + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: jwt-auth-api-publish + path: ./jwt-auth-api.Api/src/jwt-auth-api.Api/publish + + # ----------------------------- + # (OPTIONAL) AUTO MERGE MAIN → FEATURE + # ----------------------------- + merge-main: + if: github.event.pull_request.head.ref != 'main' + runs-on: ubuntu-latest + needs: publish + + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 + + - name: Merge main into branch + run: | + git config user.email "actions@github.com" + git config user.name "GitHub Actions" + + git checkout ${{ github.event.pull_request.head.ref }} + git merge origin/main --no-edit || true + git push || true + + # ----------------------------- + # (OPTIONAL) DEPLOY STAGING + # ----------------------------- + deploy-staging: + runs-on: ubuntu-latest + needs: publish + environment: staging + if: github.event.pull_request.merged == true + steps: + - name: Deploy Placeholder + run: | + echo "Deploy to staging would happen here." diff --git a/.gitignore b/.gitignore index ce89292..342a2cc 100644 --- a/.gitignore +++ b/.gitignore @@ -416,3 +416,7 @@ FodyWeavers.xsd *.msix *.msm *.msp + +# BuildHost temporários +BuildHost-netcore/ +BuildHost-net472/ diff --git a/diagramas/docker-compose.yml b/diagramas/docker-compose.yml new file mode 100644 index 0000000..1860db0 --- /dev/null +++ b/diagramas/docker-compose.yml @@ -0,0 +1,23 @@ +services: + DFV_db: + image: postgres:17 + container_name: DFV_database + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: admin + POSTGRES_DB: DFV_db + ports: + - "5435:5432" + volumes: + - ./scripts:/docker-entrypoint-initdb.d/ + - DFV_db-data:/var/lib/postgresql/data + networks: + - DFV-network + restart: always + +volumes: + DFV_db-data: + +networks: + DFV-network: + external: true \ No newline at end of file diff --git "a/diagramas/scripts/API de autentica\303\247\303\243o (login) usando PostgreSQL.sql" "b/diagramas/scripts/API de autentica\303\247\303\243o (login) usando PostgreSQL.sql" new file mode 100644 index 0000000..0d26eed --- /dev/null +++ "b/diagramas/scripts/API de autentica\303\247\303\243o (login) usando PostgreSQL.sql" @@ -0,0 +1,52 @@ +CREATE TABLE "usuario" ( + "id" serial PRIMARY KEY, + "nome" varchar(150) NOT NULL, + "email" varchar(150) UNIQUE NOT NULL, + "senha_hash" varchar(255) NOT NULL, + "ativo" boolean DEFAULT true, + "criado_em" timestamp DEFAULT (now()), + "atualizado_em" timestamp +); + +CREATE TABLE "role" ( + "id" serial PRIMARY KEY, + "nome" varchar(100) UNIQUE NOT NULL, + "descricao" text +); + +CREATE TABLE "usuario_role" ( + "id" serial PRIMARY KEY, + "usuario_id" int, + "role_id" int +); + +CREATE TABLE "token" ( + "id" serial PRIMARY KEY, + "usuario_id" int, + "refresh_token" varchar(300) NOT NULL, + "expiracao" timestamp NOT NULL, + "criado_em" timestamp DEFAULT (now()), + "ativo" boolean DEFAULT true +); + +CREATE TABLE "permissao" ( + "id" serial PRIMARY KEY, + "nome" varchar(150) UNIQUE NOT NULL, + "descricao" text +); + +CREATE TABLE "role_permissao" ( + "id" serial PRIMARY KEY, + "role_id" int, + "permissao_id" int +); + +ALTER TABLE "usuario_role" ADD FOREIGN KEY ("usuario_id") REFERENCES "usuario" ("id"); + +ALTER TABLE "usuario_role" ADD FOREIGN KEY ("role_id") REFERENCES "role" ("id"); + +ALTER TABLE "token" ADD FOREIGN KEY ("usuario_id") REFERENCES "usuario" ("id"); + +ALTER TABLE "role_permissao" ADD FOREIGN KEY ("role_id") REFERENCES "role" ("id"); + +ALTER TABLE "role_permissao" ADD FOREIGN KEY ("permissao_id") REFERENCES "permissao" ("id"); diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Api/Controllers/PersonController.cs b/jwt-auth-api.Api/src/jwt-auth-api.Api/Controllers/PersonController.cs new file mode 100644 index 0000000..e2683f8 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Api/Controllers/PersonController.cs @@ -0,0 +1,67 @@ +using jwt_auth_api.Application.Service; +using jwt_auth_api.Core; +using Microsoft.AspNetCore.Mvc; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace jwt_auth_api.Api.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class PersonController : ControllerBase + { + private readonly ServicePerson _servicePerson; + public PersonController(ServicePerson servicePerson) + { + _servicePerson = servicePerson; + } + [HttpGet] + public List Get() + { + return _servicePerson.Read(); + } + + + [HttpGet("{id}")] + public Person Get(Guid id) + { + return _servicePerson.ReadById(id); + } + + [HttpGet("exist/{id}")] + public bool Exist(Guid id) + { + return _servicePerson.Exists(id); + } + + [HttpPost] + public void Post([FromBody] Person model) + { + _servicePerson.Create(model); + } + + + [HttpPut("{id}")] + public void Put(Guid id, [FromBody] Person model) + { + _servicePerson.Update(model); + } + + [HttpDelete("{id}")] + public StatusCodeResult Delete(Guid id) + { + try + { + this._servicePerson.Delete(id); + StatusCodeResult result = new StatusCodeResult(204); + return result; + } + catch (Exception) + { + StatusCodeResult result = new StatusCodeResult(500); + return result; + } + + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Api/Extensions/DependencyInjectionExtensions.cs b/jwt-auth-api.Api/src/jwt-auth-api.Api/Extensions/DependencyInjectionExtensions.cs new file mode 100644 index 0000000..3eb326e --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Api/Extensions/DependencyInjectionExtensions.cs @@ -0,0 +1,19 @@ +using jwt_auth_api.Application.Service; +using jwt_auth_api.Infrastructure.Repositories; +using jwt_auth_api.Infrastructure.Repositories.Interfaces; + +namespace jwt_auth_api.Api.Extensions +{ + public static class DependencyInjectionExtensions + { + public static IServiceCollection AddAppDependencies(this IServiceCollection services) + { + services.AddScoped(); + + // ===== Repositories ===== + services.AddScoped(typeof(IRepositoriy<>), typeof(BaseRepository<>)); + return services; + } + + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Api/Program.cs b/jwt-auth-api.Api/src/jwt-auth-api.Api/Program.cs new file mode 100644 index 0000000..8e69155 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Api/Program.cs @@ -0,0 +1,43 @@ +using jwt_auth_api.Api.Extensions; +using jwt_auth_api.Infrastructure.Context; +using Microsoft.EntityFrameworkCore; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + + + +builder.Services.AddControllers(); +// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi +builder.Services.AddOpenApi(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +//===== Database ===== +builder.Services.AddDbContext(options => +{ + var connectionString = builder.Configuration.GetConnectionString("Postgres"); + options.UseNpgsql(connectionString); +}); + +//===== Extensions ===== +builder.Services.AddAppDependencies(); +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.MapOpenApi(); + + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Api/Properties/launchSettings.json b/jwt-auth-api.Api/src/jwt-auth-api.Api/Properties/launchSettings.json new file mode 100644 index 0000000..0da6cec --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Api/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5261", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7185;http://localhost:5261", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Api/appsettings.Development.json b/jwt-auth-api.Api/src/jwt-auth-api.Api/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Api/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Api/appsettings.json b/jwt-auth-api.Api/src/jwt-auth-api.Api/appsettings.json new file mode 100644 index 0000000..d062b4f --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Api/appsettings.json @@ -0,0 +1,12 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + "Postgres": "" + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Api/jwt-auth-api.Api.csproj b/jwt-auth-api.Api/src/jwt-auth-api.Api/jwt-auth-api.Api.csproj new file mode 100644 index 0000000..02351fc --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Api/jwt-auth-api.Api.csproj @@ -0,0 +1,27 @@ + + + + net10.0 + enable + enable + jwt_auth_api.Api + 18fa9d8e-8b08-4b82-9ad0-83b746f424a9 + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Api/jwt-auth-api.Api.http b/jwt-auth-api.Api/src/jwt-auth-api.Api/jwt-auth-api.Api.http new file mode 100644 index 0000000..93f1e3e --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Api/jwt-auth-api.Api.http @@ -0,0 +1,6 @@ +@jwt_auth_api.Api_HostAddress = http://localhost:5261 + +GET {{jwt_auth_api.Api_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Api/jwt-auth-api.Api.slnx b/jwt-auth-api.Api/src/jwt-auth-api.Api/jwt-auth-api.Api.slnx new file mode 100644 index 0000000..d626a77 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Api/jwt-auth-api.Api.slnx @@ -0,0 +1,7 @@ + + + + + + + diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Application/Service/BaseService.cs b/jwt-auth-api.Api/src/jwt-auth-api.Application/Service/BaseService.cs new file mode 100644 index 0000000..d5c09cc --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Application/Service/BaseService.cs @@ -0,0 +1,58 @@ +using jwt_auth_api.Core; +using jwt_auth_api.Infrastructure.Repositories.Interfaces; + +namespace jwt_auth_api.Application.Service +{ + public class BaseService : IRepositoriy where T : BaseModel + { + private readonly IRepositoriy _repository; + public BaseService(IRepositoriy repository) + { + _repository = repository; + } + public virtual Guid Create(T entity) + { + return _repository.Create(entity); + } + + public virtual void Delete(Guid id) + { + var entity = _repository.ReadById(id); + + if (entity == null) + throw new Exception($"Registro {id} não encontrado."); + + _repository.Delete(id); + } + + public virtual bool Exists(Guid id) + { + return _repository.Exists(id); + } + + public virtual List Read() + { + return _repository.Read(); + } + + public virtual T ReadById(Guid id) + { + var entity = _repository.ReadById(id); + + if (entity == null) + throw new Exception($"Registro ID {id} não encontrado."); + + return entity; + } + + public virtual void Update(T entity) + { + var existing = _repository.ReadById(entity.Id); + + if (existing == null) + throw new Exception($"Registro {entity.Id} não encontrado."); + + _repository.Update(entity); + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Application/Service/ServicePerson.cs b/jwt-auth-api.Api/src/jwt-auth-api.Application/Service/ServicePerson.cs new file mode 100644 index 0000000..27fbd99 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Application/Service/ServicePerson.cs @@ -0,0 +1,13 @@ +using jwt_auth_api.Core; +using jwt_auth_api.Infrastructure.Repositories.Interfaces; + + +namespace jwt_auth_api.Application.Service +{ + public class ServicePerson : BaseService + { + public ServicePerson(IRepositoriy repository) : base(repository) + { + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Application/Service/ServiceUsuario.cs b/jwt-auth-api.Api/src/jwt-auth-api.Application/Service/ServiceUsuario.cs new file mode 100644 index 0000000..1313fa8 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Application/Service/ServiceUsuario.cs @@ -0,0 +1,15 @@ +using jwt_auth_api.Core; +using jwt_auth_api.Infrastructure.Repositories.Interfaces; +using System; +using System.Collections.Generic; +using System.Text; + +namespace jwt_auth_api.Application.Service +{ + public class ServiceUsuario : BaseService + { + public ServiceUsuario(IRepositoriy repository) : base(repository) + { + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Application/jwt-auth-api.Application.csproj b/jwt-auth-api.Api/src/jwt-auth-api.Application/jwt-auth-api.Application.csproj new file mode 100644 index 0000000..f04eb83 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Application/jwt-auth-api.Application.csproj @@ -0,0 +1,15 @@ + + + + net10.0 + jwt_auth_api.Application + enable + enable + + + + + + + + diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Core/BaseModel.cs b/jwt-auth-api.Api/src/jwt-auth-api.Core/BaseModel.cs new file mode 100644 index 0000000..2e99515 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Core/BaseModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace jwt_auth_api.Core +{ + public class BaseModel + { + public Guid Id { get; set; } = Guid.NewGuid(); + public DateTime CreatedAt { get; set; } = DateTime.UtcNow; + + public override string ToString() + { + return $"{this.Id} - {this.CreatedAt}"; + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Core/Permissao.cs b/jwt-auth-api.Api/src/jwt-auth-api.Core/Permissao.cs new file mode 100644 index 0000000..3e3ccd6 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Core/Permissao.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace jwt_auth_api.Core +{ + public class Permissao : BaseModel + { + public string Name { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Core/Person.cs b/jwt-auth-api.Api/src/jwt-auth-api.Core/Person.cs new file mode 100644 index 0000000..e283390 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Core/Person.cs @@ -0,0 +1,13 @@ +namespace jwt_auth_api.Core +{ + public class Person : BaseModel + { + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; + public override string ToString() + { + return $"{base.ToString()} - {this.FirstName} - {this.LastName})"; + } + + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Core/Role.cs b/jwt-auth-api.Api/src/jwt-auth-api.Core/Role.cs new file mode 100644 index 0000000..ef5a940 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Core/Role.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace jwt_auth_api.Core +{ + public class Role : BaseModel + { + public string Name { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Core/RolePermissao.cs b/jwt-auth-api.Api/src/jwt-auth-api.Core/RolePermissao.cs new file mode 100644 index 0000000..f6b9d62 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Core/RolePermissao.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace jwt_auth_api.Core +{ + public class RolePermissao : BaseModel + { + public Guid RoleId { get; set; } + public Guid PermissaoId { get; set; } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Core/Token.cs b/jwt-auth-api.Api/src/jwt-auth-api.Core/Token.cs new file mode 100644 index 0000000..3cdd974 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Core/Token.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace jwt_auth_api.Core +{ + public class Token : BaseModel + { + public Guid UsuarioId { get; set; } + public string RefreshToken { get; set; } = string.Empty; + public DateTime ExpiresAt { get; set; } + + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Core/Usuario.cs b/jwt-auth-api.Api/src/jwt-auth-api.Core/Usuario.cs new file mode 100644 index 0000000..ab709ff --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Core/Usuario.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace jwt_auth_api.Core +{ + public class Usuario : BaseModel + { + public string Email { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public bool IsActive { get; set; } + public Guid PersonId { get; set; } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Core/UsuarioRole.cs b/jwt-auth-api.Api/src/jwt-auth-api.Core/UsuarioRole.cs new file mode 100644 index 0000000..dadf55f --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Core/UsuarioRole.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace jwt_auth_api.Core +{ + public class UsuarioRole : BaseModel + { + public Guid UsuarioId { get; set; } + public Guid RoleId { get; set; } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Core/jwt-auth-api.Domain.csproj b/jwt-auth-api.Api/src/jwt-auth-api.Core/jwt-auth-api.Domain.csproj new file mode 100644 index 0000000..916c1c4 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Core/jwt-auth-api.Domain.csproj @@ -0,0 +1,10 @@ + + + + net10.0 + jwt_auth_api.Core + enable + enable + + + diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Context/ApplicationDbContext.cs b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Context/ApplicationDbContext.cs new file mode 100644 index 0000000..0d942b3 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Context/ApplicationDbContext.cs @@ -0,0 +1,19 @@ +using jwt_auth_api.Core; +using Microsoft.EntityFrameworkCore; + +namespace jwt_auth_api.Infrastructure.Context +{ + public class ApplicationDbContext : DbContext + { + public ApplicationDbContext(DbContextOptions options) : base(options) { } + + public DbSet Persons { get; set; } + public DbSet Tokens { get; set; } + public DbSet UsuarioRoles { get; set; } + public DbSet RolePermissaos { get; set; } + public DbSet Permissaos { get; set; } + public DbSet Roles { get; set; } + public DbSet Usuarios { get; set; } + + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Migrations/20251203120433_Initial.Designer.cs b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Migrations/20251203120433_Initial.Designer.cs new file mode 100644 index 0000000..d385198 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Migrations/20251203120433_Initial.Designer.cs @@ -0,0 +1,188 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using jwt_auth_api.Infrastructure.Context; + +#nullable disable + +namespace jwt_auth_api.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20251203120433_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("jwt_auth_api.Core.Permissao", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Permissaos"); + }); + + modelBuilder.Entity("jwt_auth_api.Core.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Persons"); + }); + + modelBuilder.Entity("jwt_auth_api.Core.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("jwt_auth_api.Core.RolePermissao", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("PermissaoId") + .HasColumnType("uuid"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("RolePermissaos"); + }); + + modelBuilder.Entity("jwt_auth_api.Core.Token", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresAt") + .HasColumnType("timestamp with time zone"); + + b.Property("RefreshToken") + .IsRequired() + .HasColumnType("text"); + + b.Property("UsuarioId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("Tokens"); + }); + + modelBuilder.Entity("jwt_auth_api.Core.Usuario", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("PersonId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("Usuarios"); + }); + + modelBuilder.Entity("jwt_auth_api.Core.UsuarioRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("UsuarioId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("UsuarioRoles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Migrations/20251203120433_Initial.cs b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Migrations/20251203120433_Initial.cs new file mode 100644 index 0000000..48a74d7 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Migrations/20251203120433_Initial.cs @@ -0,0 +1,141 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace jwt_auth_api.Infrastructure.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Permissaos", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "text", nullable: false), + Description = table.Column(type: "text", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Permissaos", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Persons", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + FirstName = table.Column(type: "text", nullable: false), + LastName = table.Column(type: "text", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Persons", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "RolePermissaos", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + RoleId = table.Column(type: "uuid", nullable: false), + PermissaoId = table.Column(type: "uuid", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RolePermissaos", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Roles", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "text", nullable: false), + Description = table.Column(type: "text", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Roles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Tokens", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + UsuarioId = table.Column(type: "uuid", nullable: false), + RefreshToken = table.Column(type: "text", nullable: false), + ExpiresAt = table.Column(type: "timestamp with time zone", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Tokens", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "UsuarioRoles", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + UsuarioId = table.Column(type: "uuid", nullable: false), + RoleId = table.Column(type: "uuid", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UsuarioRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Usuarios", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Email = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + PersonId = table.Column(type: "uuid", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Usuarios", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Permissaos"); + + migrationBuilder.DropTable( + name: "Persons"); + + migrationBuilder.DropTable( + name: "RolePermissaos"); + + migrationBuilder.DropTable( + name: "Roles"); + + migrationBuilder.DropTable( + name: "Tokens"); + + migrationBuilder.DropTable( + name: "UsuarioRoles"); + + migrationBuilder.DropTable( + name: "Usuarios"); + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 0000000..471b7b8 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,185 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using jwt_auth_api.Infrastructure.Context; + +#nullable disable + +namespace jwt_auth_api.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("jwt_auth_api.Core.Permissao", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Permissaos"); + }); + + modelBuilder.Entity("jwt_auth_api.Core.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Persons"); + }); + + modelBuilder.Entity("jwt_auth_api.Core.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("jwt_auth_api.Core.RolePermissao", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("PermissaoId") + .HasColumnType("uuid"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("RolePermissaos"); + }); + + modelBuilder.Entity("jwt_auth_api.Core.Token", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresAt") + .HasColumnType("timestamp with time zone"); + + b.Property("RefreshToken") + .IsRequired() + .HasColumnType("text"); + + b.Property("UsuarioId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("Tokens"); + }); + + modelBuilder.Entity("jwt_auth_api.Core.Usuario", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("PersonId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("Usuarios"); + }); + + modelBuilder.Entity("jwt_auth_api.Core.UsuarioRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("UsuarioId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("UsuarioRoles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/BaseRepository.cs b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/BaseRepository.cs new file mode 100644 index 0000000..aa819c6 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/BaseRepository.cs @@ -0,0 +1,62 @@ +using jwt_auth_api.Core; +using jwt_auth_api.Infrastructure.Context; +using jwt_auth_api.Infrastructure.Repositories.Interfaces; +using Microsoft.EntityFrameworkCore; + +namespace jwt_auth_api.Infrastructure.Repositories +{ + public class BaseRepository : IRepositoriy where T : BaseModel + { + private readonly ApplicationDbContext _context; + private readonly DbSet _dbSet; + public BaseRepository(ApplicationDbContext context) + { + _context = context; + _dbSet = context.Set(); + } + public Guid Create(T entity) + { + _dbSet.Add(entity); + _context.SaveChanges(); + return entity.Id; + } + + public void Delete(Guid id) + { + var entity = ReadById(id); + + if (entity == null) + return; + + _dbSet.Remove(entity); + _context.SaveChanges(); + } + + public bool Exists(Guid id) + { + return _context.Set().Any(e => e.Id == id); + } + + public List Read() + { + return _dbSet.ToList(); + } + + public T ReadById(Guid id) + { + var entity = _dbSet.Find(id); + if (entity is null) + throw new KeyNotFoundException($"Entity com id {id} não encontrada."); + return entity; + } + + public void Update(T entity) + { + var modelOriginal = ReadById(entity.Id); + if (modelOriginal == null) + return; + _context.Entry(modelOriginal).CurrentValues.SetValues(entity); + _context.SaveChanges(); + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/Interfaces/IRepositoriy.cs b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/Interfaces/IRepositoriy.cs new file mode 100644 index 0000000..45c8e28 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/Interfaces/IRepositoriy.cs @@ -0,0 +1,13 @@ + +namespace jwt_auth_api.Infrastructure.Repositories.Interfaces +{ + public interface IRepositoriy + { + Guid Create(T entity); + List Read(); + T ReadById(Guid id); + void Update(T entity); + void Delete(Guid id); + bool Exists(Guid id); + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/RepositoryInDbPostgres.cs b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/RepositoryInDbPostgres.cs new file mode 100644 index 0000000..634321a --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/RepositoryInDbPostgres.cs @@ -0,0 +1,12 @@ +using jwt_auth_api.Core; +using jwt_auth_api.Infrastructure.Context; + +namespace jwt_auth_api.Infrastructure.Repositories +{ + public class RepositoryInDbPostgres : BaseRepository + { + public RepositoryInDbPostgres(ApplicationDbContext context) : base(context) + { + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/RepositoryPerson.cs b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/RepositoryPerson.cs new file mode 100644 index 0000000..3099e8b --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/RepositoryPerson.cs @@ -0,0 +1,14 @@ +using jwt_auth_api.Infrastructure.Context; +using System; +using System.Collections.Generic; +using System.Text; + +namespace jwt_auth_api.Infrastructure.Repositories +{ + public class RepositoryPerson : RepositoryInDbPostgres + { + public RepositoryPerson(ApplicationDbContext context) : base(context) + { + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/RepositoryUsuario.cs b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/RepositoryUsuario.cs new file mode 100644 index 0000000..267d335 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/Repositories/RepositoryUsuario.cs @@ -0,0 +1,11 @@ +using jwt_auth_api.Infrastructure.Context; + +namespace jwt_auth_api.Infrastructure.Repositories +{ + public class RepositoryUsuario : RepositoryInDbPostgres + { + public RepositoryUsuario(ApplicationDbContext context) : base(context) + { + } + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/jwt-auth-api.Infrastructure.csproj b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/jwt-auth-api.Infrastructure.csproj new file mode 100644 index 0000000..87f41e6 --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Infrastructure/jwt-auth-api.Infrastructure.csproj @@ -0,0 +1,29 @@ + + + + net10.0 + jwt_auth_api.Infrastructure + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Shared/Class1.cs b/jwt-auth-api.Api/src/jwt-auth-api.Shared/Class1.cs new file mode 100644 index 0000000..86b738d --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Shared/Class1.cs @@ -0,0 +1,7 @@ +namespace jwt_auth_api.Shared +{ + public class Class1 + { + + } +} diff --git a/jwt-auth-api.Api/src/jwt-auth-api.Shared/jwt-auth-api.Shared.csproj b/jwt-auth-api.Api/src/jwt-auth-api.Shared/jwt-auth-api.Shared.csproj new file mode 100644 index 0000000..6d33dcf --- /dev/null +++ b/jwt-auth-api.Api/src/jwt-auth-api.Shared/jwt-auth-api.Shared.csproj @@ -0,0 +1,10 @@ + + + + net10.0 + jwt_auth_api.Shared + enable + enable + + +