diff --git a/Aspnet/Controllers/PropiedadesController.cs b/Aspnet/Controllers/PropiedadesController.cs index 05daf81..bfc470c 100644 --- a/Aspnet/Controllers/PropiedadesController.cs +++ b/Aspnet/Controllers/PropiedadesController.cs @@ -73,6 +73,35 @@ public class PropiedadesController: ControllerBase { BadRequest(new { message = "Fallo al momento de añadir la propiedad a la base de datos"}); } + [HttpPatch("api/propiedad")] + public IActionResult PatchPropiedad([FromBody] PatchPropiedadDto propiedad, [FromHeader(Name = "Auth")] string Auth) { + + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 1); + if (validacion1 == false) return Unauthorized(); + + string validacion2 = ValidarPropiedad(propiedad); + if (validacion2 != "") return BadRequest(new { message = validacion2 }); + + Cliente? cli = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(propiedad.Email); + if (cli == null) return BadRequest(new { message = "El email no corresponde a un propietario"}); + + Propiedade Prop = new Propiedade{ + Id = propiedad.id, + Canthabitaciones = propiedad.Canthabitaciones, + Dnipropietario = cli.Dni, + Idtipropiedad = propiedad.tipo, + Ubicacion = propiedad.Ubicacion, + Letra = propiedad.Letra ?? null, + Piso = propiedad.Piso ?? null, + }; + + bool ret = RepositorioPropiedades.Singleton.PatchPropiedad(Prop); + return (ret)? + Ok(new {message = "Fue modificado Correctamente"}): + BadRequest(new {message = "Fallo al modificar la base de datos"}); + } + [HttpDelete("api/propiedad")] public IActionResult BajaPropiedad(int id, [FromHeader(Name = "Auth")] string Auth, [FromHeader(Name = "Email")] string email){ if (String.IsNullOrEmpty(Auth)) return Unauthorized(); @@ -140,8 +169,29 @@ public class PropiedadesController: ControllerBase { string ret = ""; if (String.IsNullOrEmpty(prop.Email)) ret += "Falta Definir un email de propietario\n"; + if (prop.Canthabitaciones < 0) ret += "No se puede tener una cantidad de habitaciones negativa\n"; + if (prop.Idtipropiedad <= 0) ret += "No tiene un tipo de propiedad asociada"; + + if (String.IsNullOrEmpty(prop.Ubicacion)) ret += "Tiene que definir la ubicacion de la propiedad\n"; + + return ret; + + } + private string ValidarPropiedad(PatchPropiedadDto prop) { + if (prop == null) return "Esta mal formado el body de la request"; + + string ret = ""; + if (prop.id <1) ret += "No Cargo el dato de id"; + if (String.IsNullOrEmpty(prop.Email)) ret += "Falta Definir un email de propietario\n"; + + if (prop.id <1 ) ret += "No puede haber una id menor a 1"; + + if (prop.Canthabitaciones < 0) ret += "No se puede tener una cantidad de habitaciones negativa\n"; + + if (prop.tipo <= 0) ret += "No tiene un tipo de propiedad asociada"; + if (String.IsNullOrEmpty(prop.Ubicacion)) ret += "Tiene que definir la ubicacion de la propiedad\n"; return ret; diff --git a/Entidades/Dto/PatchPropiedadDto.cs b/Entidades/Dto/PatchPropiedadDto.cs new file mode 100644 index 0000000..3426407 --- /dev/null +++ b/Entidades/Dto/PatchPropiedadDto.cs @@ -0,0 +1,3 @@ +namespace Entidades.Dto; + +public record PatchPropiedadDto(int id, string Ubicacion, int Canthabitaciones, int? Piso, string? Letra, string Email, int tipo); diff --git a/Front/src/Componentes/RowPropiedad.svelte b/Front/src/Componentes/RowPropiedad.svelte index e054ef4..9894728 100644 --- a/Front/src/Componentes/RowPropiedad.svelte +++ b/Front/src/Componentes/RowPropiedad.svelte @@ -1,8 +1,9 @@ +{#if showAlert} +