-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
146cdba
commit 65bc11a
Showing
77 changed files
with
717 additions
and
1,157 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
42 changes: 24 additions & 18 deletions
42
OpenAdm.Api/Controllers/Carrinhos/AddCarrinhoController.cs
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,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
25
OpenAdm.Api/Controllers/Carrinhos/CoutCarrinhoController.cs
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,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); | ||
} | ||
} |
24 changes: 9 additions & 15 deletions
24
OpenAdm.Api/Controllers/Carrinhos/DeleteProdutoCarrinhoController.cs
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,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
38
OpenAdm.Api/Controllers/Carrinhos/GetCarrinhoController.cs
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,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); | ||
} | ||
} |
Oops, something went wrong.