Update API eliminacion de Generic
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 3m3s
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 3m3s
This commit is contained in:
parent
945da30636
commit
4e15bcfcc1
@ -1,8 +1,10 @@
|
||||
using Domain.Entities;
|
||||
|
||||
namespace Models.Interfaces
|
||||
{
|
||||
public interface IPhSAccountTypeRepository : IGenericRepository<EAccountType>
|
||||
public interface IPhSAccountTypeRepository
|
||||
{
|
||||
Task<IEnumerable<EAccountType>> GetAllAsync();
|
||||
Task<EAccountType?> GetByNameAsync(string name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Interfaces;
|
||||
using Models.Models;
|
||||
|
||||
namespace Models.Repositories
|
||||
{
|
||||
public class GenericRepository<T> : IGenericRepository<T> where T : class
|
||||
{
|
||||
private readonly PhronCareOperationsHubContext _context;
|
||||
private readonly DbSet<T> _dbSet;
|
||||
|
||||
public GenericRepository(PhronCareOperationsHubContext context)
|
||||
{
|
||||
_context = context;
|
||||
_dbSet = _context.Set<T>();
|
||||
}
|
||||
|
||||
public async Task<T?> GetByIdAsync(int id)
|
||||
{
|
||||
return await _dbSet.FindAsync(id);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<T>> GetAllAsync()
|
||||
{
|
||||
return await _dbSet.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task AddAsync(T entity)
|
||||
{
|
||||
await _dbSet.AddAsync(entity);
|
||||
}
|
||||
|
||||
public void Update(T entity)
|
||||
{
|
||||
_dbSet.Update(entity);
|
||||
}
|
||||
|
||||
public void Delete(T entity)
|
||||
{
|
||||
_dbSet.Remove(entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -5,12 +5,13 @@ using Models.Models;
|
||||
|
||||
namespace Models.Repositories
|
||||
{
|
||||
|
||||
public class PhSAccountTypeRepository(PhronCareOperationsHubContext context) : GenericRepository<EAccountType>(context), IPhSAccountTypeRepository
|
||||
public class PhSAccountTypeRepository(PhronCareOperationsHubContext context) : IPhSAccountTypeRepository
|
||||
{
|
||||
#region Declaraciones y Constructor
|
||||
private readonly PhronCareOperationsHubContext _context = context;
|
||||
|
||||
public new async Task<IEnumerable<EAccountType>> GetAllAsync()
|
||||
#endregion
|
||||
#region Metodos de clase
|
||||
public async Task<IEnumerable<EAccountType>> GetAllAsync()
|
||||
{
|
||||
var accountTypes = await _context.PhSAccountTypes.ToListAsync();
|
||||
return accountTypes.Select(at => MapEntity<PhSAccountType, EAccountType>(at));
|
||||
@ -21,6 +22,7 @@ namespace Models.Repositories
|
||||
var accountType = await _context.PhSAccountTypes.FirstOrDefaultAsync(a => a.Name == name);
|
||||
return accountType != null ? MapEntity<PhSAccountType, EAccountType>(accountType) : null;
|
||||
}
|
||||
#endregion
|
||||
#region Métodos Auxiliares
|
||||
private static TDestination MapEntity<TSource, TDestination>(TSource source) where TDestination : new()
|
||||
{
|
||||
|
||||
@ -10,7 +10,6 @@ namespace phronCare.API.Controllers.Sales
|
||||
{
|
||||
private readonly IAccountTypeDom _accountTypeService;
|
||||
|
||||
// Constructor que acepta ITicketDom como parámetro
|
||||
public AccountTypeController(IAccountTypeDom accountTypeService)
|
||||
{
|
||||
_accountTypeService = accountTypeService ?? throw new ArgumentNullException(nameof(accountTypeService));
|
||||
@ -28,5 +27,14 @@ namespace phronCare.API.Controllers.Sales
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
[HttpGet("GetByName/{name}")]
|
||||
public async Task<IActionResult> GetByName(string name)
|
||||
{
|
||||
var result = await _accountTypeService.GetByNameAsync(name);
|
||||
if (result == null)
|
||||
return NotFound($"No se encontró un tipo de cuenta con el nombre '{name}'.");
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user