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"});
|
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")]
|
[HttpDelete("api/propiedad")]
|
||||||
public IActionResult BajaPropiedad(int id, [FromHeader(Name = "Auth")] string Auth, [FromHeader(Name = "Email")] string email){
|
public IActionResult BajaPropiedad(int id, [FromHeader(Name = "Auth")] string Auth, [FromHeader(Name = "Email")] string email){
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
@@ -140,8 +169,29 @@ public class PropiedadesController: ControllerBase {
|
|||||||
|
|
||||||
string ret = "";
|
string ret = "";
|
||||||
if (String.IsNullOrEmpty(prop.Email)) ret += "Falta Definir un email de propietario\n";
|
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.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 (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";
|
if (String.IsNullOrEmpty(prop.Ubicacion)) ret += "Tiene que definir la ubicacion de la propiedad\n";
|
||||||
|
|
||||||
return ret;
|
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">
|
<script lang="ts">
|
||||||
import { fade } from "svelte/transition";
|
import { fade, fly, scale } from "svelte/transition";
|
||||||
import type {PropiedadDto} from "../types"
|
import type {PropiedadDto} from "../types"
|
||||||
import ModalEstatico from "./ModalEstatico.svelte";
|
import ModalEstatico from "./ModalEstatico.svelte";
|
||||||
import ModificarPropiedadForm from "./modificarPropiedadForm.svelte";
|
import ModificarPropiedadForm from "./modificarPropiedadForm.svelte";
|
||||||
|
|
||||||
let { id, ubicacion, tipo, letra, piso,canthabitaciones }: PropiedadDto = $props();
|
let { id, ubicacion, tipo, letra, piso,canthabitaciones }: PropiedadDto = $props();
|
||||||
|
|
||||||
let modal: boolean = $state(false);
|
let modal: boolean = $state(false);
|
||||||
@@ -58,4 +59,9 @@
|
|||||||
<ModalEstatico payload={modalpayload}/>
|
<ModalEstatico payload={modalpayload}/>
|
||||||
{/if}
|
{/if}
|
||||||
{#if modificar}
|
{#if modificar}
|
||||||
|
<tr transition:fade={{duration:100}}>
|
||||||
|
<td colspan="7">
|
||||||
|
<ModificarPropiedadForm {id} {ubicacion} {canthabitaciones} {letra} {piso} {tipo} />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -32,7 +32,17 @@
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.popup.show {
|
||||||
|
animation: rollDown 0.5s ease forwards;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
.dropdown-menu.hide {
|
.dropdown-menu.hide {
|
||||||
animation: rollUp 0.5s ease forwards;
|
animation: rollUp 0.5s ease forwards;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.popup.hide {
|
||||||
|
animation: rollUp 0.5s ease forwards;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,23 +1,76 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
|
||||||
import type { PropiedadDto } from "../types";
|
import type { PropiedadDto } from "../types";
|
||||||
|
import {urlG} from "../stores/urlStore";
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
let propi: PropiedadDto = $props();
|
let {canthabitaciones, id, letra, piso, tipo, ubicacion}: PropiedadDto = $props();
|
||||||
|
|
||||||
function submitForm(e: Event) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
|
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>
|
</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">
|
<form onsubmit={submitForm} class="card card-body">
|
||||||
<div class="form-floating mb-3">
|
<div class="form-floating mb-3">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
id="ubicacion"
|
id="ubicacion"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
bind:value={propi.ubicacion}
|
bind:value={ubicacion}
|
||||||
placeholder="Ubicación"
|
placeholder="Ubicación"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
@@ -28,7 +81,7 @@
|
|||||||
type="number"
|
type="number"
|
||||||
id="canthabitaciones"
|
id="canthabitaciones"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
bind:value={propi.canthabitaciones}
|
bind:value={canthabitaciones}
|
||||||
min="1"
|
min="1"
|
||||||
placeholder="Cantidad de Habitaciones"
|
placeholder="Cantidad de Habitaciones"
|
||||||
required
|
required
|
||||||
@@ -40,7 +93,7 @@
|
|||||||
type="number"
|
type="number"
|
||||||
id="piso"
|
id="piso"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
bind:value={propi.piso}
|
bind:value={piso}
|
||||||
min="0"
|
min="0"
|
||||||
placeholder="Piso"
|
placeholder="Piso"
|
||||||
/>
|
/>
|
||||||
@@ -51,7 +104,7 @@
|
|||||||
type="text"
|
type="text"
|
||||||
id="letra"
|
id="letra"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
bind:value={propi.letra}
|
bind:value={letra}
|
||||||
maxlength="1"
|
maxlength="1"
|
||||||
placeholder="Letra"
|
placeholder="Letra"
|
||||||
/>
|
/>
|
||||||
@@ -59,9 +112,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-floating mb-3">
|
<div class="form-floating mb-3">
|
||||||
<select
|
<select
|
||||||
id="idtipropiedad"
|
id="idtipo"
|
||||||
class="form-select"
|
class="form-select"
|
||||||
bind:value={propi.tipo}
|
bind:value={tipo}
|
||||||
required
|
required
|
||||||
>
|
>
|
||||||
<option value="1">Casa</option>
|
<option value="1">Casa</option>
|
||||||
@@ -71,7 +124,7 @@
|
|||||||
<option value="5">LocalComercial</option>
|
<option value="5">LocalComercial</option>
|
||||||
<option value="6">Oficina</option>
|
<option value="6">Oficina</option>
|
||||||
</select>
|
</select>
|
||||||
<label for="idtipropiedad">Tipo de Propiedad</label>
|
<label for="idtipopropiedad">Tipo de propiedad</label>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary">Enviar</button>
|
<button type="submit" class="btn btn-primary">Enviar</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,39 +1,39 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte" ;
|
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte" ;
|
||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
import RowPropiedad from "../Componentes/RowPropiedad.svelte";
|
import RowPropiedad from "../Componentes/RowPropiedad.svelte";
|
||||||
import type { PropiedadDto } from "../types";
|
import type { PropiedadDto } from "../types";
|
||||||
|
|
||||||
let propiedades = writable<PropiedadDto[]>([]);
|
let propiedades = writable<PropiedadDto[]>([]);
|
||||||
let email = localStorage.getItem("email");
|
let email = localStorage.getItem("email");
|
||||||
let token = sessionStorage.getItem("token");
|
let token = sessionStorage.getItem("token");
|
||||||
|
|
||||||
let fallo: boolean = $state(false);
|
let fallo: boolean = $state(false);
|
||||||
|
|
||||||
onMount(async ()=> {
|
onMount(async ()=> {
|
||||||
try {
|
try {
|
||||||
const responce = await fetch("http://localhost:5007/api/propiedades/Propietario", {
|
const responce = await fetch("http://localhost:5007/api/propiedades/Propietario", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
'Auth': String(token),
|
'Auth': String(token),
|
||||||
'Email' : String(email),
|
'Email' : String(email),
|
||||||
'Content-Type' : "application/json"
|
'Content-Type' : "application/json"
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (responce.ok){
|
if (responce.ok){
|
||||||
const json = await responce.json();
|
const json = await responce.json();
|
||||||
propiedades.set(json);
|
propiedades.set(json);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!responce.ok){
|
if (!responce.ok){
|
||||||
fallo = true;
|
fallo = true;
|
||||||
}
|
}
|
||||||
} catch (e){
|
} catch (e){
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ onMount(async ()=> {
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each $propiedades as propiedad}
|
{#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}
|
{/each}
|
||||||
</tbody>
|
</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 Entidades;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace Modelo;
|
namespace Modelo;
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,21 @@ public bool AñadirPropiedad(Propiedade? prop) {
|
|||||||
return (int)filasInsertadasParam.Value == 1? true: false;
|
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) {
|
public IQueryable<PropiedadesDto> ObtenerPropiedadesPorEmail(string email) {
|
||||||
FormattableString sqlq = $"""
|
FormattableString sqlq = $"""
|
||||||
SELECT p.id, p.ubicacion as Ubicacion, p.canthabitaciones, p.piso, p.letra, tp.descripcion as Tipo From Propiedades p
|
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;
|
var con = Context;
|
||||||
Propiedade? prop = con.Propiedades.FirstOrDefault(x=>x.Id == id);
|
Propiedade? prop = con.Propiedades.FirstOrDefault(x=>x.Id == id);
|
||||||
if (prop == null) return false;
|
if (prop == null) return false;
|
||||||
Console.WriteLine("prop.dni: "+prop.Dnipropietario+", cli.dni: "+cli.Dni);
|
|
||||||
if (prop.Dnipropietario != cli.Dni) return false;
|
if (prop.Dnipropietario != cli.Dni) return false;
|
||||||
prop.Idestado = 3;
|
prop.Idestado = 3;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user