Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunobento1990 committed Jul 6, 2024
1 parent 146cdba commit 65bc11a
Show file tree
Hide file tree
Showing 77 changed files with 717 additions and 1,157 deletions.
78 changes: 18 additions & 60 deletions OpenAdm.Api/Controllers/BannerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,103 +10,61 @@ namespace OpenAdm.Api.Controllers;

[ApiController]
[Route("banners")]
public class BannerController(IBannerService bannerService) : ControllerBaseApi
public class BannerController(IBannerService bannerService) : ControllerBase
{
private readonly IBannerService _bannerService = bannerService;

[HttpGet("list")]
[ResponseCache(CacheProfileName = "Default300")]
public async Task<IActionResult> ListarBanners()
{
try
{
var bannersViewModel = await _bannerService.GetBannersAsync();
return Ok(bannersViewModel);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
var bannersViewModel = await _bannerService.GetBannersAsync();
return Ok(bannersViewModel);
}

[Authorize(AuthenticationSchemes = "Bearer")]
[Autentica]
[IsFuncionario]
[HttpGet("paginacao")]
public async Task<IActionResult> Paginacao([FromQuery] PaginacaoBannerDto paginacaoBannerDto)
{
try
{
var paginacaoViewModel = await _bannerService.GetPaginacaoAsync(paginacaoBannerDto);
return Ok(paginacaoViewModel);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
var paginacaoViewModel = await _bannerService.GetPaginacaoAsync(paginacaoBannerDto);
return Ok(paginacaoViewModel);
}

[Authorize(AuthenticationSchemes = "Bearer")]
[Autentica]
[IsFuncionario]
[HttpPost("create")]
public async Task<IActionResult> Create(BannerCreateDto bannerCreateDto)
{
try
{
var result = await _bannerService.CreateBannerAsync(bannerCreateDto);
return Ok(result);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
var result = await _bannerService.CreateBannerAsync(bannerCreateDto);
return Ok(result);
}

[ResponseCache(CacheProfileName = "Default300")]
[Authorize(AuthenticationSchemes = "Bearer")]
[Autentica]
[IsFuncionario]
[HttpGet("get-banner")]
public async Task<IActionResult> GetBanner([FromQuery] Guid id)
{
try
{
var bannerViewModel = await _bannerService.GetBannerByIdAsync(id);
return Ok(bannerViewModel);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
var bannerViewModel = await _bannerService.GetBannerByIdAsync(id);
return Ok(bannerViewModel);
}

[Authorize(AuthenticationSchemes = "Bearer")]
[Autentica]
[IsFuncionario]
[HttpDelete("delete")]
public async Task<IActionResult> DeleteBanner([FromQuery] Guid id)
{
try
{
await _bannerService.DeleteBannerAsync(id);
return Ok();
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
await _bannerService.DeleteBannerAsync(id);
return Ok();
}

[Authorize(AuthenticationSchemes = "Bearer")]
[Autentica]
[IsFuncionario]
[HttpPut("update")]
public async Task<IActionResult> EditBanner(BannerEditDto bannerEditDto)
{
try
{
var bannerViewModel = await _bannerService.EditBannerAsync(bannerEditDto);
return Ok(bannerViewModel);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
var bannerViewModel = await _bannerService.EditBannerAsync(bannerEditDto);
return Ok(bannerViewModel);
}
}
42 changes: 24 additions & 18 deletions OpenAdm.Api/Controllers/Carrinhos/AddCarrinhoController.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAdm.Application.Interfaces;
using Microsoft.AspNetCore.Mvc;
using OpenAdm.Api.Attributes;
using OpenAdm.Application.Interfaces.Carrinhos;
using OpenAdm.Application.Models.Usuarios;
using OpenAdm.Domain.Interfaces;
using OpenAdm.Domain.Model.Carrinho;

namespace OpenAdm.Api.Controllers.Carrinhos;


[ApiController]
[Route("carrinho")]
[Authorize(AuthenticationSchemes = "Bearer")]
public class AddCarrinhoController : ControllerBaseApi
[Autentica]
public class AddCarrinhoController : ControllerBase
{
private readonly IAddCarrinhoService _addCarrinhoSerice;
private readonly ITokenService _tokenService;

public AddCarrinhoController(IAddCarrinhoService addCarrinhoSerice, ITokenService tokenService)
private readonly IUsuarioAutenticado _usuarioAutenticado;
public AddCarrinhoController(
IAddCarrinhoService addCarrinhoSerice,
IUsuarioAutenticado usuarioAutenticado)
{
_addCarrinhoSerice = addCarrinhoSerice;
_tokenService = tokenService;
_usuarioAutenticado = usuarioAutenticado;
}

[HttpPut("adicionar")]
public async Task<IActionResult> AdicionarCarinho(IList<AddCarrinhoModel> addCarrinhoDto)
{
try
{
var usuarioViewModel = _tokenService.GetTokenUsuarioViewModel();
await _addCarrinhoSerice.AddCarrinhoAsync(addCarrinhoDto, usuarioViewModel);
return Ok(new { message = "Produto adicionado com sucesso!" });
}
catch (Exception ex)
var usuario = await _usuarioAutenticado.GetUsuarioAutenticadoAsync();
await _addCarrinhoSerice.AddCarrinhoAsync(addCarrinhoDto, new UsuarioViewModel()
{
return await HandleErrorAsync(ex);
}
Cnpj = usuario.Cnpj,
Cpf = usuario.Cpf,
DataDeAtualizacao = usuario.DataDeAtualizacao,
DataDeCriacao = usuario.DataDeCriacao,
Email = usuario.Email,
Id = usuario.Id,
Nome = usuario.Nome,
Numero = usuario.Numero,
Telefone = usuario.Telefone
});
return Ok(new { message = "Produto adicionado com sucesso!" });
}
}
25 changes: 9 additions & 16 deletions OpenAdm.Api/Controllers/Carrinhos/CoutCarrinhoController.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAdm.Application.Interfaces;
using Microsoft.AspNetCore.Mvc;
using OpenAdm.Api.Attributes;
using OpenAdm.Application.Interfaces.Carrinhos;
using OpenAdm.Domain.Interfaces;

namespace OpenAdm.Api.Controllers.Carrinhos;

[ApiController]
[Route("carrinho")]
[Authorize(AuthenticationSchemes = "Bearer")]
public class CoutCarrinhoController : ControllerBaseApi
[Autentica]
public class CoutCarrinhoController : ControllerBase
{
private readonly IGetCountCarrinhoService _carrinhoService;
private readonly Guid _usuarioId;

public CoutCarrinhoController(IGetCountCarrinhoService carrinhoService,
ITokenService tokenService)
IUsuarioAutenticado usuarioAutenticado)
{
_usuarioId = tokenService.GetTokenUsuarioViewModel().Id;
_usuarioId = usuarioAutenticado.Id;
_carrinhoService = carrinhoService;
}

[HttpGet("get-carrinho-count")]
public async Task<IActionResult> GetCarrinhoCount()
{
try
{
var result = await _carrinhoService.GetCountCarrinhoAsync(_usuarioId);
return Ok(result);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
var result = await _carrinhoService.GetCountCarrinhoAsync(_usuarioId);
return Ok(result);
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using OpenAdm.Api.Attributes;
using OpenAdm.Application.Interfaces;
using OpenAdm.Application.Interfaces.Carrinhos;
using OpenAdm.Domain.Interfaces;

namespace OpenAdm.Api.Controllers.Carrinhos;

[ApiController]
[Route("carrinho")]
[Authorize(AuthenticationSchemes = "Bearer")]
public class DeleteProdutoCarrinhoController : ControllerBaseApi
[Autentica]
public class DeleteProdutoCarrinhoController : ControllerBase
{
private readonly IDeleteProdutoCarrinhoService _deleteProdutoCarrinhoService;
private readonly Guid _usuarioId;

public DeleteProdutoCarrinhoController(
IDeleteProdutoCarrinhoService deleteProdutoCarrinhoService,
ITokenService tokenService)
IUsuarioAutenticado usuarioAutenticado)
{
_usuarioId = tokenService.GetTokenUsuarioViewModel().Id;
_usuarioId = usuarioAutenticado.Id;
_deleteProdutoCarrinhoService = deleteProdutoCarrinhoService;
}

[HttpDelete("delete-produto-carrinho")]
public async Task<IActionResult> DeleteProdutCarrinho([FromQuery] Guid produtoId)
{
try
{
var result = await _deleteProdutoCarrinhoService.DeleteProdutoCarrinhoAsync(produtoId, _usuarioId);
return Ok();
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
var result = await _deleteProdutoCarrinhoService.DeleteProdutoCarrinhoAsync(produtoId, _usuarioId);
return Ok();
}
}
38 changes: 22 additions & 16 deletions OpenAdm.Api/Controllers/Carrinhos/GetCarrinhoController.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using OpenAdm.Api.Attributes;
using OpenAdm.Application.Interfaces;
using OpenAdm.Application.Interfaces.Carrinhos;
using OpenAdm.Application.Models.Usuarios;
using OpenAdm.Domain.Interfaces;

namespace OpenAdm.Api.Controllers.Carrinhos;

[ApiController]
[Route("carrinho")]
[Authorize(AuthenticationSchemes = "Bearer")]
public class GetCarrinhoController : ControllerBaseApi
[Autentica]
public class GetCarrinhoController : ControllerBase
{
private readonly IGetCarrinhoService _getCarrinhoService;
private readonly ITokenService _tokenService;
private readonly IUsuarioAutenticado _usuarioAutenticado;

public GetCarrinhoController(IGetCarrinhoService getCarrinhoService, ITokenService tokenService)
public GetCarrinhoController(IGetCarrinhoService getCarrinhoService, IUsuarioAutenticado usuarioAutenticado)
{
_getCarrinhoService = getCarrinhoService;
_tokenService = tokenService;
_usuarioAutenticado = usuarioAutenticado;
}

[HttpGet("get-carrinho")]
public async Task<IActionResult> GetCarrinho()
{
try
var usuario = await _usuarioAutenticado.GetUsuarioAutenticadoAsync();
var result = await _getCarrinhoService.GetCarrinhoAsync(new UsuarioViewModel()
{
var usuarioViewModel = _tokenService.GetTokenUsuarioViewModel();
var result = await _getCarrinhoService.GetCarrinhoAsync(usuarioViewModel);
return Ok(result);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
Cnpj = usuario.Cnpj,
Cpf = usuario.Cpf,
DataDeAtualizacao = usuario.DataDeAtualizacao,
DataDeCriacao = usuario.DataDeCriacao,
Email = usuario.Email,
Id = usuario.Id,
Nome = usuario.Nome,
Numero = usuario.Numero,
Telefone = usuario.Telefone
});
return Ok(result);
}
}
Loading

0 comments on commit 65bc11a

Please sign in to comment.