-
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
e3a1df4
commit 8bb00c1
Showing
26 changed files
with
260 additions
and
22 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,30 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using OpenAdm.Application.Interfaces; | ||
|
||
namespace OpenAdm.Api.Controllers; | ||
|
||
[ApiController] | ||
[Route("home")] | ||
public class HomeController : ControllerBaseApi | ||
{ | ||
private readonly IHomeSevice _homeEcommerSevice; | ||
|
||
public HomeController(IHomeSevice homeEcommerSevice) | ||
{ | ||
_homeEcommerSevice = homeEcommerSevice; | ||
} | ||
|
||
[HttpGet("ecommerce")] | ||
public async Task<IActionResult> ListEcommerce() | ||
{ | ||
try | ||
{ | ||
var home = await _homeEcommerSevice.GetHomeEcommerceAsync(); | ||
return Ok(home); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return await HandleErrorAsync(ex); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using OpenAdm.Application.Models.Home; | ||
|
||
namespace OpenAdm.Application.Interfaces; | ||
|
||
public interface IHomeSevice | ||
{ | ||
Task<HomeECommerceViewModel> GetHomeEcommerceAsync(); | ||
} |
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
4 changes: 2 additions & 2 deletions
4
...Adm.Application/Models/BannerViewModel.cs → ...ication/Models/Banners/BannerViewModel.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
25 changes: 25 additions & 0 deletions
25
OpenAdm.Application/Models/Categorias/CategoriaViewModel.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,25 @@ | ||
using OpenAdm.Application.Models.Produtos; | ||
using OpenAdm.Domain.Entities; | ||
using System.Text; | ||
|
||
namespace OpenAdm.Application.Models.Categorias; | ||
|
||
public class CategoriaViewModel : BaseModel | ||
{ | ||
public string Descricao { get; set; } = string.Empty; | ||
public string? Foto { get; set; } | ||
public List<ProdutoViewModel>? Produtos { get; set; } | ||
|
||
public CategoriaViewModel ToModel(Categoria entity) | ||
{ | ||
Id = entity.Id; | ||
DataDeCriacao = entity.DataDeCriacao; | ||
DataDeAtualizacao = entity.DataDeAtualizacao; | ||
Numero = entity.Numero; | ||
Descricao = entity.Descricao; | ||
Foto = entity.Foto != null ? Encoding.UTF8.GetString(entity.Foto) : null; | ||
Produtos = entity.Produtos.Select(x => new ProdutoViewModel().ToModel(x)).ToList(); | ||
|
||
return this; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...pplication/Models/FuncionarioViewModel.cs → ...dels/Funcionarios/FuncionarioViewModel.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
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,12 @@ | ||
using OpenAdm.Application.Models.Banners; | ||
using OpenAdm.Application.Models.Categorias; | ||
using OpenAdm.Application.Models.Produtos; | ||
|
||
namespace OpenAdm.Application.Models.Home; | ||
|
||
public class HomeECommerceViewModel | ||
{ | ||
public IList<BannerViewModel> Banners { get; set; } = new List<BannerViewModel>(); | ||
public IList<CategoriaViewModel> Categorias { get; set; } = new List<CategoriaViewModel>(); | ||
public IList<ProdutoViewModel> ProdutosMaisVendidos { get; set; } = new List<ProdutoViewModel>(); | ||
} |
2 changes: 1 addition & 1 deletion
2
OpenAdm.Application/Models/RequestLogin.cs → ...Application/Models/Logins/RequestLogin.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
4 changes: 3 additions & 1 deletion
4
...dels/ResponseLoginFuncionarioViewModel.cs → ...gins/ResponseLoginFuncionarioViewModel.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
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,37 @@ | ||
using OpenAdm.Application.Models.Categorias; | ||
using OpenAdm.Domain.Entities; | ||
using System.Text; | ||
|
||
namespace OpenAdm.Application.Models.Produtos; | ||
|
||
public class ProdutoViewModel : BaseModel | ||
{ | ||
public string Descricao { get; set; } = string.Empty; | ||
public string? EspecificacaoTecnica { get; set; } | ||
public string Foto { get; set; } = string.Empty; | ||
//public List<TamanhoViewModel>? Tamanhos { get; set; } = new(); | ||
//public List<PesoViewModel>? Pesos { get; set; } = new(); | ||
public Guid CategoriaId { get; set; } | ||
public CategoriaViewModel? Categoria { get; set; } = null!; | ||
public string? Referencia { get; private set; } | ||
public ProdutoViewModel ToModel(Produto entity) | ||
{ | ||
|
||
Id = entity.Id; | ||
DataDeCriacao = entity.DataDeCriacao; | ||
DataDeAtualizacao = entity.DataDeAtualizacao; | ||
Numero = entity.Numero; | ||
Descricao = entity.Descricao; | ||
EspecificacaoTecnica = entity.EspecificacaoTecnica; | ||
Foto = Encoding.UTF8.GetString(entity.Foto); | ||
//Tamanhos = entity.Tamanhos.OrderBy(x => x.Numero).Select(x => new TamanhoViewModel().ForModel(x) ?? new()).ToList(); | ||
//Pesos = entity.Pesos.OrderBy(x => x.Numero).Select(x => new PesoViewModel().ForModel(x) ?? new()).ToList(); | ||
|
||
if (entity.Categoria != null) | ||
Categoria = new CategoriaViewModel().ToModel(entity.Categoria); | ||
|
||
CategoriaId = entity.CategoriaId; | ||
Referencia = entity.Referencia; | ||
return this; | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
...Application/Models/ConfiguracaoDeToken.cs → ...tion/Models/Tokens/ConfiguracaoDeToken.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using OpenAdm.Application.Interfaces; | ||
using OpenAdm.Application.Models.Banners; | ||
using OpenAdm.Application.Models.Categorias; | ||
using OpenAdm.Application.Models.Home; | ||
using OpenAdm.Application.Models.Produtos; | ||
using OpenAdm.Domain.Interfaces; | ||
|
||
namespace OpenAdm.Application.Services; | ||
|
||
public class HomeSevice : IHomeSevice | ||
{ | ||
private readonly ICategoriaRepository _categoryRepository; | ||
private readonly IProdutoRepository _produtoRepository; | ||
private readonly IBannerRepository _bannerRepository; | ||
|
||
public HomeSevice( | ||
ICategoriaRepository categoryRepository, | ||
IProdutoRepository produtoRepository, | ||
IBannerRepository bannerRepository) | ||
{ | ||
_categoryRepository = categoryRepository; | ||
_produtoRepository = produtoRepository; | ||
_bannerRepository = bannerRepository; | ||
} | ||
|
||
public async Task<HomeECommerceViewModel> GetHomeEcommerceAsync() | ||
{ | ||
var banners = await _bannerRepository.GetBannersAsync(); | ||
var categorias = await _categoryRepository.GetCategoriasAsync(); | ||
var produtosMaisVendidos = await _produtoRepository.GetProdutosMaisVendidosAsync(); | ||
|
||
return new HomeECommerceViewModel() | ||
{ | ||
Banners = banners.Select(x => new BannerViewModel().ToModel(x)).ToList(), | ||
Categorias = categorias.Select(x => new CategoriaViewModel().ToModel(x)).ToList(), | ||
ProdutosMaisVendidos = produtosMaisVendidos.Select(x => new ProdutoViewModel().ToModel(x)).ToList(), | ||
}; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using OpenAdm.Domain.Entities; | ||
|
||
namespace OpenAdm.Domain.Interfaces; | ||
|
||
public interface ICategoriaRepository : IGenericRepository<Categoria> | ||
{ | ||
Task<IList<Categoria>> GetCategoriasAsync(); | ||
} |
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,8 @@ | ||
using OpenAdm.Domain.Entities; | ||
|
||
namespace OpenAdm.Domain.Interfaces; | ||
|
||
public interface IProdutoRepository : IGenericRepository<Produto> | ||
{ | ||
Task<IList<Produto>> GetProdutosMaisVendidosAsync(); | ||
} |
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,20 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using OpenAdm.Domain.Entities; | ||
using OpenAdm.Domain.Interfaces; | ||
using OpenAdm.Infra.Context; | ||
|
||
namespace OpenAdm.Infra.Repositories; | ||
|
||
public class CategoriaRepository(ParceiroContext parceiroContext) | ||
: GenericRepository<Categoria>(parceiroContext), ICategoriaRepository | ||
{ | ||
private readonly ParceiroContext _parceiroContext = parceiroContext; | ||
|
||
public async Task<IList<Categoria>> GetCategoriasAsync() | ||
{ | ||
return await _parceiroContext | ||
.Categorias | ||
.AsNoTracking() | ||
.ToListAsync(); | ||
} | ||
} |
Oops, something went wrong.