diff --git a/Aspnet/Controllers/DefectoController.cs b/Aspnet/Controllers/DefectoController.cs new file mode 100644 index 0000000..9d635f5 --- /dev/null +++ b/Aspnet/Controllers/DefectoController.cs @@ -0,0 +1,46 @@ +using Entidades; +using Entidades.Dto; +using Microsoft.AspNetCore.Mvc; +using Modelo; + +namespace AlquilaFacil.Controllers; + +[ApiController] +public class DefectoController: ControllerBase { + + [HttpGet("api/defectos")] + public IActionResult ObtenerDefectosEnContrato([FromHeader(Name = "Auth")] string Auth, long Idcontrato = 0) { + if (Idcontrato <= 0) return BadRequest( new { message = "La id de contrato no puede ser menor o igual a 0"}); + + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false){ + validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false) { + return Unauthorized(); + } + } + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return Unauthorized(); + + Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(Idcontrato); + if (cont == null) return BadRequest(new { message = "No hay contrato por esa id"}); + + if (cont.Dniinquilino != cli.Dni && cont.Dnipropietario != cli.Dni) return BadRequest(new { message = "no deberias tener acceso a esto"}); + + var l = RepositorioDefectos.Singleton.ObtenerDefectosPorIdContrato(Idcontrato); + return Ok(l); + + } + + [HttpPost("api/defecto")] // WIP tengo que hablar con mi madre + public IActionResult AltaDefecto([FromHeader(Name = "Auth")] string Auth, AltaDefectoDto data) { + + } + + [HttpPut("api/defecto/marcarpago")] // WIP Prerequisito tener altadefecto + public IActionResult MarcarPago([FromHeader(Name = "Auth")] string Auth, long iddefecto = 0) { + + } +} diff --git a/Entidades/Dto/AltaDefectoDto.cs b/Entidades/Dto/AltaDefectoDto.cs new file mode 100644 index 0000000..c8105ac --- /dev/null +++ b/Entidades/Dto/AltaDefectoDto.cs @@ -0,0 +1,8 @@ +namespace Entidades.Dto; +public class AltaDefectoDto { + public string Descripcion { get; set; } =""; + public Decimal Costo { get; set; } + public ulong Pagainquilino { get; set; } + public int Iddivisa { get; set; } + public long Idcontrato { get; set; } +} \ No newline at end of file diff --git a/Entidades/Dto/DefectoDto.cs b/Entidades/Dto/DefectoDto.cs new file mode 100644 index 0000000..81d6eb7 --- /dev/null +++ b/Entidades/Dto/DefectoDto.cs @@ -0,0 +1,10 @@ +namespace Entidades.Dto; +public class DefectoDto { + public long Id { get; set;} + public string Descripcion { get; set;} =""; + public Decimal Costo { get; set;} + public int Idestado { get; set;} + public long Idcontrato { get; set;} + public bool Pagainquilino { get; set;} + public int Iddivisa { get; set;} +} \ No newline at end of file diff --git a/Modelo/RepositorioDefectos.cs b/Modelo/RepositorioDefectos.cs new file mode 100644 index 0000000..2b039a5 --- /dev/null +++ b/Modelo/RepositorioDefectos.cs @@ -0,0 +1,12 @@ +using Entidades; + +namespace Modelo; + +public class RepositorioDefectos: RepositorioBase { + public IQueryable ObtenerDefectosPorIdContrato(long idcontrato){ + var con = Context; + + var l = con.Defectos.Where(x=>x.Idcontrato == idcontrato); + return l; + } +} \ No newline at end of file