feat: modificar propiedad
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
3
Entidades/Dto/PatchPropiedadDto.cs
Normal file
3
Entidades/Dto/PatchPropiedadDto.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace Entidades.Dto;
|
||||
|
||||
public record PatchPropiedadDto(int id, string Ubicacion, int Canthabitaciones, int? Piso, string? Letra, string Email, int tipo);
|
||||
@@ -1,8 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { fade } from "svelte/transition";
|
||||
import { fade, fly, scale } from "svelte/transition";
|
||||
import type {PropiedadDto} from "../types"
|
||||
import ModalEstatico from "./ModalEstatico.svelte";
|
||||
import ModificarPropiedadForm from "./modificarPropiedadForm.svelte";
|
||||
import ModalEstatico from "./ModalEstatico.svelte";
|
||||
import ModificarPropiedadForm from "./modificarPropiedadForm.svelte";
|
||||
|
||||
let { id, ubicacion, tipo, letra, piso,canthabitaciones }: PropiedadDto = $props();
|
||||
|
||||
let modal: boolean = $state(false);
|
||||
@@ -58,4 +59,9 @@
|
||||
<ModalEstatico payload={modalpayload}/>
|
||||
{/if}
|
||||
{#if modificar}
|
||||
<tr transition:fade={{duration:100}}>
|
||||
<td colspan="7">
|
||||
<ModificarPropiedadForm {id} {ubicacion} {canthabitaciones} {letra} {piso} {tipo} />
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
|
||||
@@ -32,7 +32,17 @@
|
||||
display: block;
|
||||
}
|
||||
|
||||
.popup.show {
|
||||
animation: rollDown 0.5s ease forwards;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.dropdown-menu.hide {
|
||||
animation: rollUp 0.5s ease forwards;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.popup.hide {
|
||||
animation: rollUp 0.5s ease forwards;
|
||||
display: block;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,76 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import type { PropiedadDto } from "../types";
|
||||
import {urlG} from "../stores/urlStore";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
let propi: PropiedadDto = $props();
|
||||
|
||||
function submitForm(e: Event) {
|
||||
e.preventDefault();
|
||||
let {canthabitaciones, id, letra, piso, tipo, ubicacion}: PropiedadDto = $props();
|
||||
|
||||
onMount(()=> {
|
||||
switch(tipo) {
|
||||
case"Casa":
|
||||
tipo = "1"
|
||||
break;
|
||||
case"Piso":
|
||||
tipo = "2"
|
||||
break;
|
||||
case"Departamento":
|
||||
tipo = "3"
|
||||
break;
|
||||
case"Galpon":
|
||||
tipo = "4"
|
||||
break;
|
||||
case"LocalComercial":
|
||||
tipo = "5"
|
||||
break;
|
||||
case"Oficina":
|
||||
tipo = "6"
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
let showAlert: boolean = $state(false);
|
||||
let errorMessage: string = $state("");
|
||||
const token = sessionStorage.getItem("token");
|
||||
const email = localStorage.getItem("email");
|
||||
|
||||
async function submitForm(e: Event) {
|
||||
e.preventDefault();
|
||||
try {
|
||||
let response = await fetch(String($urlG + "/api/propiedad"), {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Auth' : String(token),
|
||||
'Content-Type' : 'application/json',
|
||||
},
|
||||
body: JSON.stringify({id, canthabitaciones, letra, piso, tipo, ubicacion, email}),
|
||||
});
|
||||
if (response.ok){
|
||||
location.reload();
|
||||
}
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
errorMessage = errorData.message;
|
||||
showAlert = true;
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error("Fallo al enviar el formulario para crear un inquilino");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if showAlert}
|
||||
<div class='alert alert-warning alert-dismissible fade show' role='alert'>
|
||||
<strong>{errorMessage}</strong>
|
||||
<button type="button" class="btn-close close" aria-label="Close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
{/if}
|
||||
<form onsubmit={submitForm} class="card card-body">
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="text"
|
||||
id="ubicacion"
|
||||
class="form-control"
|
||||
bind:value={propi.ubicacion}
|
||||
bind:value={ubicacion}
|
||||
placeholder="Ubicación"
|
||||
required
|
||||
/>
|
||||
@@ -28,7 +81,7 @@
|
||||
type="number"
|
||||
id="canthabitaciones"
|
||||
class="form-control"
|
||||
bind:value={propi.canthabitaciones}
|
||||
bind:value={canthabitaciones}
|
||||
min="1"
|
||||
placeholder="Cantidad de Habitaciones"
|
||||
required
|
||||
@@ -40,7 +93,7 @@
|
||||
type="number"
|
||||
id="piso"
|
||||
class="form-control"
|
||||
bind:value={propi.piso}
|
||||
bind:value={piso}
|
||||
min="0"
|
||||
placeholder="Piso"
|
||||
/>
|
||||
@@ -51,7 +104,7 @@
|
||||
type="text"
|
||||
id="letra"
|
||||
class="form-control"
|
||||
bind:value={propi.letra}
|
||||
bind:value={letra}
|
||||
maxlength="1"
|
||||
placeholder="Letra"
|
||||
/>
|
||||
@@ -59,9 +112,9 @@
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<select
|
||||
id="idtipropiedad"
|
||||
id="idtipo"
|
||||
class="form-select"
|
||||
bind:value={propi.tipo}
|
||||
bind:value={tipo}
|
||||
required
|
||||
>
|
||||
<option value="1">Casa</option>
|
||||
@@ -71,7 +124,7 @@
|
||||
<option value="5">LocalComercial</option>
|
||||
<option value="6">Oficina</option>
|
||||
</select>
|
||||
<label for="idtipropiedad">Tipo de Propiedad</label>
|
||||
<label for="idtipopropiedad">Tipo de propiedad</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Enviar</button>
|
||||
</form>
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte" ;
|
||||
import { onMount } from "svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte" ;
|
||||
import { writable } from 'svelte/store';
|
||||
import RowPropiedad from "../Componentes/RowPropiedad.svelte";
|
||||
import type { PropiedadDto } from "../types";
|
||||
import RowPropiedad from "../Componentes/RowPropiedad.svelte";
|
||||
import type { PropiedadDto } from "../types";
|
||||
|
||||
let propiedades = writable<PropiedadDto[]>([]);
|
||||
let email = localStorage.getItem("email");
|
||||
let token = sessionStorage.getItem("token");
|
||||
let propiedades = writable<PropiedadDto[]>([]);
|
||||
let email = localStorage.getItem("email");
|
||||
let token = sessionStorage.getItem("token");
|
||||
|
||||
let fallo: boolean = $state(false);
|
||||
let fallo: boolean = $state(false);
|
||||
|
||||
onMount(async ()=> {
|
||||
try {
|
||||
const responce = await fetch("http://localhost:5007/api/propiedades/Propietario", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
'Auth': String(token),
|
||||
'Email' : String(email),
|
||||
'Content-Type' : "application/json"
|
||||
},
|
||||
});
|
||||
if (responce.ok){
|
||||
const json = await responce.json();
|
||||
propiedades.set(json);
|
||||
return;
|
||||
}
|
||||
onMount(async ()=> {
|
||||
try {
|
||||
const responce = await fetch("http://localhost:5007/api/propiedades/Propietario", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
'Auth': String(token),
|
||||
'Email' : String(email),
|
||||
'Content-Type' : "application/json"
|
||||
},
|
||||
});
|
||||
if (responce.ok){
|
||||
const json = await responce.json();
|
||||
propiedades.set(json);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!responce.ok){
|
||||
fallo = true;
|
||||
}
|
||||
} catch (e){
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
if (!responce.ok){
|
||||
fallo = true;
|
||||
}
|
||||
} catch (e){
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
@@ -52,7 +52,7 @@ onMount(async ()=> {
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each $propiedades as propiedad}
|
||||
<RowPropiedad id={propiedad.id} ubicacion={propiedad.ubicacion} letra={propiedad.letra} piso={propiedad.piso} tipo={propiedad.tipo} canthabitaciones={propiedad.canthabitaciones}/>
|
||||
<RowPropiedad id={propiedad.id} ubicacion={propiedad.ubicacion} letra={propiedad.letra} piso={propiedad.piso} tipo={propiedad.tipo} canthabitaciones={propiedad.canthabitaciones} />
|
||||
|
||||
{/each}
|
||||
</tbody>
|
||||
|
||||
3
Front/src/stores/urlStore.js
Normal file
3
Front/src/stores/urlStore.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import { readable } from 'svelte/store';
|
||||
|
||||
export const urlG = readable('http://localhost:5007');
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Entidades;
|
||||
|
||||
namespace Modelo;
|
||||
|
||||
|
||||
@@ -66,6 +66,21 @@ public bool AñadirPropiedad(Propiedade? prop) {
|
||||
return (int)filasInsertadasParam.Value == 1? true: false;
|
||||
}
|
||||
|
||||
public bool PatchPropiedad(Propiedade prop) {
|
||||
var con = Context;
|
||||
Propiedade? propi = con.Propiedades.FirstOrDefault(x=>x.Id == prop.Id);
|
||||
|
||||
if (propi == null) return false;
|
||||
|
||||
propi.Canthabitaciones = prop.Canthabitaciones;
|
||||
propi.Idtipropiedad = prop.Idtipropiedad;
|
||||
propi.Ubicacion = prop.Ubicacion;
|
||||
propi.Piso = prop.Piso;
|
||||
propi.Letra = prop.Letra;
|
||||
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public IQueryable<PropiedadesDto> ObtenerPropiedadesPorEmail(string email) {
|
||||
FormattableString sqlq = $"""
|
||||
SELECT p.id, p.ubicacion as Ubicacion, p.canthabitaciones, p.piso, p.letra, tp.descripcion as Tipo From Propiedades p
|
||||
@@ -98,7 +113,6 @@ public bool AñadirPropiedad(Propiedade? prop) {
|
||||
var con = Context;
|
||||
Propiedade? prop = con.Propiedades.FirstOrDefault(x=>x.Id == id);
|
||||
if (prop == null) return false;
|
||||
Console.WriteLine("prop.dni: "+prop.Dnipropietario+", cli.dni: "+cli.Dni);
|
||||
if (prop.Dnipropietario != cli.Dni) return false;
|
||||
prop.Idestado = 3;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user