diff --git a/Aspnet/Builder/Builder.cs b/Aspnet/Builder/Builder.cs new file mode 100644 index 0000000..2a9b274 --- /dev/null +++ b/Aspnet/Builder/Builder.cs @@ -0,0 +1,9 @@ +using System.Runtime.CompilerServices; +using Minio.Helper; + +public abstract class Builder where T:new() { + protected T data = new T(); + public T Build() { + return data; + } +} \ No newline at end of file diff --git a/Aspnet/Builder/NotificacionBuilder.cs b/Aspnet/Builder/NotificacionBuilder.cs new file mode 100644 index 0000000..baf3e6b --- /dev/null +++ b/Aspnet/Builder/NotificacionBuilder.cs @@ -0,0 +1,40 @@ +using System; +using Entidades; + +public class NotificacioneBuilder : Builder +{ + 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; + } +} diff --git a/Aspnet/Builder/NotificacionDtoBuilder.cs b/Aspnet/Builder/NotificacionDtoBuilder.cs new file mode 100644 index 0000000..8141110 --- /dev/null +++ b/Aspnet/Builder/NotificacionDtoBuilder.cs @@ -0,0 +1,30 @@ +namespace AlquilaFacil.Builder; +using Entidades.Dto; +public class NotificacionDtoBuilder: Builder { + + 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; + } + +} \ No newline at end of file diff --git a/Aspnet/Controllers/ContratoController.cs b/Aspnet/Controllers/ContratoController.cs index 2ee6664..23e2cfa 100644 --- a/Aspnet/Controllers/ContratoController.cs +++ b/Aspnet/Controllers/ContratoController.cs @@ -11,4 +11,5 @@ public class ContratoController: ControllerBase { } + } \ No newline at end of file diff --git a/Aspnet/Controllers/NotificacionesController.cs b/Aspnet/Controllers/NotificacionesController.cs new file mode 100644 index 0000000..33ed386 --- /dev/null +++ b/Aspnet/Controllers/NotificacionesController.cs @@ -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 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"}); + } +} \ No newline at end of file diff --git a/Entidades/Dto/AltaNotificacionDto.cs b/Entidades/Dto/AltaNotificacionDto.cs new file mode 100644 index 0000000..14b9a96 --- /dev/null +++ b/Entidades/Dto/AltaNotificacionDto.cs @@ -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;} +} \ No newline at end of file diff --git a/Entidades/Dto/NotificacionDto.cs b/Entidades/Dto/NotificacionDto.cs new file mode 100644 index 0000000..9a7e488 --- /dev/null +++ b/Entidades/Dto/NotificacionDto.cs @@ -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;} =""; +} \ No newline at end of file diff --git a/Entidades/Dto/NotificacionMarcarLeidoDto.cs b/Entidades/Dto/NotificacionMarcarLeidoDto.cs new file mode 100644 index 0000000..60965bb --- /dev/null +++ b/Entidades/Dto/NotificacionMarcarLeidoDto.cs @@ -0,0 +1 @@ +public record NotificacionMarcarLeidoDto(DateTime? Fecha, string Email); \ No newline at end of file diff --git a/Front/src/App.svelte b/Front/src/App.svelte index d3b8711..44c19fa 100644 --- a/Front/src/App.svelte +++ b/Front/src/App.svelte @@ -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"; @@ -67,12 +67,12 @@ - + - + diff --git a/Front/src/Componentes/ModalConfirm.svelte b/Front/src/Componentes/ModalConfirm.svelte new file mode 100644 index 0000000..dea14b3 --- /dev/null +++ b/Front/src/Componentes/ModalConfirm.svelte @@ -0,0 +1,36 @@ + + + {#if show} + + {/if} + \ No newline at end of file diff --git a/Front/src/Componentes/PublicacionPropiedad.svelte b/Front/src/Componentes/PublicacionPropiedad.svelte index 6dc0964..c921590 100644 --- a/Front/src/Componentes/PublicacionPropiedad.svelte +++ b/Front/src/Componentes/PublicacionPropiedad.svelte @@ -1,8 +1,46 @@ +
{prop.tipo}
@@ -19,7 +57,7 @@ Servicios: {prop.servicios || "Sin servicios especificados"}
Monto: ${prop.monto}

- +