Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunobento1990 committed Feb 17, 2024
1 parent 53bf889 commit 9f7ed55
Show file tree
Hide file tree
Showing 42 changed files with 897 additions and 14 deletions.
1 change: 0 additions & 1 deletion OpenAdm.Api/Controllers/CarrinhoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public CarrinhoController(ICarrinhoService carrinhoService)
_carrinhoService = carrinhoService;
}

[EnableCors("iscasluneoriginwithpost")]
[HttpPut("adicionar")]
public async Task<IActionResult> AdicionarCarinho(AddCarrinhoModel addCarrinhoDto)
{
Expand Down
31 changes: 31 additions & 0 deletions OpenAdm.Api/Controllers/EsqueceuSenhaController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Mvc;
using OpenAdm.Application.Dtos.Usuarios;
using OpenAdm.Application.Interfaces;

namespace OpenAdm.Api.Controllers;

[ApiController]
[Route("usuarios")]
public class EsqueceuSenhaController : ControllerBaseApi
{
private readonly IEsqueceuSenhaService _esqueceuSenhaService;

public EsqueceuSenhaController(IEsqueceuSenhaService esqueceuSenhaService)
{
_esqueceuSenhaService = esqueceuSenhaService;
}

[HttpPut("esqueceu-senha")]
public async Task<IActionResult> ResetarSenha(EsqueceuSenhaDto esqueceuSenhaDto)
{
try
{
await _esqueceuSenhaService.EsqueceuSenhaAsync(esqueceuSenhaDto);
return Ok();
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}
}
32 changes: 32 additions & 0 deletions OpenAdm.Api/Controllers/ItensPedidoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAdm.Application.Interfaces;

namespace OpenAdm.Api.Controllers;

[ApiController]
[Route("itens-pedidos")]
[Authorize(AuthenticationSchemes = "Bearer")]
public class ItensPedidoController : ControllerBaseApi
{
private readonly IItensPedidoService _itensPedidoService;

public ItensPedidoController(IItensPedidoService itensPedidoService)
{
_itensPedidoService = itensPedidoService;
}

[HttpGet("get-pedido-id")]
public async Task<IActionResult> GetByPedido([FromQuery] Guid pedidoId)
{
try
{
var itens = await _itensPedidoService.GetItensPedidoByPedidoIdAsync(pedidoId);
return Ok(itens);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}
}
18 changes: 15 additions & 3 deletions OpenAdm.Api/Controllers/PedidoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace OpenAdm.Api.Controllers;

[ApiController]
[Route("pedidos")]
[Authorize(AuthenticationSchemes = "Bearer")]
public class PedidoController : ControllerBaseApi
{
private readonly IPedidoService _pedidoService;
Expand All @@ -18,7 +19,6 @@ public PedidoController(IPedidoService pedidoService)
_pedidoService = pedidoService;
}

[Authorize(AuthenticationSchemes = "Bearer")]
[IsFuncionario]
[HttpGet("paginacao")]
public async Task<IActionResult> Paginacao([FromQuery] PaginacaoPedidoDto paginacaoPedidoDto)
Expand All @@ -34,7 +34,6 @@ public async Task<IActionResult> Paginacao([FromQuery] PaginacaoPedidoDto pagina
}
}

[Authorize(AuthenticationSchemes = "Bearer")]
[IsFuncionario]
[HttpPut("update-status")]
public async Task<IActionResult> UpdateStatusPedido(UpdateStatusPedidoDto updateStatusPedidoDto)
Expand All @@ -50,7 +49,6 @@ public async Task<IActionResult> UpdateStatusPedido(UpdateStatusPedidoDto update
}
}

[Authorize(AuthenticationSchemes = "Bearer")]
[IsFuncionario]
[HttpDelete("delete")]
public async Task<IActionResult> Delete([FromQuery] Guid id)
Expand All @@ -65,4 +63,18 @@ public async Task<IActionResult> Delete([FromQuery] Guid id)
return await HandleErrorAsync(ex);
}
}

[HttpGet("list")]
public async Task<IActionResult> GetPedidos([FromQuery] int statusPedido)
{
try
{
var pedidos = await _pedidoService.GetPedidosUsuarioAsync(statusPedido);
return Ok(pedidos);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}
}
56 changes: 56 additions & 0 deletions OpenAdm.Api/Controllers/UsuarioController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAdm.Application.Dtos.Usuarios;
using OpenAdm.Application.Interfaces;
using OpenAdm.Application.Models.Tokens;

namespace OpenAdm.Api.Controllers;

[ApiController]
[Route("usuarios")]
public class UsuarioController : ControllerBaseApi
{
private readonly IUsuarioService _usuarioService;
private readonly ConfiguracaoDeToken _configGenerateToken;

public UsuarioController(IUsuarioService usuarioService)
{
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);
_usuarioService = usuarioService;
}

[Authorize(AuthenticationSchemes = "Bearer")]
[HttpGet("get-conta")]
public async Task<IActionResult> GetConta()
{
try
{
var usuarioViewModel = await _usuarioService.GetUsuarioByIdAsync();
return Ok(usuarioViewModel);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}

[Authorize(AuthenticationSchemes = "Bearer")]
[HttpPut("update")]
public async Task<IActionResult> UpdateUsuario(UpdateUsuarioDto updateUsuarioDto)
{
try
{
var result = await _usuarioService.UpdateUsuarioAsync(updateUsuarioDto, _configGenerateToken);

return Ok(result);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}
}
11 changes: 11 additions & 0 deletions OpenAdm.Application/Dtos/Usuarios/EsqueceuSenhaDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;

namespace OpenAdm.Application.Dtos.Usuarios;

public class EsqueceuSenhaDto
{
[Required]
[MaxLength(255)]
[DataType(DataType.EmailAddress)]
public string Email { get; set; } = string.Empty;
}
18 changes: 18 additions & 0 deletions OpenAdm.Application/Dtos/Usuarios/UpdateUsuarioDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;

namespace OpenAdm.Application.Dtos.Usuarios;

public class UpdateUsuarioDto
{
[Required]
[MaxLength(255)]
public string Nome { get; set; } = string.Empty;
[Required]
[MaxLength(255)]
[DataType(DataType.EmailAddress)]
public string Email { get; set; } = string.Empty;
[MaxLength(15)]
public string? Telefone { get; set; }
[MaxLength(20)]
public string? Cnpj { get; set; }
}
8 changes: 8 additions & 0 deletions OpenAdm.Application/Interfaces/IEmailService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using OpenAdm.Application.Models.Emails;

namespace OpenAdm.Application.Interfaces;

public interface IEmailService
{
Task<bool> SendEmail(EnvioEmailModel envioEmailModel);
}
8 changes: 8 additions & 0 deletions OpenAdm.Application/Interfaces/IEsqueceuSenhaService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using OpenAdm.Application.Dtos.Usuarios;

namespace OpenAdm.Application.Interfaces;

public interface IEsqueceuSenhaService
{
Task<bool> EsqueceuSenhaAsync(EsqueceuSenhaDto esqueceuSenhaDto);
}
8 changes: 8 additions & 0 deletions OpenAdm.Application/Interfaces/IItensPedidoService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using OpenAdm.Application.Models.Pedidos;

namespace OpenAdm.Application.Interfaces;

public interface IItensPedidoService
{
Task<IList<ItensPedidoViewModel>> GetItensPedidoByPedidoIdAsync(Guid pedidoId);
}
2 changes: 2 additions & 0 deletions OpenAdm.Application/Interfaces/IPedidoService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OpenAdm.Application.Dtos.Pedidos;
using OpenAdm.Application.Models.Pedidos;
using OpenAdm.Domain.Model;
using OpenAdm.Domain.PaginateDto;

Expand All @@ -9,4 +10,5 @@ public interface IPedidoService
Task<PaginacaoViewModel<PedidoViewModel>> GetPaginacaoAsync(PaginacaoPedidoDto paginacaoPedidoDto);
Task<PedidoViewModel> UpdateStatusPedidoAsync(UpdateStatusPedidoDto updateStatusPedidoDto);
Task<bool> DeletePedidoAsync(Guid id);
Task<List<PedidoViewModel>> GetPedidosUsuarioAsync(int statusPedido);
}
12 changes: 12 additions & 0 deletions OpenAdm.Application/Interfaces/IUsuarioService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using OpenAdm.Application.Dtos.Usuarios;
using OpenAdm.Application.Models.Logins;
using OpenAdm.Application.Models.Tokens;
using OpenAdm.Application.Models.Usuarios;

namespace OpenAdm.Application.Interfaces;

public interface IUsuarioService
{
Task<UsuarioViewModel> GetUsuarioByIdAsync();
Task<ResponseLoginUsuarioViewModel> UpdateUsuarioAsync(UpdateUsuarioDto updateUsuarioDto, ConfiguracaoDeToken configuracaoDeToken);
}
11 changes: 11 additions & 0 deletions OpenAdm.Application/Models/Emails/EnvioEmailModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace OpenAdm.Application.Models.Emails;

public class EnvioEmailModel
{
public string Email { get; set; } = string.Empty;
public string Mensagem { get; set; } = string.Empty;
public string Assunto { get; set; } = string.Empty;
public string? NomeDoArquivo { get; set; }
public string? TipoDoArquivo { get; set; }
public byte[]? Arquivo { get; set; }
}
47 changes: 47 additions & 0 deletions OpenAdm.Application/Models/Pedidos/ItensPedidoViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using OpenAdm.Application.Models.Pesos;
using OpenAdm.Application.Models.Produtos;
using OpenAdm.Application.Models.Tamanhos;
using OpenAdm.Domain.Entities;

namespace OpenAdm.Application.Models.Pedidos;

public class ItensPedidoViewModel : BaseModel
{
public Guid? PesoId { get; set; }
public PesoViewModel? Peso { get; set; }
public Guid? TamanhoId { get; set; }
public TamanhoViewModel? Tamanho { get; set; }
public Guid ProdutoId { get; set; }
public ProdutoViewModel Produto { get; set; } = null!;
public Guid PedidoId { get; set; }
public decimal ValorUnitario { get; set; }
public decimal Quantidade { get; set; }
public decimal ValorTotal { get; set; }
public ItensPedidoViewModel ToModel(ItensPedido entity)
{
Id = entity.Id;
DataDeCriacao = entity.DataDeCriacao;
Numero = entity.Numero;
PesoId = entity.PesoId;
TamanhoId = entity.TamanhoId;
ProdutoId = entity.ProdutoId;
PedidoId = entity.PedidoId;

if (entity.Peso != null)
{
Peso = new PesoViewModel().ToModel(entity.Peso);
}

if (entity.Tamanho != null)
{
Tamanho = new TamanhoViewModel().ToModel(entity.Tamanho);
}

Produto = new ProdutoViewModel().ToModel(entity.Produto) ?? new();
ValorUnitario = entity.ValorUnitario;
ValorTotal = entity.ValorTotal;
Quantidade = entity.Quantidade;

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using OpenAdm.Domain.Entities;
using OpenAdm.Domain.Enums;

namespace OpenAdm.Application.Dtos.Pedidos;
namespace OpenAdm.Application.Models.Pedidos;

public class PedidoViewModel : BaseViewModel
{
Expand All @@ -16,7 +16,9 @@ public PedidoViewModel ForModel(Pedido entity)
Numero = entity.Numero;
ValorTotal = entity.ValorTotal;
StatusPedido = entity.StatusPedido;
Usuario = entity.Usuario.Nome;

if (entity.Usuario != null)
Usuario = entity.Usuario.Nome;

return this;
}
Expand Down
19 changes: 19 additions & 0 deletions OpenAdm.Application/Models/Pesos/PesoViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using OpenAdm.Application.Models;
using OpenAdm.Domain.Entities;

namespace OpenAdm.Application.Models.Pesos;

public class PesoViewModel : BaseModel
{
public string Descricao { get; set; } = string.Empty;

public PesoViewModel ToModel(Peso entity)
{
Id = entity.Id;
Descricao = entity.Descricao;
DataDeCriacao = entity.DataDeCriacao;
DataDeAtualizacao = entity.DataDeAtualizacao;
Numero = entity.Numero;
return this;
}
}
Loading

0 comments on commit 9f7ed55

Please sign in to comment.