avance: estado pre implementacion de notificaciones
This commit is contained in:
9
Aspnet/Builder/Builder.cs
Normal file
9
Aspnet/Builder/Builder.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using Minio.Helper;
|
||||
|
||||
public abstract class Builder<T> where T:new() {
|
||||
protected T data = new T();
|
||||
public T Build() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
40
Aspnet/Builder/NotificacionBuilder.cs
Normal file
40
Aspnet/Builder/NotificacionBuilder.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Entidades;
|
||||
|
||||
public class NotificacioneBuilder : Builder<Notificacione>
|
||||
{
|
||||
public NotificacioneBuilder SetDnicliente(long dnicliente) {
|
||||
data.Dnicliente = dnicliente;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificacioneBuilder SetDniremitente(long dniremitente) {
|
||||
data.Dniremitente = dniremitente;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificacioneBuilder SetFecha(DateTime fecha) {
|
||||
data.Fecha = fecha;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificacioneBuilder SetMensaje(string mensaje) {
|
||||
data.Mensaje = mensaje;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificacioneBuilder SetAccion(string accion) {
|
||||
data.Accion = accion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificacioneBuilder SetIdpropiedad(int idpropiedad) {
|
||||
data.Idpropiedad = idpropiedad;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificacioneBuilder SetLeido(bool leido) {
|
||||
data.Leido = leido;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
30
Aspnet/Builder/NotificacionDtoBuilder.cs
Normal file
30
Aspnet/Builder/NotificacionDtoBuilder.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace AlquilaFacil.Builder;
|
||||
using Entidades.Dto;
|
||||
public class NotificacionDtoBuilder: Builder<NotificacionDto> {
|
||||
|
||||
public NotificacionDtoBuilder SetRemitente(string remitente) {
|
||||
data.Remitente = remitente;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificacionDtoBuilder SetAccion(string accion) {
|
||||
data.Accion = accion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificacionDtoBuilder SetMensaje(string mensaje) {
|
||||
data.Mensaje = mensaje;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificacionDtoBuilder SetFecha(DateTime? fecha) {
|
||||
data.Fecha = fecha;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NotificacionDtoBuilder SetPropiedad(string propiedad) {
|
||||
data.Propiedad = propiedad;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,4 +11,5 @@ public class ContratoController: ControllerBase {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
83
Aspnet/Controllers/NotificacionesController.cs
Normal file
83
Aspnet/Controllers/NotificacionesController.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using AlquilaFacil.Builder;
|
||||
using Entidades;
|
||||
using Entidades.Dto;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Modelo;
|
||||
|
||||
namespace AlquilaFacil.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class NotificacionesController: ControllerBase {
|
||||
[HttpGet("api/notificaciones")]
|
||||
public IActionResult GetNotificaciones([FromHeader(Name ="Auth")]string Auth, bool leido = false) {
|
||||
if (string.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
|
||||
var cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return BadRequest(new {message = "Fallo al intentar encontrar tu usuario (puede que te hayas logeado desde otro dispositivo?)"});
|
||||
|
||||
LinkedList<NotificacionDto> noti = new();
|
||||
var notificaciones = cli.NotificacioneDniclienteNavigations.Where(x=>x.Leido == leido).ToList();
|
||||
|
||||
Parallel.ForEach(notificaciones, i => {
|
||||
var dto = new NotificacionDtoBuilder()
|
||||
.SetRemitente(i.DniremitenteNavigation.Nombre)
|
||||
.SetAccion(i.Accion)
|
||||
.SetMensaje(i.Mensaje)
|
||||
.SetFecha(i.Fecha)
|
||||
.SetPropiedad(i.IdpropiedadNavigation.Ubicacion)
|
||||
.Build();
|
||||
|
||||
noti.AddFirst(dto);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
[HttpPut("api/notificaciones")]
|
||||
public IActionResult MarcarComoLeido([FromHeader(Name = "Auth")]string Auth, NotificacionMarcarLeidoDto nota) {
|
||||
if (String.IsNullOrWhiteSpace(Auth)) return Unauthorized();
|
||||
|
||||
if (nota.Fecha == null || String.IsNullOrWhiteSpace(nota.Email)) return BadRequest(new {message = "Faltan datos"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
|
||||
if (cli == null) return BadRequest(new {message = "El token de autorizacion no pertenese a ningun Usuario"});
|
||||
|
||||
if (cli.Email != nota.Email) return BadRequest(new {message = "El token de autorizacion no corresponde a tu usuario"});
|
||||
|
||||
bool ret = RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, nota.Fecha);
|
||||
return ret ?
|
||||
Ok(new{message = "Se Marco como leido"}):BadRequest(new{message = "Fallo al marcarse como leido"});
|
||||
}
|
||||
|
||||
[HttpPost("api/notificaciones/consultaAlquiler")]
|
||||
public IActionResult ConsultaAlquiler([FromHeader(Name ="Auth")]string Auth, [FromBody] AltaNotificacionDto data) {
|
||||
if (String.IsNullOrWhiteSpace(Auth)) return Unauthorized();
|
||||
bool validacion1 = RepositorioUsuarios.Singleton.CheckToken(Auth, data.Remitente);
|
||||
if (validacion1 == false) return BadRequest(new {message = "el token no corresponde a su usuario"});
|
||||
|
||||
if (data.Accion == "") return BadRequest(new{message = "El campo Accion esta vacio"});
|
||||
if (data.Mensaje == "") return BadRequest(new {message = "El campo Mensaje esta vacio"});
|
||||
|
||||
Cliente? inq = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (inq == null) return BadRequest(new { message = "no hay un usuario para el cual el token de autorizacion corresponda (vuelvase a logear)" });
|
||||
|
||||
Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(data.Propiedad);
|
||||
if (prop == null || prop.Idestado != 1) return BadRequest(new{message="No hay una propiedad dada de alta para ese id"});
|
||||
if (prop.DnipropietarioNavigation == null) return BadRequest(new{message="la propiedad no tiene propietario dado de alto ????"});
|
||||
|
||||
var noti = new NotificacioneBuilder()
|
||||
.SetAccion(data.Accion)
|
||||
.SetMensaje(data.Mensaje)
|
||||
.SetLeido(false)
|
||||
.SetDnicliente(prop.DnipropietarioNavigation.Dni)
|
||||
.SetDniremitente(inq.Dni)
|
||||
.SetIdpropiedad(prop.Id)
|
||||
.SetFecha(DateTime.Now)
|
||||
.Build();
|
||||
|
||||
var ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti);
|
||||
|
||||
return ret?
|
||||
Ok(new {message = "Se envio la notificacion"}):BadRequest(new {message = "Fallo al intentar guardar la notificacion"});
|
||||
}
|
||||
}
|
||||
7
Entidades/Dto/AltaNotificacionDto.cs
Normal file
7
Entidades/Dto/AltaNotificacionDto.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Entidades.Dto;
|
||||
public class AltaNotificacionDto {
|
||||
public string Remitente { get; set; } ="";
|
||||
public string Accion { get; set; } ="";
|
||||
public string Mensaje { get; set; } ="";
|
||||
public int Propiedad { get; set;}
|
||||
}
|
||||
8
Entidades/Dto/NotificacionDto.cs
Normal file
8
Entidades/Dto/NotificacionDto.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Entidades.Dto;
|
||||
public class NotificacionDto {
|
||||
public string Remitente { get; set; } ="";
|
||||
public string Accion { get; set; } ="";
|
||||
public string Mensaje { get; set; } ="";
|
||||
public DateTime? Fecha{get; set;} =null;
|
||||
public string Propiedad { get; set;} ="";
|
||||
}
|
||||
1
Entidades/Dto/NotificacionMarcarLeidoDto.cs
Normal file
1
Entidades/Dto/NotificacionMarcarLeidoDto.cs
Normal file
@@ -0,0 +1 @@
|
||||
public record NotificacionMarcarLeidoDto(DateTime? Fecha, string Email);
|
||||
@@ -14,9 +14,9 @@
|
||||
import FrontPropietario from "./paginas/grupos/PropietarioG.svelte";
|
||||
import PublicarPropiedad from "./paginas/PublicarPropiedad.svelte";
|
||||
import BusquedaPropiedades from "./paginas/BusquedaPropiedades.svelte";
|
||||
import ControlUsuarios from "./paginas/AdminUsuarios.svelte";
|
||||
import ControlPropiedades from "./paginas/AdminPropiedades.svelte";
|
||||
import Notificaciones from "./paginas/Notificaciones.svelte";
|
||||
import AdminUsuarios from "./paginas/AdminUsuarios.svelte";
|
||||
import AdminPropiedades from "./paginas/AdminPropiedades.svelte";
|
||||
import Notificaciones from "./paginas/Notificaciones.svelte";
|
||||
</script>
|
||||
|
||||
<Router>
|
||||
@@ -67,12 +67,12 @@
|
||||
|
||||
<!-- Pantalla Control Usuarios -->
|
||||
<Route path="/accion/9">
|
||||
<ProteRoute componente={ControlUsuarios}/>
|
||||
<ProteRoute componente={AdminUsuarios}/>
|
||||
</Route>
|
||||
|
||||
<!-- Pantalla Control Propiedades -->
|
||||
<Route path="/accion/10">
|
||||
<ProteRoute componente={ControlPropiedades}/>
|
||||
<ProteRoute componente={AdminPropiedades}/>
|
||||
</Route>
|
||||
|
||||
|
||||
|
||||
36
Front/src/Componentes/ModalConfirm.svelte
Normal file
36
Front/src/Componentes/ModalConfirm.svelte
Normal file
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
let {show = false, title = "Confirmación",
|
||||
message = "¿Está seguro?",
|
||||
onConfirm , onCancel
|
||||
}:{
|
||||
show:boolean, title: string, message: string, onConfirm:()=>void, onCancel:()=>void } = $props();
|
||||
|
||||
function handleConfirm() {
|
||||
onConfirm();
|
||||
}
|
||||
|
||||
function handleCancel() {
|
||||
onCancel();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
{#if show}
|
||||
<div class="modal fade show d-block" tabindex="-1" style="background-color: rgba(0,0,0,0.5);">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">{title}</h5>
|
||||
<button type="button" class="btn-close" aria-label="Close" onclick={handleCancel}></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>{message}</p>
|
||||
<div class="d-flex justify-content-between">
|
||||
<button class="btn btn-secondary" onclick={handleCancel}>Cancelar</button>
|
||||
<button class="btn btn-primary" onclick={handleConfirm}>Aceptar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,8 +1,46 @@
|
||||
<script lang="ts">
|
||||
import type { PropiedadDto } from "../types";
|
||||
import ModalConfirm from "./ModalConfirm.svelte";
|
||||
import {urlG} from "../stores/urlStore";
|
||||
|
||||
let { prop }: { prop: PropiedadDto } = $props();
|
||||
|
||||
let show: boolean = $state(false);
|
||||
let token = sessionStorage.getItem("token");
|
||||
let remitente = localStorage.getItem("email");
|
||||
|
||||
const message: string = "Queres consultar con el propietario por el alquiler? (esto le envia una notificacion y email al propietario)";
|
||||
const accion = "Consulta Nuevo Alquiler";
|
||||
|
||||
function Consultar() {
|
||||
show = true;
|
||||
}
|
||||
|
||||
async function onConfirm() {
|
||||
const propiedad = prop.id;
|
||||
try {
|
||||
const responce = await fetch($urlG+"/api/notificaciones", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Auth": String(token)
|
||||
},
|
||||
body : JSON.stringify({remitente, accion, propiedad})
|
||||
});
|
||||
|
||||
} catch {
|
||||
|
||||
}
|
||||
|
||||
show=!show;
|
||||
}
|
||||
|
||||
function onCancel() {
|
||||
show=!show;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<ModalConfirm {show} {message} title="Consulta" {onConfirm} {onCancel}/>
|
||||
<div class="card text-center border shadow-sm">
|
||||
<div class="card-header bg-primary text-white">
|
||||
<h5 class="mb-0">{prop.tipo}</h5>
|
||||
@@ -19,7 +57,7 @@
|
||||
<strong>Servicios:</strong> {prop.servicios || "Sin servicios especificados"}<br>
|
||||
<strong>Monto:</strong> ${prop.monto}<br>
|
||||
</p>
|
||||
<button class="btn btn-primary">Consultar</button>
|
||||
<button class="btn btn-primary" onclick={Consultar}>Alquilar</button>
|
||||
</div>
|
||||
<div class="card-footer text-muted">
|
||||
ID Propiedad: {prop.id}
|
||||
|
||||
@@ -71,11 +71,10 @@
|
||||
p.pag = a;
|
||||
cargaPropiedades();
|
||||
}
|
||||
function querybusc(a) {
|
||||
function querybusc(a:AdminParametrosBusqueda) {
|
||||
p = a;
|
||||
cargaPropiedades();
|
||||
}
|
||||
$inspect(p);
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
|
||||
26
Modelo/RepositorioNotificaciones.cs
Normal file
26
Modelo/RepositorioNotificaciones.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Entidades.Dto;
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Modelo;
|
||||
|
||||
public class RepositorioNotificaciones : RepositorioBase<RepositorioNotificaciones> {
|
||||
public bool MarcarComoLeido(long dni, DateTime? fecha) {
|
||||
if (fecha == null) return false;
|
||||
|
||||
var con = Context;
|
||||
Notificacione? noti = con.Notificaciones.FirstOrDefault(x=> x.Dnicliente == dni && x.Fecha == fecha);
|
||||
if (noti == null) return false;
|
||||
|
||||
noti.Leido = true;
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool AltaNotificacion(Notificacione n) {
|
||||
var con = Context;
|
||||
con.Notificaciones.Add(n);
|
||||
return Guardar(con);
|
||||
}
|
||||
}
|
||||
@@ -177,4 +177,12 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
Cliente? cli = con.Clientes.FirstOrDefault(x=>x.Dni == dni);
|
||||
return cli;
|
||||
}
|
||||
|
||||
public Cliente? ObtenerClientePorToken(string token) {
|
||||
var con = Context;
|
||||
Cliente? cli = con.Clientes.Include(x=>x.NotificacioneDniclienteNavigations).FirstOrDefault(x=>x.Token == token);
|
||||
|
||||
if (cli == null|| cli.Dni == 0) return null;
|
||||
return cli;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user