-
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
457cb6d
commit 167287c
Showing
10 changed files
with
168 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using OpenAdm.Api.Attributes; | ||
using OpenAdm.Application.Dtos.ConfiguracoesDeFrete; | ||
using OpenAdm.Application.Dtos.Response; | ||
using OpenAdm.Application.Interfaces; | ||
using OpenAdm.Application.Models.ConfiguracoesDeFrete; | ||
|
||
namespace OpenAdm.Api.Controllers; | ||
|
||
[ApiController] | ||
[Route("configuracao-de-frete")] | ||
[Autentica] | ||
[IsFuncionario] | ||
public class ConfiguracaoDeFreteController : ControllerBase | ||
{ | ||
private readonly IConfiguracaoDeFreteService _configuracaoDeFreteService; | ||
|
||
public ConfiguracaoDeFreteController(IConfiguracaoDeFreteService configuracaoDeFreteService) | ||
{ | ||
_configuracaoDeFreteService = configuracaoDeFreteService; | ||
} | ||
|
||
[HttpPost] | ||
[ProducesResponseType<ConfiguracaoDeFreteViewModel>(200)] | ||
[ProducesResponseType<ErrorResponse>(400)] | ||
[ProducesResponseType<ErrorResponse>(401)] | ||
public async Task<IActionResult> CreateOrUpdate(ConfiguracaoDeFreteCreateDto configuracaoDeFreteCreateDto) | ||
{ | ||
var response = await _configuracaoDeFreteService.CreateOrUpdateAsync(configuracaoDeFreteCreateDto); | ||
return Ok(response); | ||
} | ||
|
||
[HttpGet] | ||
[ProducesResponseType<ConfiguracaoDeFreteViewModel>(200)] | ||
[ProducesResponseType<ErrorResponse>(400)] | ||
[ProducesResponseType<ErrorResponse>(401)] | ||
public async Task<IActionResult> Get() | ||
{ | ||
var response = await _configuracaoDeFreteService.GetAsync(); | ||
return Ok(response); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
OpenAdm.Application/Dtos/ConfiguracoesDeFrete/ConfiguracaoDeFreteCreateDto.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Domain.Pkg.Entities; | ||
|
||
namespace OpenAdm.Application.Dtos.ConfiguracoesDeFrete; | ||
|
||
public class ConfiguracaoDeFreteCreateDto | ||
{ | ||
public string CepOrigem { get; set; } = string.Empty; | ||
public string AlturaEmbalagem { get; set; } = string.Empty; | ||
public string LarguraEmbalagem { get; set; } = string.Empty; | ||
public string ComprimentoEmbalagem { get; set; } = string.Empty; | ||
public decimal? Peso { get; set; } | ||
|
||
public ConfiguracaoDeFrete ToEntity() | ||
{ | ||
return new ConfiguracaoDeFrete( | ||
id: Guid.NewGuid(), | ||
dataDeCriacao: DateTime.Now, | ||
dataDeAtualizacao: DateTime.Now, | ||
numero:0, | ||
cepOrigem: CepOrigem, | ||
alturaEmbalagem: AlturaEmbalagem, | ||
larguraEmbalagem: LarguraEmbalagem, | ||
comprimentoEmbalagem: ComprimentoEmbalagem, | ||
peso: Peso); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
OpenAdm.Application/Interfaces/IConfiguracaoDeFreteService.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using OpenAdm.Application.Dtos.ConfiguracoesDeFrete; | ||
using OpenAdm.Application.Models.ConfiguracoesDeFrete; | ||
|
||
namespace OpenAdm.Application.Interfaces; | ||
|
||
public interface IConfiguracaoDeFreteService | ||
{ | ||
Task<ConfiguracaoDeFreteViewModel> CreateOrUpdateAsync(ConfiguracaoDeFreteCreateDto configuracaoDeFreteCreateDto); | ||
Task<ConfiguracaoDeFreteViewModel> GetAsync(); | ||
} |
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,5 +1,4 @@ | ||
using Domain.Pkg.Entities; | ||
using System.Text; | ||
|
||
namespace OpenAdm.Application.Models.Banners; | ||
|
||
|
28 changes: 28 additions & 0 deletions
28
OpenAdm.Application/Models/ConfiguracoesDeFrete/ConfiguracaoDeFreteViewModel.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Domain.Pkg.Entities; | ||
|
||
namespace OpenAdm.Application.Models.ConfiguracoesDeFrete; | ||
|
||
public class ConfiguracaoDeFreteViewModel : BaseModel | ||
{ | ||
public string CepOrigem { get; set; } = string.Empty; | ||
public string AlturaEmbalagem { get; set; } = string.Empty; | ||
public string LarguraEmbalagem { get; set; } = string.Empty; | ||
public string ComprimentoEmbalagem { get; set; } = string.Empty; | ||
public decimal? Peso { get; set; } | ||
|
||
public static explicit operator ConfiguracaoDeFreteViewModel(ConfiguracaoDeFrete configuracaoDeFrete) | ||
{ | ||
return new ConfiguracaoDeFreteViewModel() | ||
{ | ||
AlturaEmbalagem = configuracaoDeFrete.AlturaEmbalagem, | ||
CepOrigem = configuracaoDeFrete.CepOrigem, | ||
ComprimentoEmbalagem = configuracaoDeFrete.ComprimentoEmbalagem, | ||
DataDeAtualizacao = configuracaoDeFrete.DataDeAtualizacao, | ||
DataDeCriacao = configuracaoDeFrete.DataDeCriacao, | ||
Id = configuracaoDeFrete.Id, | ||
LarguraEmbalagem = configuracaoDeFrete.LarguraEmbalagem, | ||
Numero = configuracaoDeFrete.Numero, | ||
Peso = configuracaoDeFrete.Peso | ||
}; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
OpenAdm.Application/Services/ConfiguracaoDeFreteService.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using OpenAdm.Application.Dtos.ConfiguracoesDeFrete; | ||
using OpenAdm.Application.Interfaces; | ||
using OpenAdm.Application.Models.ConfiguracoesDeFrete; | ||
using OpenAdm.Domain.Interfaces; | ||
|
||
namespace OpenAdm.Application.Services; | ||
|
||
public sealed class ConfiguracaoDeFreteService : IConfiguracaoDeFreteService | ||
{ | ||
private readonly IConfiguracaoDeFreteRepository _configuracaoDeFreteRepository; | ||
|
||
public ConfiguracaoDeFreteService(IConfiguracaoDeFreteRepository configuracaoDeFreteRepository) | ||
{ | ||
_configuracaoDeFreteRepository = configuracaoDeFreteRepository; | ||
} | ||
|
||
public async Task<ConfiguracaoDeFreteViewModel> CreateOrUpdateAsync( | ||
ConfiguracaoDeFreteCreateDto configuracaoDeFreteCreateDto) | ||
{ | ||
var configuracao = await _configuracaoDeFreteRepository.GetConfiguracaoAsync(); | ||
|
||
if (configuracao == null) | ||
{ | ||
configuracao = configuracaoDeFreteCreateDto.ToEntity(); | ||
await _configuracaoDeFreteRepository.AddAsync(configuracao); | ||
return (ConfiguracaoDeFreteViewModel)configuracao; | ||
} | ||
|
||
configuracao.Update( | ||
cepOrigem: configuracaoDeFreteCreateDto.CepOrigem, | ||
alturaEmbalagem: configuracaoDeFreteCreateDto.AlturaEmbalagem, | ||
larguraEmbalagem: configuracaoDeFreteCreateDto.LarguraEmbalagem, | ||
comprimentoEmbalagem: configuracaoDeFreteCreateDto.ComprimentoEmbalagem, | ||
peso: configuracaoDeFreteCreateDto.Peso); | ||
|
||
await _configuracaoDeFreteRepository.UpdateAsync(configuracao); | ||
|
||
return (ConfiguracaoDeFreteViewModel)configuracao; | ||
} | ||
|
||
public async Task<ConfiguracaoDeFreteViewModel> GetAsync() | ||
{ | ||
var configuracao = await _configuracaoDeFreteRepository.GetConfiguracaoAsync(); | ||
if (configuracao == null) return new(); | ||
|
||
return (ConfiguracaoDeFreteViewModel)configuracao; | ||
} | ||
} |
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