-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from GoliasVictor/grpc-to-rpc
Grpc to rpc
- Loading branch information
Showing
58 changed files
with
2,889 additions
and
1,147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
Nome: LivrEtec | ||
Tipo: Projeto | ||
Descricao: Projeto LivrEtec | ||
Linguagem: c# | ||
ComandoAbrir: code . | ||
SubProjetos: | ||
- Nome: LivrEtec | ||
Caminho: ./src/LivrEtec | ||
name: LivrEtec | ||
type: project | ||
description: Projeto LivrEtec | ||
language: c# | ||
subproject: | ||
- name: LivrEtec | ||
path: ./src/LivrEtec | ||
|
||
- name: GIB | ||
path: ./src/LivrEtec.GIB | ||
|
||
- name: GIB.Servidor | ||
path: ./src/LivrEtec.GIB.Servidor | ||
|
||
- name: Servidor | ||
path: ./src/LivrEtec.Servidor | ||
|
||
- name: Testes | ||
path: ./src/LivrEtec.Testes | ||
|
||
- Nome: GIB | ||
Caminho: ./src/LivrEtec.GIB | ||
|
||
- Nome: GIB.Servidor | ||
Caminho: ./src/LivrEtec.GIB.Servidor | ||
|
||
- Nome: Servidor | ||
Caminho: ./src/LivrEtec.Servidor | ||
Scripts: | ||
gib-up: dotnet run --project ./src/LivrEtec.GIB.Servidor | ||
|
||
- Nome: Testes | ||
Caminho: ./src/LivrEtec.Testes | ||
|
||
Scripts: | ||
test: dotnet test ./src/LivrEtec.sln --logger "console;verbosity=normal" | ||
test-remoto: dotnet test ./src/LivrEtec.sln --filter Category=Remoto --logger "console;verbosity=normal" | ||
test-local: dotnet test ./src/LivrEtec.sln --filter Category=local --logger "console;verbosity=normal" | ||
gib:up: dotnet run --project ./src/LivrEtec.GIB.Servidor | ||
gib:dev: dotnet watch run --project ./src/LivrEtec.GIB.Servidor | ||
docker: sudo docker compose -f src/docker-compose.yml -p livretec --profile teste up --build --exit-code-from testes | ||
doc:build: docfx docs/docfx.json | ||
doc:up: docfx docs/docfx.json --serve | ||
|
||
scripts: | ||
open: code . | ||
test: dotnet test ./src/LivrEtec.sln --logger "console;verbosity=normal" | ||
test-remoto: dotnet test ./src/LivrEtec.sln --filter Category=Remoto --logger "console;verbosity=normal" | ||
test-local: dotnet test ./src/LivrEtec.sln --filter Category=local --logger "console;verbosity=normal" | ||
gib:up: dotnet run --project ./src/LivrEtec.GIB.Servidor | ||
gib:dev: dotnet watch run --project ./src/LivrEtec.GIB.Servidor | ||
docker: docker compose -f src/docker-compose.yml -p livretec --profile teste up --build --exit-code-from testes | ||
doc:build: docfx docs/docfx.json | ||
doc:up: docfx docs/docfx.json --serve | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using LivrEtec.Repositorios; | ||
using Microsoft.AspNetCore.Authorization; | ||
using LivrEtec.GIB.Services; | ||
|
||
|
||
namespace LivrEtec.GIB.Controllers; | ||
|
||
[Route("auth")] | ||
[ApiController] | ||
public sealed class AuthController: ControllerBase | ||
{ | ||
private readonly ILogger<AuthController> logger; | ||
private readonly AuthKeyProvider authKeyProvider; | ||
private readonly IAutenticacaoService autenticacaoService; | ||
private readonly IIdentidadeService identidadeService; | ||
private readonly IRepUsuarios repUsuarios; | ||
public AuthController(ILogger<AuthController> logger, IAutenticacaoService autenticacaoService, AuthKeyProvider authKeyProvider, IIdentidadeService identidadeService, IRepUsuarios repUsuarios) | ||
{ | ||
this.logger = logger; | ||
this.autenticacaoService = autenticacaoService; | ||
this.identidadeService = identidadeService; | ||
this.authKeyProvider = authKeyProvider; | ||
this.repUsuarios = repUsuarios; | ||
} | ||
public record RequestLogin(int IdUsuario, string HashSenha); | ||
[AllowAnonymous] | ||
[HttpPost("login")] | ||
public async Task<ActionResult<string>> Login(RequestLogin request) | ||
{ | ||
if (await autenticacaoService.EhAutentico(request.IdUsuario, request.HashSenha)) | ||
return TokenService.GerarToken(request.IdUsuario, authKeyProvider.authKey); | ||
return Unauthorized("Usuario não encontrado ou Senha incorreta"); | ||
} | ||
|
||
[HttpGet("autorizado/{id_permissao}")] | ||
[AllowAnonymous] | ||
public async Task<ActionResult<bool>> EhAutorizado(int id_permissao) | ||
{ | ||
LEM.Permissao? permissao = Permissoes.TodasPermissoes.FirstOrDefault(p => p.Id == id_permissao); | ||
if (permissao is null) | ||
return Conflict("Permissão não existe"); | ||
return await identidadeService.EhAutorizado(permissao); | ||
} | ||
|
||
[HttpGet("usuario")] | ||
public async Task<DTO::Usuario> CarregarUsuario() | ||
{ | ||
await identidadeService.CarregarUsuario(); | ||
return identidadeService.Usuario!; | ||
} | ||
|
||
[HttpGet("usuario/{login}")] | ||
public async Task<int?> ObterId(string login) | ||
{ | ||
return await repUsuarios.ObterId(login); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
namespace LivrEtec.GIB.Controllers; | ||
|
||
[Route("emprestimos")] | ||
[ApiController] | ||
public sealed class EmprestimosController | ||
{ | ||
private readonly ILogger<EmprestimosController> logger; | ||
private readonly IEmprestimoService emprestimoService; | ||
private readonly IIdentidadeService identidadeService; | ||
public EmprestimosController(ILogger<EmprestimosController> logger, IEmprestimoService emprestimoService, IIdentidadeService identidadeService) | ||
{ | ||
this.logger = logger; | ||
this.emprestimoService = emprestimoService; | ||
this.identidadeService = identidadeService; | ||
} | ||
public record RequestAbrirEmprestimo(int IdPessoa, int IdLivro); | ||
[HttpPost()] | ||
public async Task<int> Abrir(RequestAbrirEmprestimo request) | ||
{ | ||
return await emprestimoService.Abrir(request.IdPessoa, request.IdLivro); | ||
} | ||
public record RequestBuscar( | ||
int? IdLivro, | ||
int? IdPessoa, | ||
bool? Fechado, | ||
bool? Atrasado | ||
); | ||
[HttpGet()] | ||
public async Task<IEnumerable<DTO::Emprestimo>> Buscar([FromQuery] RequestBuscar request) | ||
{ | ||
return (await emprestimoService.Buscar(new LEM::ParamBuscaEmprestimo( | ||
IdLivro: request.IdLivro, | ||
IdPessoa: request.IdPessoa, | ||
Fechado: request.Fechado, | ||
Atrasado: request.Atrasado | ||
))).Select(e => (DTO::Emprestimo)e); | ||
} | ||
public record RequestDevolverEmprestimo( | ||
int IdEmprestimo, | ||
bool? AtrasoJustificado, | ||
string? ExplicacaoAtraso | ||
); | ||
[HttpPatch("devolver")] | ||
public async Task Devolver(RequestDevolverEmprestimo request) | ||
{ | ||
await emprestimoService.Devolver( | ||
request.IdEmprestimo, | ||
request.AtrasoJustificado, | ||
request.ExplicacaoAtraso | ||
); | ||
} | ||
public record RequestProrrogarEmprestimo( | ||
int IdEmprestimo, | ||
DateTime NovaData | ||
); | ||
[HttpPatch("prorrogar")] | ||
public async Task Prorrogar(RequestProrrogarEmprestimo request) | ||
{ | ||
await emprestimoService.Prorrogar(request.IdEmprestimo, request.NovaData); | ||
} | ||
public record RequestPerdaEmprestimo( | ||
int id | ||
); | ||
[HttpPatch("perda")] | ||
public async Task RegistrarPerda(RequestPerdaEmprestimo request) | ||
{ | ||
await emprestimoService.RegistrarPerda(request.id); | ||
} | ||
[HttpDelete("{id}")] | ||
public async Task Excluir(int id) | ||
{ | ||
await emprestimoService.Excluir(id); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
namespace LivrEtec.GIB.Controllers; | ||
|
||
[Route("livros")] | ||
[ApiController] | ||
public sealed class LivrosController(ILogger<LivrosController> logger, ILivrosService livrosService) | ||
{ | ||
private readonly ILogger<LivrosController> logger = logger; | ||
private readonly ILivrosService livrosService = livrosService; | ||
|
||
[HttpPost()] | ||
public async Task Registrar(DTO::Livro request) | ||
{ | ||
await livrosService.Registrar(request); | ||
} | ||
|
||
[HttpGet("{id}")] | ||
public async Task<DTO::Livro?> Obter(int id) | ||
{ | ||
return await livrosService.Obter(id); | ||
} | ||
|
||
[HttpDelete("{id}")] | ||
public async Task Remover(int id) | ||
{ | ||
await livrosService.Remover(id); | ||
} | ||
public record ParamBuscaLivro(string? NomeLivro, string? NomeAutor, IEnumerable<int>? IdTags); | ||
[HttpGet()] | ||
public async Task<IEnumerable<DTO::Livro>> Buscar([FromQuery]ParamBuscaLivro request) | ||
{ | ||
return (await livrosService.Buscar(request.NomeLivro ?? "", request.NomeAutor ?? "", request.IdTags)) | ||
.Select(l => (DTO::Livro)l); | ||
} | ||
|
||
[HttpPut()] | ||
public async Task Editar(DTO::Livro request) | ||
{ | ||
Console.WriteLine(request); | ||
await livrosService.Editar(request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace LivrEtec.GIB.Services; | ||
|
||
[Route("tags")] | ||
[ApiController] | ||
public sealed class TagsController(ILogger<TagsController> logger, ITagsService tagsService) | ||
{ | ||
private readonly ILogger<TagsController> logger = logger; | ||
private readonly ITagsService tagsService = tagsService; | ||
|
||
[HttpPost()] | ||
public async Task<int> Registrar(DTO::Tag request) | ||
{ | ||
return await tagsService.Registrar(request); | ||
} | ||
[HttpGet("{id}")] | ||
public async Task<DTO::Tag?> Obter(int id) | ||
{ | ||
return await tagsService.Obter(id); | ||
} | ||
|
||
[HttpDelete("{id}")] | ||
public async Task Remover(int id) | ||
{ | ||
await tagsService.Remover(id); | ||
} | ||
|
||
public record BuscarTagReq(string Nome); | ||
[HttpGet()] | ||
public async Task<IEnumerable<DTO::Tag>> Buscar([FromQuery]BuscarTagReq request) | ||
{ | ||
return (await tagsService.Buscar(request.Nome)).Select(x => (DTO::Tag)x); | ||
} | ||
|
||
[HttpPut()] | ||
public async Task Editar(DTO::Tag request) | ||
{ | ||
await tagsService.Editar(request); | ||
} | ||
} |
Oops, something went wrong.