Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 188 additions & 0 deletions .github/workflows/dotnet-ci.yml
Original file line number Diff line number Diff line change
@@ -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."
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,7 @@ FodyWeavers.xsd
*.msix
*.msm
*.msp

# BuildHost temporários
BuildHost-netcore/
BuildHost-net472/
23 changes: 23 additions & 0 deletions diagramas/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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<Person> 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;
}

}
}
}
Original file line number Diff line number Diff line change
@@ -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<ServicePerson>();

// ===== Repositories =====
services.AddScoped(typeof(IRepositoriy<>), typeof(BaseRepository<>));
return services;
}

}
}
Loading
Loading