Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoBentoPrisma committed Feb 16, 2024
1 parent 14649a8 commit 53bf889
Show file tree
Hide file tree
Showing 54 changed files with 1,144 additions and 79 deletions.
77 changes: 77 additions & 0 deletions OpenAdm.Api/Controllers/CarrinhoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using OpenAdm.Application.Interfaces;
using OpenAdm.Domain.Model.Carrinho;

namespace OpenAdm.Api.Controllers;

[ApiController]
[Route("carrinho")]
[Authorize(AuthenticationSchemes = "Bearer")]
public class CarrinhoController : ControllerBaseApi
{
private readonly ICarrinhoService _carrinhoService;

public CarrinhoController(ICarrinhoService carrinhoService)
{
_carrinhoService = carrinhoService;
}

[EnableCors("iscasluneoriginwithpost")]
[HttpPut("adicionar")]
public async Task<IActionResult> AdicionarCarinho(AddCarrinhoModel addCarrinhoDto)
{
try
{
await _carrinhoService.AdicionarProdutoAsync(addCarrinhoDto);
return Ok(new { message = "Produto adicionado com sucesso!" });
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}

[HttpGet("get-carrinho")]
public async Task<IActionResult> GetCarrinho()
{
try
{
var result = await _carrinhoService.GetCarrinhoAsync();
return Ok(result);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}

[HttpGet("get-carrinho-count")]
public async Task<IActionResult> GetCarrinhoCount()
{
try
{
var result = await _carrinhoService.GetCountCarrinhoAsync();
return Ok(result);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}

[HttpDelete("delete-produto-carrinho")]
public async Task<IActionResult> DeleteProdutCarrinho([FromQuery] Guid produtoId)
{
try
{
var result = await _carrinhoService.DeleteProdutoCarrinhoAsync(produtoId);
return Ok();
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@ namespace OpenAdm.Api.Controllers;

[ApiController]
[Route("login")]
public class LoginFuncionarioController : ControllerBaseApi
public class LoginController : ControllerBaseApi
{
private readonly ILoginFuncionarioService _loginFuncionarioService;
private readonly ILoginUsuarioService _loginUsuarioService;
private readonly ConfiguracaoDeToken _configGenerateToken;

public LoginFuncionarioController(ILoginFuncionarioService loginFuncionarioService)
public LoginController(
ILoginFuncionarioService loginFuncionarioService,
ILoginUsuarioService loginUsuarioService)
{
var key = VariaveisDeAmbiente.GetVariavel("JWT_KEY");
var issue = VariaveisDeAmbiente.GetVariavel("JWT_ISSUE");
var audience = VariaveisDeAmbiente.GetVariavel("JWT_AUDIENCE");
var expirate = DateTime.Now.AddHours(int.Parse(VariaveisDeAmbiente.GetVariavel("JWT_EXPIRATION")));
_configGenerateToken = new ConfiguracaoDeToken(key, issue, audience, expirate);
_loginFuncionarioService = loginFuncionarioService;
_loginUsuarioService = loginUsuarioService;
}

[HttpPost("funcionario")]
public async Task<IActionResult> Login(RequestLogin requestLogin)
public async Task<IActionResult> LoginFuncionario(RequestLogin requestLogin)
{
try
{
Expand All @@ -35,4 +39,18 @@ public async Task<IActionResult> Login(RequestLogin requestLogin)
return await HandleErrorAsync(ex);
}
}

[HttpPost("usuario")]
public async Task<IActionResult> LoginUsuario(RequestLogin requestLogin)
{
try
{
var responselogin = await _loginUsuarioService.LoginAsync(requestLogin, _configGenerateToken);
return Ok(responselogin);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}
}
12 changes: 12 additions & 0 deletions OpenAdm.Application/Interfaces/ICarrinhoService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using OpenAdm.Application.Models.Carrinhos;
using OpenAdm.Domain.Model.Carrinho;

namespace OpenAdm.Application.Interfaces;

public interface ICarrinhoService
{
Task<bool> AdicionarProdutoAsync(AddCarrinhoModel addCarrinhoModel);
Task<IList<CarrinhoViewModel>> GetCarrinhoAsync();
Task<int> GetCountCarrinhoAsync();
Task<bool> DeleteProdutoCarrinhoAsync(Guid produtoId);
}
9 changes: 9 additions & 0 deletions OpenAdm.Application/Interfaces/ILoginUsuarioService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OpenAdm.Application.Models.Logins;
using OpenAdm.Application.Models.Tokens;

namespace OpenAdm.Application.Interfaces;

public interface ILoginUsuarioService
{
Task<ResponseLoginUsuarioViewModel> LoginAsync(RequestLogin requestLogin, ConfiguracaoDeToken configuracaoDeToken);
}
2 changes: 2 additions & 0 deletions OpenAdm.Application/Interfaces/ITokenService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using OpenAdm.Application.Models.Tokens;
using OpenAdm.Application.Models.Usuarios;

namespace OpenAdm.Application.Interfaces;

public interface ITokenService
{
string GenerateToken(object obj, ConfiguracaoDeToken configGenerateToken);
bool IsFuncionario();
UsuarioViewModel GetTokenUsuarioViewModel();
}
17 changes: 17 additions & 0 deletions OpenAdm.Application/Models/Carrinhos/CarrinhoViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using OpenAdm.Application.Models.Categorias;

namespace OpenAdm.Application.Models.Carrinhos;

public class CarrinhoViewModel
{
public Guid Id { get; set; }
public long Numero { get; set; }
public string Descricao { get; set; } = string.Empty;
public string? EspecificacaoTecnica { get; set; }
public string Foto { get; set; } = string.Empty;
public List<TamanhoCarrinhoViewModel>? Tamanhos { get; set; } = new();
public List<PesoCarrinhoViewModel>? Pesos { get; set; } = new();
public Guid CategoriaId { get; set; }
public CategoriaViewModel? Categoria { get; set; } = null!;
public string? Referencia { get; set; }
}
7 changes: 7 additions & 0 deletions OpenAdm.Application/Models/Carrinhos/PesoCarrinhoViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenAdm.Application.Models.Carrinhos;

public class PesoCarrinhoViewModel : BaseModel
{
public string Descricao { get; set; } = string.Empty;
public QuantidadeProdutoCarrinhoViewModel PrecoProduto { get; set; } = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenAdm.Application.Models.Carrinhos;

public class QuantidadeProdutoCarrinhoViewModel
{
public Guid Id { get; set; }
public decimal Quantidade { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenAdm.Application.Models.Carrinhos;

public class TamanhoCarrinhoViewModel : BaseModel
{
public string Descricao { get; set; } = string.Empty;
public QuantidadeProdutoCarrinhoViewModel PrecoProduto { get; set; } = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OpenAdm.Application.Models.Usuarios;

namespace OpenAdm.Application.Models.Logins;

public class ResponseLoginUsuarioViewModel(UsuarioViewModel usuario, string token)
{
public UsuarioViewModel Usuario { get; set; } = usuario;
public string Token { get; set; } = token;
}
25 changes: 25 additions & 0 deletions OpenAdm.Application/Models/Usuarios/UsuarioViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using OpenAdm.Domain.Entities;

namespace OpenAdm.Application.Models.Usuarios;

public class UsuarioViewModel : BaseModel
{
public string Nome { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string? Telefone { get; set; }
public string? Cnpj { get; set; }

public UsuarioViewModel ToModel(Usuario entity)
{
Id = entity.Id;
DataDeCriacao = entity.DataDeCriacao;
DataDeAtualizacao = entity.DataDeAtualizacao;
Email = entity.Email;
Numero = entity.Numero;
Telefone = entity.Telefone;
Nome = entity.Nome;
Cnpj = entity.Cnpj;

return this;
}
}
6 changes: 3 additions & 3 deletions OpenAdm.Application/Services/BannerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task<BannerViewModel> CreateBannerAsync(BannerCreateDto bannerCreat
public async Task DeleteBannerAsync(Guid id)
{
var banner = await _bannerRepository.GetBannerByIdAsync(id)
?? throw new ExceptionApi(GenericError.RegistroNotFound);
?? throw new ExceptionApi(CodigoErrors.RegistroNotFound);

var result = await _bannerRepository.DeleteAsync(banner);

Expand All @@ -37,7 +37,7 @@ public async Task DeleteBannerAsync(Guid id)
public async Task<BannerViewModel> EditBannerAsync(BannerEditDto bannerEditDto)
{
var banner = await _bannerRepository.GetBannerByIdAsync(bannerEditDto.Id)
?? throw new ExceptionApi(GenericError.RegistroNotFound);
?? throw new ExceptionApi(CodigoErrors.RegistroNotFound);

banner.Update(bannerEditDto.Foto, bannerEditDto.Ativo);

Expand All @@ -49,7 +49,7 @@ public async Task<BannerViewModel> EditBannerAsync(BannerEditDto bannerEditDto)
public async Task<BannerViewModel> GetBannerByIdAsync(Guid id)
{
var banner = await _bannerRepository.GetBannerByIdAsync(id)
?? throw new ExceptionApi(GenericError.RegistroNotFound);
?? throw new ExceptionApi(CodigoErrors.RegistroNotFound);

return new BannerViewModel().ToModel(banner);
}
Expand Down
Loading

0 comments on commit 53bf889

Please sign in to comment.