diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4361744 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# CS8602: Dereference of a possibly null reference. +dotnet_diagnostic.CS8602.severity = suggestion diff --git a/.gitignore b/.gitignore index baab4fc..cfe669c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ /Entidades/obj/ /Aspnet/obj/ /Modelo/bin/ +Aspnet/bin/ +node_modules/ \ No newline at end of file diff --git a/Aspnet/AlquilaFacil.csproj b/Aspnet/AlquilaFacil.csproj index 842f7c7..91ae823 100644 --- a/Aspnet/AlquilaFacil.csproj +++ b/Aspnet/AlquilaFacil.csproj @@ -9,6 +9,8 @@ + + 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/DtoBuilder/CanonDtoBuilder.cs b/Aspnet/Builder/DtoBuilder/CanonDtoBuilder.cs new file mode 100644 index 0000000..1c0538a --- /dev/null +++ b/Aspnet/Builder/DtoBuilder/CanonDtoBuilder.cs @@ -0,0 +1,35 @@ +using Entidades.Dto; + +namespace AlquilaFacil.Builder; + +public class CanonDtoBuilder : Builder{ + public CanonDtoBuilder SetId(long id) { + data.Id = id; + return this; + } + + public CanonDtoBuilder SetMesNum(int mesNum) { + data.MesNum = mesNum; + return this; + } + + public CanonDtoBuilder SetMes(DateTime d){ + data.Mes = d; + return this; + } + + public CanonDtoBuilder SetMonto(Decimal monto) { + data.Monto = monto; + return this; + } + + public CanonDtoBuilder SetDivisa(string divisa) { + data.Divisa = divisa; + return this; + } + + public CanonDtoBuilder SetPago(bool p) { + data.Pago = p; + return this; + } +} \ No newline at end of file diff --git a/Aspnet/Builder/DtoBuilder/ContratoDtoBuilder.cs b/Aspnet/Builder/DtoBuilder/ContratoDtoBuilder.cs new file mode 100644 index 0000000..5a3d4a0 --- /dev/null +++ b/Aspnet/Builder/DtoBuilder/ContratoDtoBuilder.cs @@ -0,0 +1,50 @@ +using Entidades.Dto; + +namespace AlquilaFacil.Builder; +public class ContratoDtoBuilder: Builder { + public ContratoDtoBuilder SetId(long id ){ + data.id = id; + return this; + } + + public ContratoDtoBuilder SetUbicacion(string ub){ + data.Ubicacion = ub; + return this; + } + + public ContratoDtoBuilder SetTipo(string tipo){ + data.TipoPropiedad = tipo; + return this; + } + + public ContratoDtoBuilder SetFechaInicio(DateTime fec) { + data.Fechainicio = fec; + return this; + } + + public ContratoDtoBuilder SetInquilino(string inquilino){ + data.Inquilino = inquilino; + return this; + } + + public ContratoDtoBuilder SetPropietario(string propietario){ + data.Propietario = propietario; + return this; + } + + public ContratoDtoBuilder SetEstado(ulong habilitado, ulong cancelado) { + bool Habilitado = habilitado == 0?false:true; + bool Cancelado = cancelado == 0?false:true; + + if (Habilitado == true && Cancelado == false){ + data.Estado = "Alquiler Iniciado"; + } else if (Cancelado == true && Habilitado == false) { + data.Estado = "Nunca Empezo Esta Cancelado"; + } else if (Habilitado == false && Cancelado ==false){ + data.Estado = "Esta en Proceso"; + } else if (Habilitado == true && Cancelado == true){ + data.Estado = "Terminado"; + } + return this; + } +} \ No newline at end of file diff --git a/Aspnet/Builder/DtoBuilder/ContratoPropiedadDtoBuilder.cs b/Aspnet/Builder/DtoBuilder/ContratoPropiedadDtoBuilder.cs new file mode 100644 index 0000000..ab8a5e5 --- /dev/null +++ b/Aspnet/Builder/DtoBuilder/ContratoPropiedadDtoBuilder.cs @@ -0,0 +1,75 @@ +using Entidades.Dto; + +namespace AlquilaFacil.Builder; +public class ContratoPropiedadDtoBuilder : Builder{ + public ContratoPropiedadDtoBuilder SetId(long id ){ + data.id = id; + return this; + } + + public ContratoPropiedadDtoBuilder SetUbicacion(string ub){ + data.Ubicacion = ub; + return this; + } + + public ContratoPropiedadDtoBuilder SetTipo(string tipo){ + data.TipoPropiedad = tipo; + return this; + } + + public ContratoPropiedadDtoBuilder SetFechaInicio(DateTime fec) { + data.Fechainicio = fec; + return this; + } + + public ContratoPropiedadDtoBuilder SetInquilino(string inquilino){ + data.Inquilino = inquilino; + return this; + } + + public ContratoPropiedadDtoBuilder SetPropietario(string propietario){ + data.Propietario = propietario; + return this; + } + + public ContratoPropiedadDtoBuilder SetEstado(ulong habilitado, ulong cancelado) { + bool Habilitado = habilitado == 0?false:true; + bool Cancelado = cancelado == 0?false:true; + + if (Habilitado == true && Cancelado == false){ + data.Estado = "Alquiler Iniciado"; + } else if (Cancelado == true && Habilitado == false) { + data.Estado = "Nunca Empezo Esta Cancelado"; + } else if (Habilitado == false && Cancelado ==false){ + data.Estado = "Esta en Proceso"; + } else if (Habilitado == true && Cancelado == true){ + data.Estado = "Terminado"; + } + return this; + } + + public ContratoPropiedadDtoBuilder SetHabitaciones(int habitaciones){ + data.Habitaciones = habitaciones; + return this; + } + + public ContratoPropiedadDtoBuilder SetPiso(int piso){ + data.Piso = piso; + return this; + } + + public ContratoPropiedadDtoBuilder SetLetra(string letra){ + data.Letra = letra; + return this; + } + + public ContratoPropiedadDtoBuilder SetMesesAumento(int mesesAumento){ + data.MesesAumento = mesesAumento; + return this; + } + + public ContratoPropiedadDtoBuilder SetMesesDuracion(int mesesDurationContrato) { + data.MesesDuracion = mesesDurationContrato; + return this; + } +} diff --git a/Aspnet/Builder/DtoBuilder/DefectoDtoBuilder.cs b/Aspnet/Builder/DtoBuilder/DefectoDtoBuilder.cs new file mode 100644 index 0000000..c8e415b --- /dev/null +++ b/Aspnet/Builder/DtoBuilder/DefectoDtoBuilder.cs @@ -0,0 +1,34 @@ +using Entidades.Dto; + +namespace AlquilaFacil.Builder; +public class DefectoDtoBuilder: Builder { + public DefectoDtoBuilder SetId(long id) { + data.Id = id; + return this; + } + public DefectoDtoBuilder SetDesc(string Descripcion){ + data.Descripcion = Descripcion; + return this; + } + public DefectoDtoBuilder SetCosto(Decimal Costo){ + data.Costo = Costo; + return this; + } + public DefectoDtoBuilder SetEstado(string estado){ + data.Estado = estado; + return this; + } + public DefectoDtoBuilder SetIdContrato(long id){ + data.Idcontrato = id; + return this; + + } + public DefectoDtoBuilder SetPagaInquilino(ulong pag){ + data.Pagainquilino=pag==1?"Si":"No"; + return this; + } + public DefectoDtoBuilder SetDivisa(string divisa){ + data.Divisa = divisa; + return this; + } +} \ No newline at end of file diff --git a/Aspnet/Builder/DtoBuilder/GaranteDtoBuilder.cs b/Aspnet/Builder/DtoBuilder/GaranteDtoBuilder.cs new file mode 100644 index 0000000..6583038 --- /dev/null +++ b/Aspnet/Builder/DtoBuilder/GaranteDtoBuilder.cs @@ -0,0 +1,36 @@ +using Entidades.Dto; + +namespace AlquilaFacil.Builder; +public class GaranteDtoBuilder : Builder { + + public GaranteDtoBuilder SetDni (long Dni) { + data.Dni = Dni; + return this; + } + + public GaranteDtoBuilder SetNombre (string Nombre) { + data.Nombre = Nombre; + return this; + } + + public GaranteDtoBuilder SetApellido (string Apellido) { + data.Apellido = Apellido; + return this; + } + + public GaranteDtoBuilder SetDomicilio (string Domicilio) { + data.Domicilio = Domicilio; + return this; + } + + public GaranteDtoBuilder SetCelular (string Celular) { + data.Celular = Celular; + return this; + } + + public GaranteDtoBuilder SetDomicilioLaboral (string Domiciliolaboral) { + data.Domiciliolaboral = Domiciliolaboral; + return this; + } + +} \ No newline at end of file diff --git a/Aspnet/Builder/DtoBuilder/InformeAlquilerBuilder.cs b/Aspnet/Builder/DtoBuilder/InformeAlquilerBuilder.cs new file mode 100644 index 0000000..a0020ef --- /dev/null +++ b/Aspnet/Builder/DtoBuilder/InformeAlquilerBuilder.cs @@ -0,0 +1,17 @@ +using Entidades.Informes; + +namespace AlquilaFacil.Builder; +public class InformesAlquilerBuilder: Builder{ + public InformesAlquilerBuilder SetId(long id){ + data.Id = id; + return this; + } + public InformesAlquilerBuilder SetUbicacion(string Ubicacion){ + data.Ubicacion = Ubicacion; + return this; + } + public InformesAlquilerBuilder SetDivisa(string Divisa){ + data.Divisa = Divisa; + return this; + } +} \ No newline at end of file diff --git a/Aspnet/Builder/DtoBuilder/NotificacionDtoBuilder.cs b/Aspnet/Builder/DtoBuilder/NotificacionDtoBuilder.cs new file mode 100644 index 0000000..7f9cfdb --- /dev/null +++ b/Aspnet/Builder/DtoBuilder/NotificacionDtoBuilder.cs @@ -0,0 +1,34 @@ +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; + } + + public NotificacionDtoBuilder SetReceptor(string receptor) { + data.Receptor = receptor; + return this; + } +} \ No newline at end of file diff --git a/Aspnet/Builder/GaranteBuilder.cs b/Aspnet/Builder/GaranteBuilder.cs new file mode 100644 index 0000000..4c996f4 --- /dev/null +++ b/Aspnet/Builder/GaranteBuilder.cs @@ -0,0 +1,35 @@ +using Entidades; + +namespace AlquilaFacil.Builder; + +public class GaranteBuilder : Builder { + public GaranteBuilder SetNombre(string Nombre) { + data.Nombre = Nombre; + return this; + } + + public GaranteBuilder SetApellido(string Apellido) { + data.Apellido = Apellido; + return this; + } + + public GaranteBuilder SetDni(long Dni) { + data.Dni = Dni; + return this; + } + + public GaranteBuilder SetDomicilio(string Domicilio) { + data.Domicilio = Domicilio; + return this; + } + + public GaranteBuilder SetCelular(string Celular) { + data.Celular = Celular; + return this; + } + + public GaranteBuilder SetDomicilioLaboral(string Domiciliolaboral) { + data.Domiciliolaboral = Domiciliolaboral; + return this; + } +} \ 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/PrecontratoBuilder.cs b/Aspnet/Builder/PrecontratoBuilder.cs new file mode 100644 index 0000000..5e58b57 --- /dev/null +++ b/Aspnet/Builder/PrecontratoBuilder.cs @@ -0,0 +1,50 @@ +namespace AlquilaFacil.Builder; + +using System; +using Entidades; +public class PrecontratoBuilder : Builder { + public PrecontratoBuilder SetHabilitado(){ + data.Habilitado = 0; + return this; + } + + public PrecontratoBuilder SetInquilino(long dniInq) { + data.Dniinquilino = dniInq; + return this; + } + + public PrecontratoBuilder SetPropietario(long dniProp) { + data.Dnipropietario = dniProp; + return this; + } + + public PrecontratoBuilder SetPropiedad(int idprop) { + data.Idpropiedad = idprop; + return this; + } + + public PrecontratoBuilder SetCantidadGarantes(int cantgarante) { + data.Cantgarantemin = cantgarante; + return this; + } + + public PrecontratoBuilder SetIndiceActializacionInicial() { + data.Indiceactualizacion = 0.000M; + return this; + } + + public PrecontratoBuilder SetMesesHastaAumento(int meses) { + data.MesesHastaAumento = meses; + return this; + } + + public PrecontratoBuilder SetFecha(DateTime fechaprimernotificacion){ + data.Fechainicio = fechaprimernotificacion; + return this; + } + + public PrecontratoBuilder SetMesesDuracion(int mesesDuracionContrato){ + data.MesesDurationContrato = mesesDuracionContrato; + return this; + } +} \ No newline at end of file diff --git a/Aspnet/Config/MinioConfig.cs b/Aspnet/Config/MinioConfig.cs new file mode 100644 index 0000000..df4fec8 --- /dev/null +++ b/Aspnet/Config/MinioConfig.cs @@ -0,0 +1,5 @@ +namespace AlquilaFacil.Config; +public class MinioConfigcus { + public string usr { get; set; } =""; + public string scrt { get; set; } = ""; +} \ No newline at end of file diff --git a/Aspnet/Controllers/AccionesController.cs b/Aspnet/Controllers/AccionesController.cs index 240f30c..9be95b8 100644 --- a/Aspnet/Controllers/AccionesController.cs +++ b/Aspnet/Controllers/AccionesController.cs @@ -1,24 +1,40 @@ +using System.ComponentModel.DataAnnotations; using Entidades.Dto; using Microsoft.AspNetCore.Mvc; using Modelo; +using System.Text.Json; + namespace AlquilaFacil.Controllers; [ApiController] public class AccionesController: ControllerBase { - [HttpPost("api/acciones")] - public IActionResult ListarAccionesPorUsuario([FromBody] LoginDto email, [FromHeader(Name = "Auth")] string Auth) { - if (email.Email == "" || email.Email == null) return BadRequest(); - + [HttpGet("api/acciones")] + public IActionResult ListarAccionesPorUsuario([FromHeader(Name ="Email")] string Email, [FromHeader(Name = "Auth")] string Auth) { + if (Email == "" || Email == null) return BadRequest(); if (Auth == "") return Unauthorized(new { esValido = false}); - bool esValido = RepositorioUsuarios.Singleton.CheckToken(email.Email, Auth); + bool esValido = RepositorioUsuarios.Singleton.CheckToken(Email, Auth); if (!esValido) return Unauthorized(); - var Permisos = RepositorioPermisos.Singleton.ListarPermisos(email.Email); + var Permisos = RepositorioPermisos.Singleton.ListarPermisos(Email); Response.Headers["Content-Type"] = "application/json"; return Ok(Permisos); } + + [HttpPost("api/acciones/grupo")] + public IActionResult ListarAccionesPorGrupo([FromHeader(Name = "Auth")] string Auth, + [FromBody] AccionesPorGrupoDto req) { + if (string.IsNullOrEmpty(Auth)) return BadRequest(); + bool esValido = RepositorioUsuarios.Singleton.CheckToken(req.Email, Auth); + if (esValido == false) return BadRequest(esValido); + + bool tieneGrupo = RepositorioUsuarios.Singleton.CheckGrupo(req.Email, req.Grupo); + if (tieneGrupo == false) return Unauthorized(); + + var permisos = RepositorioGrupos.Singleton.ListarPermisosDeGrupo(req.Grupo); + return Ok(permisos); + } } \ No newline at end of file diff --git a/Aspnet/Controllers/AdminController.cs b/Aspnet/Controllers/AdminController.cs new file mode 100644 index 0000000..759c19d --- /dev/null +++ b/Aspnet/Controllers/AdminController.cs @@ -0,0 +1,152 @@ +using Microsoft.AspNetCore.Mvc; +using Modelo; +using Entidades.Admin; +using Entidades.Dto; +using Entidades; +using System.Linq.Expressions; +using AlquilaFacil.StrategyBusquedaAdmin; +using System.Diagnostics; +namespace AlquilaFacil.Controllers; + +[ApiController] +public class AdminController: ControllerBase +{ + [HttpGet("api/admin/clientes")] + public IActionResult GetClientes([FromHeader(Name ="Auth")]string Auth){ + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9); + if (validacion1 == false) return Unauthorized(); + + IEnumerablelist = RepositorioUsuarios.Singleton.GetClientes(); + return Ok(list); + } + + [HttpGet("api/admin/clientes/grupo")] + public IActionResult GetGruposByCliente([FromHeader(Name ="Auth")]string Auth, [FromQuery]long Dni){ + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9); + if (validacion1 == false) return Unauthorized(); + + if (Dni <= 0) return BadRequest(new {message = "No puede tener un dni con numero negativo o cero"}); + + IEnumerable list = RepositorioGrupos.Singleton.ObtenerGruposPorDni(Dni); + return Ok(list); + } + [HttpPatch("api/admin/cliente/addGrupo")] + public IActionResult AddGrupoACliente([FromHeader(Name = "Auth")]string Auth, [FromBody]EmailGrupo data){ + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9); + if (validacion1 == false) return Unauthorized(); + + if (data.email == "" || data.grupo == "") return BadRequest(new { message = "Faltan datos en la request" }); + + var ret = RepositorioUsuarios.Singleton.CheckGrupo(data.email, data.grupo); + if (ret) return BadRequest(new { message = $"El usuario ya pertenece al grupo {data.grupo}"}); + + var ret2 = RepositorioUsuarios.Singleton.AñadirClienteAGrupo(data.email, data.grupo); + + return ret2 ? Ok(new {message = "Se Añadio al Grupo"}): BadRequest(new { message = "Fallo al añadirse al Grupo" }); + } + + [HttpPatch("api/admin/cliente/rmGrupo")] + public IActionResult RmGrupoACliente([FromHeader(Name = "Auth")]string Auth, [FromBody]EmailGrupo data){ + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9); + if (validacion1 == false) return Unauthorized(); + + if (data.email == "" || data.grupo == "") return BadRequest(new { message = "Faltan datos en la request" }); + + //una ward para que no me bloquee a mi mismo de tener acceso a admin + if (data.email == "celu@fedesrv.ddns.net" && data.grupo == "Admin") return BadRequest(new { message = "Si hago esto me estaria bloqueando la cuenta a mi mismo" }); + + var ret = RepositorioUsuarios.Singleton.CheckGrupo(data.email, data.grupo); + if (!ret) return BadRequest(new { message = $"El usuario no pertenece al grupo {data.grupo}"}); + + if (data.grupo == "Propietario") { + IQueryable ret3 = RepositorioPropiedades.Singleton.ObtenerPropiedadesPorEmail(data.email); + if (ret3.Count() > 0){ + bool ret4 = RepositorioPropiedades.Singleton.BajaPropiedades(data.email); + if (ret4 == false) return BadRequest(new { message = "No se pudo dar de baja las propiedades"}); + } + } + if (data.grupo == "Inquilino") { + var ret5 = RepositorioContratos.Singleton.ObtenerContratosPorEmailInquilino(data.email); + if ( ret5 == null || ret5.Where(x=>x.Habilitado == 0).Count() > 0) return BadRequest(new { message = "Aun tenes alquileres pendientes o fallo al intentar obtener la lista de alquileres, no se puede dar de baja"}); + } + + var ret2 = RepositorioUsuarios.Singleton.EliminarClienteAGrupo(data.email, data.grupo); + return ret2 ? Ok(new {message = $"Se elimino del Grupo: {data.grupo}"}): BadRequest(new { message = "Fallo al añadirse al Grupo" }); + } + + [HttpDelete("api/admin/cliente")] + public IActionResult BajaCliente([FromHeader(Name ="Auth")]string Auth, long Dni){ + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9); + if (validacion1 == false) return Unauthorized(); + + if ( Dni <=0) return BadRequest(new {message = "No puede tener un Dni menor o igual a 0"}); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorDni(Dni); + + if (cli == null) return BadRequest(new {message = "No existe un cliente con ese numero de dni"}); + + bool esPropietario = RepositorioUsuarios.Singleton.CheckGrupo(cli.Email, "Propietario"); + bool esInquilino = RepositorioUsuarios.Singleton.CheckGrupo(cli.Email, "Inquilino"); + + if (esPropietario) { + IQueryable ret3 = RepositorioPropiedades.Singleton.ObtenerPropiedadesPorEmail(cli.Email); + if (ret3.Count() > 0){ + bool ret4 = RepositorioPropiedades.Singleton.BajaPropiedades(cli.Email); + if (ret4 == false) return BadRequest(new { message = "No se pudo dar de baja las propiedades"}); + } + } + + if (esInquilino) { + var ret5 = RepositorioContratos.Singleton.ObtenerContratosPorEmailInquilino(cli.Email); + if ( ret5 == null || ret5.Where(x=>x.Habilitado == 0).Count() > 0) return BadRequest(new { message = "Aun tenes alquileres pendientes o fallo al intentar obtener la lista de alquileres, no se puede dar de baja"}); + } + // lo da de baja si no tiene el grupo propietario y no tiene alquileres pendientes + var ret = RepositorioUsuarios.Singleton.BajaCliente(Dni); + return Ok(ret); + } + + [HttpDelete("api/admin/propiedad")] + public IActionResult BajaPropiedad([FromHeader(Name = "Auth")] string Auth, int id = 0) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10); + if (validacion1 == false) return Unauthorized(); + + if (id <= 0) return BadRequest(new { message = "Falto indicar id Propiedad"}); + + var ret = RepositorioPropiedades.Singleton.BajaPropiedad(id); + return ret ? + Ok(new {message = "Se cambio el estado de la propiedad"}): BadRequest(new { message = "No se pudo dar de baja"}); + } + + [HttpGet("api/admin/busqueda/paginada")] + public IActionResult FiltroPropiedadesPaginado([FromHeader(Name = "Auth")]string Auth, int cantidadHabitaciones = 0, int tipoPropiedad = 0, [FromQuery]string servicios = "", int pag = 1) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10); + if (validacion1 == false) return Unauthorized(); + + IQueryable? props = null; + pag -= 1; + + var clave = $"{(cantidadHabitaciones != 0 ? "1" : "0")}{(tipoPropiedad != 0 ? "1" : "0")}{(!string.IsNullOrEmpty(servicios) ? "1" : "0")}"; + var gen = AdminBusquedaContext.Singleton; + var estrategia = gen.ObtenerEstrategia(clave); + props = estrategia.Filtrar(servicios, cantidadHabitaciones, tipoPropiedad, pag); + + return Ok(props); + } + + [HttpGet("api/admin/busqueda/cantPag")] + public IActionResult CantidadPaginas([FromHeader(Name = "Auth")]string Auth, int cantidadHabitaciones = 0, int tipoPropiedad = 0, [FromQuery]string servicios = "") { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10); + if (validacion1 == false) return Unauthorized(); + + int ret = RepositorioPropiedades.Singleton.CuantasPaginasBusqueda(cantidadHabitaciones, servicios, tipoPropiedad, 0); + return Ok(new { message = ret}); + } +} \ No newline at end of file diff --git a/Aspnet/Controllers/BusquedaControler.cs b/Aspnet/Controllers/BusquedaControler.cs new file mode 100644 index 0000000..1098add --- /dev/null +++ b/Aspnet/Controllers/BusquedaControler.cs @@ -0,0 +1,38 @@ +using Entidades.Dto; +using Modelo; +using Microsoft.AspNetCore.Mvc; +using Entidades.Admin; +using AlquilaFacil.StrategyBusqueda; + +namespace AlquilaFacil.Controllers; + +[ApiController] +public class BusquedaController: ControllerBase { + [HttpGet("api/busqueda")] + public IActionResult FiltroPropiedades([FromHeader(Name = "Auth")]string Auth, int cantidadHabitaciones = 0, int tipoPropiedad = 0, [FromQuery]string servicios = "") { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 3); + if (validacion1 == false) return Unauthorized(); + + IQueryable? props = null; + + var clave = $"{(cantidadHabitaciones != 0 ? "1" : "0")}{(tipoPropiedad != 0 ? "1" : "0")}{(!string.IsNullOrEmpty(servicios) ? "1" : "0")}"; + + var gen = BusquedaContext.Singleton; + var estrategia = gen.ObtenerEstrategia(clave); + props = estrategia.Filtrar(servicios, cantidadHabitaciones, tipoPropiedad); + + return Ok(props); + } + + [HttpGet("api/busqueda/cantPag")] + public IActionResult GetCantPag([FromHeader(Name = "Auth")]string Auth, int cantidadHabitaciones = 0, int tipoPropiedad = 0, [FromQuery]string servicios = "") { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 3); + if (validacion1 == false) return Unauthorized(); + + int ret = RepositorioPropiedades.Singleton.CuantasPaginasBusqueda(cantidadHabitaciones, servicios, tipoPropiedad, 1); + return Ok(new { message = ret}); + + } +} diff --git a/Aspnet/Controllers/ContratoController.cs b/Aspnet/Controllers/ContratoController.cs new file mode 100644 index 0000000..fa6c146 --- /dev/null +++ b/Aspnet/Controllers/ContratoController.cs @@ -0,0 +1,822 @@ +using System.Net; +using System.Text.Json; +using AlquilaFacil.Builder; +using AlquilaFacil.Config; +using AlquilaFacil.Facade; +using Entidades; +using Entidades.Dto; +using Microsoft.AspNetCore.Mvc; +using Minio; +using Minio.DataModel; +using Minio.DataModel.Args; +using Minio.Exceptions; +using Modelo; + +namespace AlquilaFacil.Controllers; + +[ApiController] +public class ContratoController: ControllerBase { + + [HttpPost("api/contrato/GenerarRecibo")] + public ActionResult GenerarRecibo([FromHeader(Name="Auth")]string Auth, MarcarPagoDto dto, bool html= true) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false){ + validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false) { + return Unauthorized(); + } + } + + if (dto.Idcontrato <= 0) return BadRequest(new { message = "No puede tener un contrato con id 0 o menor"}); + + Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(dto.Idcontrato); + if (cont == null) return BadRequest(new { message = "No hay un contrato por ese id"}); + + if (cont.DniinquilinoNavigation == null || cont.DnipropietarioNavigation == null || cont.IdpropiedadNavigation == null || + cont.IdpropiedadNavigation.IdtipropiedadNavigation == null) return BadRequest(new { message = "comunicate con el admin esta mal cargado el contratod de alguina forma"}); + + Canon? can = RepositorioCanons.Singleton.ObtenerCanonContrato(dto.fecha, dto.Idcontrato); + if (can == null) return BadRequest(new { message = "no hay un canon para ese contrato con esa fecha"}); + if (can.IdreciboNavigation == null) return BadRequest(new { message = "No hay un recibo para ese canon"}); + + var cdb = new ContratoDtoBuilder() + .SetInquilino($"{cont.DniinquilinoNavigation.Nombre} {cont.DniinquilinoNavigation.Apellido}") + .SetUbicacion(cont.IdpropiedadNavigation.Ubicacion) + .SetPropietario($"{cont.DnipropietarioNavigation.Nombre} {cont.DnipropietarioNavigation.Apellido}") + .SetId(cont.Id) + .SetTipo(cont.IdpropiedadNavigation.IdtipropiedadNavigation.Descripcion) + .SetFechaInicio(cont.Fechainicio) + .SetEstado(cont.Habilitado, cont.Cancelado) + .Build(); + + var dof = new DocumentoFacade(); + MemoryStream? memstr = new(); + if (html){ + dof.GenerarHtml(cdb, can.IdreciboNavigation, memstr); + return File(memstr, "text/html", "Recibo.html"); + } else { + dof.GenerarPdf (cdb, can.IdreciboNavigation, memstr); + return File(memstr, "application/pdf", "Recibo.pdf"); + } + + } + + [HttpPost("api/contratos/marcarPago")] + public IActionResult marcarPago([FromHeader(Name="Auth")]string Auth, MarcarPagoDto dto) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false)return Unauthorized(); + if (dto.Idcontrato<=0) return BadRequest(new { message = "No puede existir un contrato con id 0 o menor"}); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null)return Unauthorized(); + + Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(dto.Idcontrato); + if (cont == null) return BadRequest(new { message = "No hay un contrato por esa id"}); + + if (cli.Dni != cont.Dnipropietario) return BadRequest(new {message = "No sos propietario o intenta volviendote a logear"}); + + Canon? c = RepositorioCanons.Singleton.ObtenerCanonContrato(dto.fecha, dto.Idcontrato); + if (c == null) return BadRequest(new { message = "no hay un canon por esa id"}); + + Recibo re = new Recibo{ + Monto = c.Monto, + Fecha = c.Fecha, + }; + + bool ret = RepositorioCanons.Singleton.SetRecibo(c, re); + return ret ? + Ok(new { message = "Se guardo correctamente"}):BadRequest(new { message = "No se pudo guardar"}); + + } + + [HttpPost("api/contratos/realizarPago")] + public IActionResult realizarPago([FromHeader(Name="Auth")]string Auth, MarcarPagoDto dto) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false) return Unauthorized(); + if (dto.Idcontrato<=0) return BadRequest(new { message = "No puede existir un contrato con id 0 o menor"}); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null)return Unauthorized(); + + Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(dto.Idcontrato); + if (cont == null) return BadRequest(new { message = "No hay un contrato por esa id"}); + + if (cli.Dni != cont.Dniinquilino) return BadRequest(new {message = "No sos inquilino o intenta volviendote a logear"}); + + Canon? c = RepositorioCanons.Singleton.ObtenerCanonContrato(dto.fecha, dto.Idcontrato); + if (c == null) return BadRequest(new { message = "no hay un canon por esa id"}); + + Recibo re = new Recibo{ + Monto = c.Monto, + Fecha = c.Fecha, + }; + + bool ret = RepositorioCanons.Singleton.SetRecibo(c, re); + return ret ? + Ok(new { message = "Se guardo correctamente"}):BadRequest(new { message = "No se pudo guardar"}); + } + + [HttpPost("api/contratos/crearcanons")] + public IActionResult crearCanons([FromHeader(Name="Auth")]string Auth, CrearCanonsDto dto){ + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false)return Unauthorized(); + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return Unauthorized(); + + if (dto.idcontrato <=0) return BadRequest(new { message ="estan mal cargados los datos"}); + + Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(dto.idcontrato); + if (cont == null) return BadRequest(new { message = "no hay un contrato por esa id"}); + if (cli.Dni != cont.Dnipropietario) return BadRequest(new {message = "No sos el propietario o intenta volviendote a logear"}); + + var ret = RepositorioCanons.Singleton.CrearCanons(dto.aumento, dto.idcontrato); + return ret ? + Ok(new { message = "Se crearon los canons correctamente"}):BadRequest(new { message = "No se pudo guardar"}); + } + + [HttpGet("api/contratos/canon")] + public ActionResult getCanons([FromHeader(Name="Auth")]string Auth, int id = 0) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false){ + validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false) { + return Unauthorized(); + } + } + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if(cli == null) return Unauthorized(); + + var cont = RepositorioContratos.Singleton.ObtenerContratoPorId(id); + if (cont == null) return BadRequest(new { message = "No existe el contrato"}); + if ( cont.Dnipropietario != cli.Dni && cont.Dniinquilino != cli.Dni) return Unauthorized(); + + var list = RepositorioCanons.Singleton.ObtenerCanonsPorContrato(id); + if (list == null) return BadRequest(new { message = "No hay contrato por esa id"}); + + string divisa =""; + if (cont.Iddivisa == 0) divisa = "AR$"; else if (cont.Iddivisa == 1) divisa = "US$"; + + List d = new(); + + foreach (var i in list) { + var c = new CanonDtoBuilder() + .SetId(i.Id) + .SetPago(i.Idrecibo==null?false:true) + .SetDivisa(divisa==""?"Ugh esta mal cargado la divisa en el contrato":divisa) + .SetMes(i.Fecha) + .SetMesNum(int.Parse((i.Fecha.Month - cont.Fechainicio.Month).ToString()) + 1) + .SetMonto(i.Monto) + .Build(); + d.Add(c); + } + + return Ok(d); + } + + [HttpGet("api/contratos/propietario")] + public IActionResult ObtenerContratosPorPropietario([FromHeader(Name="Auth")]string Auth) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false) return Unauthorized(); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli==null) return Unauthorized(); + + var list = RepositorioContratos.Singleton.ObtenerContratosDePropietario(cli.Dni); + + List dtos = new(); + foreach (var i in list) { + if (i.DniinquilinoNavigation == null || i.IdpropiedadNavigation == null + || i.DnipropietarioNavigation == null) continue; + + var cont = new ContratoDtoBuilder() + .SetInquilino($"{i.DniinquilinoNavigation.Nombre} {i.DniinquilinoNavigation.Apellido}") + .SetUbicacion(i.IdpropiedadNavigation.Ubicacion) + .SetId(i.Id) + .SetPropietario($"{i.DnipropietarioNavigation.Nombre} {i.DnipropietarioNavigation.Apellido}") + .SetTipo(i.IdpropiedadNavigation.IdtipropiedadNavigation.Descripcion) + .SetFechaInicio(i.Fechainicio) + .SetEstado(i.Habilitado, i.Cancelado) + .Build(); + dtos.Add(cont); + } + return Ok(dtos); + } + + [HttpGet("api/contrato/propietario")] + public IActionResult ObtenerContratoPorPropietarioPorId([FromHeader(Name="Auth")]string Auth, int id=0) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false) return Unauthorized(); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli==null) return Unauthorized(); + + if (id <= 0) return BadRequest(new { message = "No hay propiedades con id igual o menor a 0"}); + var i = RepositorioContratos.Singleton.ObtenerContratoPorId(id); + if (i == null || i.DniinquilinoNavigation == null || + i.IdpropiedadNavigation == null || i.DnipropietarioNavigation == null)return BadRequest(new { message = "Fallo la query"}); + if (cli.Dni != i.Dnipropietario) return BadRequest(new { message = "No sos el propietario"}); + + var cont = new ContratoPropiedadDtoBuilder() + .SetInquilino($"{i.DniinquilinoNavigation.Nombre} {i.DniinquilinoNavigation.Apellido}") + .SetUbicacion(i.IdpropiedadNavigation.Ubicacion) + .SetId(i.Id) + .SetPropietario($"{i.DnipropietarioNavigation.Nombre} {i.DnipropietarioNavigation.Apellido}") + .SetTipo(i.IdpropiedadNavigation.IdtipropiedadNavigation.Descripcion) + .SetFechaInicio(i.Fechainicio) + .SetEstado(i.Habilitado, i.Cancelado) + .SetHabitaciones(i.IdpropiedadNavigation.Canthabitaciones) + .SetPiso(i.IdpropiedadNavigation.Piso??0) + .SetLetra(i.IdpropiedadNavigation.Letra??"") + .SetMesesAumento(i.MesesHastaAumento) + .SetMesesDuracion(i.MesesDurationContrato) + .Build(); + + return Ok(cont); + } + + [HttpGet("api/contratos/inquilino")] + public IActionResult ObtenerContratosPorInquilino([FromHeader(Name="Auth")]string Auth) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false) return Unauthorized(); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli==null) return Unauthorized(); + + var list = RepositorioContratos.Singleton.ObtenerContratosDeInquilino(cli.Dni); + + List dtos = new(); + foreach (var i in list) { + if (i.DniinquilinoNavigation == null || i.IdpropiedadNavigation == null + || i.DnipropietarioNavigation == null) continue; + + var cont = new ContratoDtoBuilder() + .SetInquilino($"{i.DniinquilinoNavigation.Nombre} {i.DniinquilinoNavigation.Apellido}") + .SetUbicacion(i.IdpropiedadNavigation.Ubicacion) + .SetPropietario($"{i.DnipropietarioNavigation.Nombre} {i.DnipropietarioNavigation.Apellido}") + .SetId(i.Id) + .SetTipo(i.IdpropiedadNavigation.IdtipropiedadNavigation.Descripcion) + .SetFechaInicio(i.Fechainicio) + .SetEstado(i.Habilitado, i.Cancelado) + .Build(); + dtos.Add(cont); + } + return Ok(dtos); + } + + [HttpGet("api/contrato/inquilino")] + public IActionResult ObtenerContratoPorInquilinoPorId([FromHeader(Name="Auth")]string Auth, int id=0) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false) return Unauthorized(); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli==null) return Unauthorized(); + + if (id <= 0) return BadRequest(new { message = "No hay propiedades con id igual o menor a 0"}); + var i = RepositorioContratos.Singleton.ObtenerContratoPorId(id); + if (i == null || i.DniinquilinoNavigation == null || + i.IdpropiedadNavigation == null || i.DnipropietarioNavigation == null)return BadRequest(new { message = "Fallo la query"}); + if (cli.Dni != i.Dniinquilino) return BadRequest(new { message = "No sos el inquilino"}); + + var cont = new ContratoPropiedadDtoBuilder() + .SetInquilino($"{i.DniinquilinoNavigation.Nombre} {i.DniinquilinoNavigation.Apellido}") + .SetUbicacion(i.IdpropiedadNavigation.Ubicacion) + .SetId(i.Id) + .SetPropietario($"{i.DnipropietarioNavigation.Nombre} {i.DnipropietarioNavigation.Apellido}") + .SetTipo(i.IdpropiedadNavigation.IdtipropiedadNavigation.Descripcion) + .SetFechaInicio(i.Fechainicio) + .SetEstado(i.Habilitado, i.Cancelado) + .SetHabitaciones(i.IdpropiedadNavigation.Canthabitaciones) + .SetPiso(i.IdpropiedadNavigation.Piso??0) + .SetLetra(i.IdpropiedadNavigation.Letra??"") + .SetMesesAumento(i.MesesHastaAumento) + .SetMesesDuracion(i.MesesDurationContrato) + .Build(); + + return Ok(cont); + } + + [HttpPost("api/contratos/precontrato")] + public IActionResult IniciarPrecontrato([FromHeader(Name = "Auth")]string Auth, [FromBody] PrecontratoDto dto) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false) return Unauthorized(); + + string validacion2 = ValidarDtoPrecontrato(dto); + if (validacion2 != "") return BadRequest(new {message = validacion2}); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return BadRequest(new {message = "Tu token no corresponde a ningun cliente (volvete a logear)"}); + if (cli.Email != dto.EmailPropietario) return BadRequest(new {message = "No Corresponde el email de propietario con el del token"}); + + Cliente? propi = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(dto.EmailPropietario); + if (propi == null || propi.Dni == 0) return BadRequest(new {message = "No hay propietario por ese email"}); + + Cliente? inq = RepositorioInquilinos.Singleton.ObtenerInquilinoPorEmail(dto.EmailInquilino); + if (inq == null || inq.Dni == 0) return BadRequest(new {message = "No hay inquilinos por ese email"}); + + Propiedade? p = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(dto.IdPropiedad); + if (p == null || p.Id == 0) return BadRequest(new {message = "La id de propiedad no corresponde a una propiedad"}); + + var precontrato = new PrecontratoBuilder() + .SetHabilitado() + .SetPropietario(propi.Dni) + .SetInquilino(inq.Dni) + .SetCantidadGarantes(dto.CantidadGarantes) + .SetIndiceActializacionInicial() + .SetMesesHastaAumento(dto.MesesHastaAumento) + .SetPropiedad(p.Id) + .SetFecha(DateTime.Parse(dto.fechaprimernotificacion)) + .SetMesesDuracion(dto.MesesDuracionContrato) + .Build(); + + + var notificacion = new NotificacioneBuilder() + .SetAccion("Carge Garantes") + .SetDniremitente(propi.Dni) + .SetDnicliente(inq.Dni) + .SetLeido(false) + .SetFecha(DateTime.Now) + .SetIdpropiedad(p.Id) + .SetMensaje($"El propietario {propi.Nombre} {propi.Apellido} te requiere que carges informacion de {dto.CantidadGarantes} Garantes") + .Build(); + + var ret = RepositorioContratos.Singleton.CargaPrecontrato(precontrato, notificacion); + if (ret) { + ret = RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, DateTime.Parse(dto.fechaprimernotificacion)); + } + return (ret)? + Ok(new {message = "Se Cargo el precontrato y envio una notificacion al inquilino"}): + BadRequest(new {message = "No se pudo cargar el precontrato"}); + } + + [HttpPut("api/contratos/addGarantes")] + public IActionResult AddGarantes([FromHeader(Name = "Auth")]string Auth, AltaGarantesDto dto) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(""); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false) return Unauthorized(); + + var validacion2 = ValidarDtoAltaGarantes(dto); + if (validacion2 != "") return BadRequest(new {message = validacion2}); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return BadRequest(new {message = "Tu token no corresponde a ningun cliente (volvete a logear)"}); + if (cli.Email != dto.EmailInquilino) return BadRequest(new {message = "No Corresponde el email de inquilino con el del token"}); + + var validacion4 = RepositorioContratos.Singleton.CantidadGarantesEncontrato(dto.EmailInquilino, dto.Idpropiedad); + if (validacion4 <= 0 || dto.garantes.Count()!=validacion4) return BadRequest(new{message="Cantidad de garantes incorrecta"}); + + Cliente? propi = RepositorioPropietario.Singleton.ObtenerPropietarioPorIdPropiedad(dto.Idpropiedad); + if(propi == null) return BadRequest(new{message = "No se encuentra el propietario de la propiedad"}); + + foreach (var i in dto.garantes) { + string validacion3 = ValidarDtoGarante(i); + if (validacion3 != "") return BadRequest( new { message = validacion3 }); + } + + List gar = new(); + + foreach (var i in dto.garantes) { + Garante g = new GaranteBuilder() + .SetNombre(i.Nombre) + .SetApellido(i.Apellido) + .SetCelular(i.Celular) + .SetDomicilio(i.Domicilio) + .SetDni(i.Dni) + .SetDomicilioLaboral(i.Domiciliolaboral) + .Build(); + gar.Add(g); + } + + var contr = RepositorioContratos.Singleton.ObtenerContrato(dto.EmailInquilino, dto.Idpropiedad); + if (contr == null) return BadRequest(new { message = "No existe el contrato o ya fue activado"}); + + var ret = RepositorioContratos.Singleton.CargaGarantes(gar, dto.EmailInquilino, dto.Idpropiedad); + if (ret) { + Console.WriteLine(dto.fecha); + RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.fecha); + + var noti = new NotificacioneBuilder() + .SetIdpropiedad(dto.Idpropiedad) + .SetAccion("Check y Contrato") + .SetMensaje($"El inquilino cargó los datos de garantes comprobá y carga el contrato: {contr.Id}") + .SetLeido(false) + .SetDniremitente(cli.Dni) + .SetDnicliente(propi.Dni) + .SetFecha(DateTime.Now) + .Build(); + ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti); + } + return ret ? + Ok(new {message = "Se Añadieron los Garantes"}):BadRequest(new { message = "Fallo la carga"}); + } + + [HttpPut("api/contratos/cancelar")] + public IActionResult CancelarPrecontrato([FromHeader(Name = "Auth")]string Auth, CancelarPrecontratoDto dto) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(""); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false) return Unauthorized(); + + var validacion2 = ValidarCancelarDto(dto); + if (validacion2 != "") return BadRequest(new {message = validacion2}); + + Cliente? pro = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(dto.EmailPropietario); + if (pro == null) return BadRequest(new {message = "No Existe Usuario con ese email"}); + if (pro.Token != Auth) return BadRequest(new {message = "El token de auth no corresponde al token el usuario propietario"}); + + Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(dto.idpropiedad); + if (prop == null) return BadRequest(new {message = "No existe la propiedad por esa id"}); + if (prop.Dnipropietario != pro.Dni) return BadRequest(new {message = "Este propietario no es el dueño de la propiedad"}); + + var inq = RepositorioInquilinos.Singleton.ObtenerInquilinoPorEmail(dto.EmailInquilino); + if (inq == null) return BadRequest(new {message = "No hay un inquilino por ese email"}); + + var ret = RepositorioContratos.Singleton.CancelarPrecontrato(dto.EmailInquilino, dto.idpropiedad); + if (ret) { + prop.Idestado = 1; + ret = RepositorioPropiedades.Singleton.PatchPropiedad(prop); + if (ret){ + RepositorioNotificaciones.Singleton.MarcarComoLeido(pro.Dni, dto.fecha); + var noti = new NotificacioneBuilder() + .SetAccion("ContratoCancelado") + .SetIdpropiedad(dto.idpropiedad) + .SetDniremitente(pro.Dni) + .SetDnicliente(inq.Dni) + .SetMensaje($"Se cancelo el intento de alquilar la propiedad: {dto.idpropiedad}") + .SetIdpropiedad(dto.idpropiedad) + .SetLeido(false) + .Build(); + ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti); + if (ret){ + return Ok(new {message = "Se cancelo el precontrato"}); + }else{ + return Ok(new {message = "Se cancelo el precontrato, pero no se pudo notificar al inquilino"}); + } + }else{ + return BadRequest(new {message = "No se pudo setear la propiedad como Disponible en busqueda"}); + } + }else{ + return BadRequest(new {message = "Se fallo al intentar cancelar el precontrato"}); + } + } + + [HttpGet("api/contratos/precontrato/listaGarantes")] + public IActionResult ObtenerListaGarantes([FromHeader(Name = "Auth")]string Auth, long idcontrato = 0, [FromQuery] string EmailPropietario = "" ) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(""); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false) return Unauthorized(); + + if (idcontrato == 0 || EmailPropietario == "") return BadRequest(new { message = "Estan mal cargados los datos"}); + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return BadRequest(new {message = "No hay un propietario por ese token"}); + if (cli.Email != EmailPropietario) return BadRequest(new {message = "El Email del usuario no coinside con el del token"}); + + Contrato? contr = RepositorioContratos.Singleton.ObtenerPreContratoPorId(idcontrato); + if (contr == null) return BadRequest(new {message = "No hay un precontrato por esa id"}); + + LinkedList list = new(); + foreach (var i in contr.Idgarantes) { + list.AddFirst(new GaranteDtoBuilder() + .SetCelular(i.Celular) + .SetDni(i.Dni) + .SetDomicilio(i.Domicilio) + .SetDomicilioLaboral(i.Domiciliolaboral) + .SetNombre(i.Nombre) + .SetApellido(i.Apellido) + .Build()); + } + return Ok(list); + } + + private readonly IMinioClient mc; + public ContratoController(IMinioClient minioClient) { + mc = minioClient; + if (mc == null){ + MinioConfigcus? mcon = JsonSerializer.Deserialize(System.IO.File.ReadAllText("./settings.json"))?? null; + if (mcon == null) throw new Exception(); + + mc = new MinioClient().WithCredentials(mcon.usr, mcon.scrt) + .WithEndpoint("192.168.1.11:9000") + .WithSSL(false) + .Build(); + } + } + + [HttpPost("api/contratos/subirContrato")] + public async Task subirContrato([FromHeader(Name = "Auth")]string Auth, [FromForm]long idcontrato, [FromForm]DateTime ubicarnotificacion, IFormFile contrato) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(""); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false) return Unauthorized(); + + if (idcontrato<=0) return BadRequest(new {message = "No puede tener un id contrato menor o igual a 0"}); + Contrato? contr = RepositorioContratos.Singleton.ObtenerPreContratoPorId(idcontrato); + if (contr == null) return BadRequest(new { message = "No hay precontrato por esa id"}); + if (contr.Dniinquilino == 0 || contr.Dnipropietario == 0 || contr.Idpropiedad == 0 || + contr.Dniinquilino == null || contr.Dnipropietario == null || contr.Idpropiedad == null) { + return BadRequest(new { message = "Estan mal cargados los datos del precontrato comunicate con un administrador"}); + } + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null || contr.DnipropietarioNavigation == null) return BadRequest(new { message ="No se pudo checkear que el token corresponda al propietario"}); + if (cli.Dni != contr.DnipropietarioNavigation.Dni) return BadRequest(new { message = "el token de usuario no coinside con el usuario propietario"}); + + if (contrato == null) return BadRequest(new { message = "Debe subir un archivo." }); + if (contrato.ContentType != "application/pdf") return BadRequest(new { message = "El archivo debe ser un documento PDF." }); + if (!Path.GetExtension(contrato.FileName).Equals(".pdf", StringComparison.OrdinalIgnoreCase)) return BadRequest(new { message = "El archivo debe tener la extensión .pdf." }); + + string nuevoNombreArchivo = $"id:{contr.Id}-inq:{contr.Dniinquilino}-propi:{contr.Dnipropietario}-idprop:{contr.Idpropiedad}.pdf"; + + bool ret = await subirContrato(contrato, nuevoNombreArchivo); + if(ret == false) return BadRequest(new {message = "No se pudo subir el archivo"}); + + ret = RepositorioContratos.Singleton.AddUrl(contr.Id, nuevoNombreArchivo); + if (ret == false) return BadRequest(new { message = "No se pudo guardar la url del contrato" }); + + var noti = new NotificacioneBuilder() + .SetDniremitente(contr.Dnipropietario??0) + .SetIdpropiedad(contr.Idpropiedad??0) + .SetDnicliente(contr.Dniinquilino??0) + .SetAccion("Aceptar Contrato") + .SetMensaje($"El propietario: {contr.Dnipropietario}, hizo un documento de contrato: {contr.Id}") + .SetFecha(DateTime.Now) + .SetLeido(false) + .Build(); + + RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, ubicarnotificacion); + ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti); + + return (ret)? + Ok(new { message = "se notifico al futuro inquilino"}): BadRequest(new { message = "No se pudo enviar la notificacion"}); + + } + [HttpGet("api/contrato/DocumentoFinal")] + public IActionResult ObtenerContratoFinal ([FromHeader(Name = "Auth")]string Auth, [FromQuery]long idcontrato) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(""); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false){ + validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false) return Unauthorized(); + } + + if (idcontrato <= 0) return BadRequest(new {message = "La id no puede ser igual o menor a 0"}); + + Contrato? contr = RepositorioContratos.Singleton.ObtenerContratoPorId(idcontrato); + if (contr == null || contr.Dniinquilino == 0) return BadRequest(new { message = "No hay un contrato por esa id"}); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token"}); + if (cli.Dni != contr.Dniinquilino && cli.Dni != contr.Dnipropietario) return BadRequest(new { message = "El token no corresponde con el del inquilino"}); + + try{ + var memstream = new MemoryStream(); + + var goa = new GetObjectArgs() + .WithBucket("alquilafacil") + .WithObject(contr.UrlContrato) + .WithCallbackStream(stream => { + memstream.Position=0; + stream.CopyTo(memstream); + }); + + mc.GetObjectAsync(goa).Wait(); + memstream.Position = 0; + + if (memstream.Length == 0) return BadRequest(new { message = "El archivo está vacío" }); + + return File(memstream, "application/pdf", contr.UrlContrato); + + } catch (Exception e){ + Console.Error.WriteLine(e); + return BadRequest(new { message = "Fallo al intentar obtener el archivo del almacenamiento o este no existe"}); + } + } + + [HttpGet("api/contrato/getdocumento")] + public IActionResult ObtenerContrato([FromHeader(Name = "Auth")]string Auth, [FromQuery]long idcontrato) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(""); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false){ + validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false) return Unauthorized(); + } + + if (idcontrato <= 0) return BadRequest(new {message = "La id no puede ser igual o menor a 0"}); + + Contrato? contr = RepositorioContratos.Singleton.ObtenerPreContratoPorId(idcontrato); + if (contr == null || contr.Dniinquilino == 0) return BadRequest(new { message = "No hay un precontrato por esa id"}); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token"}); + if (cli.Dni != contr.Dniinquilino) return BadRequest(new { message = "El token no corresponde con el del inquilino"}); + + string nuevoNombreArchivo = $"id:{contr.Id}-inq:{contr.Dniinquilino}-propi:{contr.Dnipropietario}-idprop:{contr.Idpropiedad}.pdf"; + try{ + var memstream = new MemoryStream(); + + var goa = new GetObjectArgs() + .WithBucket("alquilafacil") + .WithObject(nuevoNombreArchivo) + .WithCallbackStream(stream => { + memstream.Position=0; + stream.CopyTo(memstream); + }); + + mc.GetObjectAsync(goa).Wait(); + memstream.Position = 0; + + if (memstream.Length == 0) return BadRequest(new { message = "El archivo está vacío" }); + + return File(memstream, "application/pdf", nuevoNombreArchivo); + + } catch (Exception e){ + Console.Error.WriteLine(e); + return BadRequest(new { message = "Fallo al intentar obtener el archivo del almacenamiento o este no existe"}); + } + + } + + [HttpPost("api/contratos/aceptarContrato")] + public IActionResult AceptarContrato([FromHeader(Name = "Auth")]string Auth, [FromBody] AceptarContratoDto dto){ + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false) return Unauthorized(); + + if (dto.Idcontrato <= 0) return BadRequest(new {message = "La id no puede ser igual o menor a 0"}); + + Contrato? contr = RepositorioContratos.Singleton.ObtenerPreContratoPorId(dto.Idcontrato); + if (contr == null || contr.Dniinquilino == 0) return BadRequest(new { message = "No hay un precontrato por esa id"}); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token"}); + if (cli.Dni != contr.Dniinquilino) return BadRequest(new { message = "El token no corresponde con el del inquilino"}); + + bool ret = RepositorioContratos.Singleton.AceptarContrato(dto.Idcontrato); + if (ret == false) return BadRequest(new { message ="fallo al aceptar el contrato"}); + + RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.Fecha); + + var noti = new NotificacioneBuilder() + .SetDniremitente(cli.Dni) + .SetIdpropiedad(contr.Idpropiedad??0) + .SetDnicliente(contr.Dnipropietario??0) + .SetAccion("Aceptado Contrato") + .SetMensaje($"Se inicio el alquiler") + .SetFecha(DateTime.Now) + .SetLeido(false) + .Build(); + + ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti); + return ret ? + Ok(new { message = "Se acepto el contrato y se crearon los Canons a ser pagados"}) : + BadRequest(new { message = "No se pudo aceptar el contrato"}); + + } + + [HttpPut("api/contratos/rechazarPreContrato")] + public IActionResult CancelarContrato([FromHeader(Name = "Auth")]string Auth, [FromBody] RechazarPreContrato dto ) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false) return Unauthorized(); + + if (dto.Idcontrato <= 0) return BadRequest(new {message = "La id no puede ser igual o menor a 0"}); + + Contrato? contr = RepositorioContratos.Singleton.ObtenerPreContratoPorId(dto.Idcontrato); + if (contr == null || contr.Dniinquilino == 0) return BadRequest(new { message = "No hay un precontrato por esa id"}); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token"}); + if (cli.Dni != contr.Dniinquilino) return BadRequest(new { message = "El token no corresponde con el del inquilino"}); + + var ret = RepositorioContratos.Singleton.CancelarPrecontrato(dto.Idcontrato); + if (ret == false) return BadRequest(new {message = "Fallo al intentar cancelar el precontrato"}); + + RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.Fecha); + var noti = new NotificacioneBuilder() + .SetDniremitente(cli.Dni) + .SetIdpropiedad(contr.Idpropiedad??0) + .SetDnicliente(contr.Dnipropietario??0) + .SetAccion("Rechazo Contrato") + .SetMensaje($"Se cancelo el proceso para alquilar de: {cli.Nombre}") + .SetFecha(DateTime.Now) + .SetLeido(false) + .Build(); + ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti); + + return ret? + Ok(new { message = "Se cancelo el proceso para iniciar el alquiler"}): + BadRequest(new { message = "No se pudo cancelar"}); + } + + private async Task subirContrato(IFormFile f, string flname) { + try { + var buck = new BucketExistsArgs().WithBucket("alquilafacil"); + bool encontrado = await mc.BucketExistsAsync(buck).ConfigureAwait(false); + + if(!encontrado){ + var mb = new MakeBucketArgs().WithBucket("alquilafacil"); + await mc.MakeBucketAsync(mb).ConfigureAwait(false); + } + using (var stream = new MemoryStream()){ + await f.CopyToAsync(stream); + stream.Position=0; + PutObjectArgs putbj = new PutObjectArgs() + .WithBucket("alquilafacil") + .WithObject(flname) + .WithStreamData(stream) + .WithContentType("application/pdf") + .WithObjectSize(stream.Length); + await mc.PutObjectAsync(putbj); + } + return true; + } catch (Exception e ) { + Console.Error.WriteLine(e.Message); + return false; + } + } + + [HttpGet("api/contratos/garantes")] + public IActionResult ObtenerGarantes([FromHeader(Name ="Auth")] string Auth, int idcontrato) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(); + if(idcontrato <= 0) return BadRequest(); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return BadRequest(); + + Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(idcontrato); + if (cont == null) return BadRequest(); + + if (cont.Dniinquilino != cli.Dni && cont.Dnipropietario != cli.Dni) return BadRequest(); + + var list = cont.Idgarantes; + List l = new(); + foreach (var i in list) { + l.Add(new GaranteDtoBuilder() + .SetCelular(i.Celular) + .SetDni(i.Dni) + .SetDomicilio(i.Domicilio) + .SetDomicilioLaboral(i.Domiciliolaboral) + .SetNombre(i.Nombre) + .SetApellido(i.Apellido) + .Build()); + } + return Ok(l); + } + + private string ValidarCancelarDto(CancelarPrecontratoDto dto) { + if (dto == null) return "dto nulo"; + string ret = ""; + + if (dto.EmailInquilino =="") ret += "No puede tener un EmailInquilino Vacio\n"; + if (dto.EmailPropietario =="") ret += "No puede tener un EmailPropietario Vacio\n"; + if (dto.idpropiedad <= 0 ) ret += "No puede tener id propiedad igual o menor a 0\n"; + if (dto.fecha == DateTime.MinValue) ret += "Falta fecha\n"; + return ret; + } + + private string ValidarDtoGarante(GaranteDto g) { + string ret = ""; + if (g == null) return "dto nulo"; + + if (g.Celular == "") ret += "No puede tener un numero de telefono vacio\n"; + if (g.Nombre == "") ret += "No puede tener un nombre vacio\n"; + if (g.Apellido == "") ret += "No puede tener un apellido vacio\n"; + if (g.Domiciliolaboral == "") ret += "Tiene que especificar su domicilio laboral\n"; + if (g.Domicilio == "") ret += "Tiene que especificar su domilio\n"; + + return ret; + } + + private string ValidarDtoAltaGarantes(AltaGarantesDto dto){ + string ret = ""; + if (dto == null) return "dto nulo"; + + if (dto.garantes.Count()<=0) ret += "No se puede tener 0 o menos garantes\n"; + if (dto.Idpropiedad<=0) ret += "la id de propiedad no puede ser igual o menor a 0\n"; + if (dto.EmailInquilino == "") ret += "El email de inquilino no puede estar vacio\n"; + + return ret; + } + private string ValidarDtoPrecontrato( PrecontratoDto dto) { + string ret = ""; + if (dto == null) return "dto nulo"; + + if (dto.CantidadGarantes<0) ret += "la cantidad de garantes necesarios no pueden ser menor a 0\n"; + if (dto.CantidadGarantes>10) ret += "Hay un maximo de 10 garantes\n"; + if (dto.EmailInquilino == "") ret += "el email del inquilino no puede ser nulo\n"; + if (dto.EmailPropietario == "") ret += "el email del propietario no puede estar vacio\n"; + if (dto.IdPropiedad <= 0) ret += "la id de propiedad no puede ser igual o menor a 0\n"; + if (dto.MesesHastaAumento <= 0) ret += "No puede tener 0 o menos meses hasta el aumento\n"; + if (dto.MesesDuracionContrato <= 0) ret += "No puede tener 0 o menos meses de duracion\n"; + if (dto.MesesDuracionContrato < dto.MesesHastaAumento) ret += "el tiempo hasta aumento no puede ser mayor de \n"; + return ret; + } + +} \ No newline at end of file diff --git a/Aspnet/Controllers/DefectoController.cs b/Aspnet/Controllers/DefectoController.cs new file mode 100644 index 0000000..a7f9fef --- /dev/null +++ b/Aspnet/Controllers/DefectoController.cs @@ -0,0 +1,95 @@ +using AlquilaFacil.Builder; +using Entidades; +using Entidades.Dto; +using Microsoft.AspNetCore.Mvc; +using Modelo; + +namespace AlquilaFacil.Controllers; + +[ApiController] +public class DefectoController: ControllerBase { + + [HttpGet("api/defectos")] + public IActionResult ObtenerDefectosEnContrato([FromHeader(Name = "Auth")] string Auth, long Idcontrato = 0) { + if (Idcontrato <= 0) return BadRequest( new { message = "La id de contrato no puede ser menor o igual a 0"}); + + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false){ + validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false) { + return Unauthorized(); + } + } + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return Unauthorized(); + + Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(Idcontrato); + if (cont == null) return BadRequest(new { message = "No hay contrato por esa id"}); + + if (cont.Dniinquilino != cli.Dni && cont.Dnipropietario != cli.Dni) return BadRequest(new { message = "no deberias tener acceso a esto"}); + + var l = RepositorioDefectos.Singleton.ObtenerDefectosPorIdContrato(Idcontrato); + List ll = new(); + foreach (var i in l){ + var n = new DefectoDtoBuilder() + .SetId(i.Id) + .SetDesc(i.Descripcion) + .SetCosto(i.Costo) + .SetEstado(i.IdestadoNavigation.Descipcion) + .SetIdContrato(i.Idcontrato??0) + .SetPagaInquilino(i.Pagainquilino) + .SetDivisa(i.IddivisaNavigation.Signo) + .Build(); + ll.Add(n); + } + return Ok(ll); + } + + [HttpPost("api/defecto")] + public IActionResult AltaDefecto([FromHeader(Name = "Auth")] string Auth, AltaDefectoDto data) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false) return Unauthorized(); + + string r = ValidarDto(data); + if (r != "") return BadRequest(new { message = r }); + + Defecto defecto = new Defecto{ + Costo = data.Costo, + Descripcion = data.Descripcion, + Idcontrato = data.Idcontrato, + Iddivisa = data.Iddivisa, + Pagainquilino = data.Pagainquilino==0?0Lu:1Lu, + Idestado = 1, + + }; + var b = RepositorioDefectos.Singleton.AltaDefecto(defecto); + return b ?Ok(new { message = "Se cargo el Defecto en el sistema"}):BadRequest(new { message ="No se pudo cargar el defecto en el sistema"}); + } + + private string ValidarDto(AltaDefectoDto d){ + string ret =""; + + if (d == null) return "Dto nulo"; + if (d.Iddivisa <0 || d.Iddivisa>1) ret +="No son divisas validas\n"; + if (d.Descripcion == "") ret+="La descripcion no puede estar vacia\n"; + if (d.Idcontrato<=0)ret += "No puede haber un id de contrato igual o menor a 0\n"; + + return ret; + } + + [HttpPut("api/defecto/marcarpago")] + public IActionResult MarcarPago([FromHeader(Name = "Auth")] string Auth, long iddefecto = 0) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false) return Unauthorized(); + + if (iddefecto<=0) return BadRequest(new { message = "No hay canones con id 0 o menor"}); + bool ret = RepositorioDefectos.Singleton.MarcarPago(iddefecto); + + return ret ? + Ok(new { message = "Se marco como pagado" }):BadRequest(new { message = "Fallo el acceso a la base de datos o no se encontro el defecto" }); + } +} diff --git a/Aspnet/Controllers/EstadisticaController.cs b/Aspnet/Controllers/EstadisticaController.cs new file mode 100644 index 0000000..93db4df --- /dev/null +++ b/Aspnet/Controllers/EstadisticaController.cs @@ -0,0 +1,60 @@ +using AlquilaFacil.Builder; +using Entidades.Informes; +using Microsoft.AspNetCore.Mvc; +using Modelo; + +namespace AlquilaFacil.Controllers; +[ApiController] +public class EstadisticaController: ControllerBase { + [HttpGet("api/stats/alquileresIniciados")] + public IActionResult alquileresIniciadosEsteAño([FromHeader(Name ="Auth")]string Auth, int year) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(""); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes"); + if (validacion1 == false) return Unauthorized(); + + var validacion2 = RepositorioContratos.Singleton.HayContratosEnAño(year); + if (validacion2 == false) return BadRequest(new { message = "No hay contratos en ese año"}); + var a = RepositorioEstadisticas.Singleton.ObtenerDataIniciadosPorAño(year); + return Ok(a); + } + [HttpGet("api/tabla/alquileresIniciados")] + public IActionResult tablaalquileresIniciadosEsteAño([FromHeader(Name ="Auth")]string Auth, int year) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(""); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes"); + if (validacion1 == false) return Unauthorized(); + + var validacion2 = RepositorioContratos.Singleton.HayContratosEnAño(year); + if (validacion2 == false) return BadRequest(new { message = "No hay contratos en ese año"}); + var a = RepositorioEstadisticas.Singleton.TablaObtenerContratosIniciadosPorAño(year); + if (a == null) return BadRequest(new { message = "Fallo al obtener el contrato"}); + + List informe =new(); + foreach (var i in a) { + var d = new InformesAlquilerBuilder() + .SetId(i.Id).SetUbicacion(i.IdpropiedadNavigation.Ubicacion) + .SetDivisa(i.IddivisaNavigation.Signo) + .Build(); + informe.Add(d); + } + return Ok(informe); + } + [HttpGet("api/stats/duracionContrato")] + public IActionResult DuracionContrato([FromHeader(Name ="Auth")]string Auth) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(""); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes"); + if (validacion1 == false) return Unauthorized(); + + var a = RepositorioEstadisticas.Singleton.ObtenerDataDuracionContratos(); + return Ok(a); + } + + [HttpGet("api/tabla/duracionContrato")] + public IActionResult TablaDuracionContrato([FromHeader(Name ="Auth")]string Auth) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(""); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes"); + if (validacion1 == false) return Unauthorized(); + + var a = RepositorioEstadisticas.Singleton.TablaObtenerDataDuracionContratos(); + return Ok(a); + } +} \ No newline at end of file diff --git a/Aspnet/Controllers/GruposController.cs b/Aspnet/Controllers/GruposController.cs index dd8f26b..be028f2 100644 --- a/Aspnet/Controllers/GruposController.cs +++ b/Aspnet/Controllers/GruposController.cs @@ -6,17 +6,16 @@ namespace AlquilaFacil.Controllers; [ApiController] public class GruposController: ControllerBase { [HttpPost("api/admin/grupos")] - public IActionResult CrearGrupo([FromBody] AdminGrupo grupo) { + public IActionResult CrearGrupo([FromBody] AdminGrupo grupo, [FromHeader(Name = "Auth")] string Auth) { + if (!string.IsNullOrEmpty(Auth)) return BadRequest(); + var ret2 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10); + if (ret2 == false) return BadRequest(ret2); + if (String.IsNullOrEmpty(grupo.descripcion)) return BadRequest(); bool ret = RepositorioGrupos.Singleton.CrearGrupo(grupo.descripcion); return (ret) ? Ok(ret) : BadRequest(); } - - [HttpGet("api/admin/grupos")] - public IActionResult ListarGrupo(){ - return Ok(RepositorioGrupos.Singleton.Listar()); - } } public record AdminGrupo(string descripcion); diff --git a/Aspnet/Controllers/InquilinoController.cs b/Aspnet/Controllers/InquilinoController.cs index 255ae7e..866040d 100644 --- a/Aspnet/Controllers/InquilinoController.cs +++ b/Aspnet/Controllers/InquilinoController.cs @@ -15,9 +15,8 @@ public class InquilinoController: ControllerBase [HttpGet("api/inquilino")] public IActionResult Get([FromHeader(Name = "Auth")] string Auth) { if (!string.IsNullOrEmpty(Auth)) return BadRequest(); - string path = Request.Path; + var ret = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9); - var ret = RepositorioPermisos.Singleton.CheckPermisos(Auth, path); if (ret == false) return BadRequest(ret); var list = RepositorioInquilinos.Singleton.GetInquilinos(); @@ -26,10 +25,14 @@ public class InquilinoController: ControllerBase } [HttpPost("api/inquilino")] - public IActionResult Post([FromBody] CrearClienteDto cid) { + public IActionResult Post([FromBody] CrearClienteDto cid, [FromHeader(Name = "Auth")] string Auth) { + if (string.IsNullOrEmpty(Auth)) return BadRequest(new {message = "El String Auth Esta Vacio"}); + var ret3 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 4); + if (ret3 == false) return BadRequest(new {message = "Falló el permiso"}); + var ret = verificarCrearUsuario(cid); - if (ret != "") return BadRequest(ret); + if (ret != "") return BadRequest(new {message = ret}); var cli = new Cliente { Dni = cid.dni, @@ -42,7 +45,7 @@ public class InquilinoController: ControllerBase }; bool ret2 = RepositorioUsuarios.Singleton.AltaInquilino(cli); - return (ret2) ? Ok() : BadRequest(ret); + return (ret2) ? Ok(new {message = "Se dio de alta la cuenta"}) : BadRequest(new {message = "Fallo Dar de Alta El inquilino"}); } private string verificarCrearUsuario(CrearClienteDto cid) { diff --git a/Aspnet/Controllers/LoginController.cs b/Aspnet/Controllers/LoginController.cs index 2667370..b4efd38 100644 --- a/Aspnet/Controllers/LoginController.cs +++ b/Aspnet/Controllers/LoginController.cs @@ -53,7 +53,6 @@ public class LoginController: ControllerBase } - private string GenerarToken(LoginDto loginDto){ var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes("ffb2cdc15d472e41a5b626e294c45020"); diff --git a/Aspnet/Controllers/NotificacionesController.cs b/Aspnet/Controllers/NotificacionesController.cs new file mode 100644 index 0000000..3fadadd --- /dev/null +++ b/Aspnet/Controllers/NotificacionesController.cs @@ -0,0 +1,124 @@ +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?)"}); + + IQueryable notificaciones = RepositorioNotificaciones.Singleton.ObtenerNotificacionesDeUsuario(cli.Dni) + .Where(x=>x.Leido == leido); + + + List noti = new(); + foreach (Notificacione i in notificaciones) { + if(i.DniclienteNavigation == null || i.DniremitenteNavigation==null) return BadRequest(new { message = "Esta mal cargado el precontrato"}); + var dto = new NotificacionDtoBuilder() + .SetRemitente(i.DniremitenteNavigation.Email??"") + .SetAccion(i.Accion??"") + .SetMensaje(i.Mensaje??"") + .SetFecha(i.Fecha) + .SetPropiedad(i.Idpropiedad.ToString()??"") + .SetReceptor(i.DniclienteNavigation.Email??"") + .Build(); + + noti.Add(dto); + } + + return Ok(noti); + } + + [HttpGet("api/notificaciones/haySinLeer")] + public IActionResult GetHayNotis([FromHeader(Name ="Auth")]string Auth) { + if (String.IsNullOrWhiteSpace(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?)"}); + + bool ret = RepositorioNotificaciones.Singleton.HayNotis(cli.Dni); + return Ok(new {message = ret}); + } + + [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(data.Remitente, Auth); + 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"}); + } + + [HttpPost("api/notificarInquilino")] + public IActionResult NotificarInq([FromHeader(Name ="Auth")]string Auth, [FromBody] AvisoInquilinoDto data) { + if (String.IsNullOrWhiteSpace(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false)return Unauthorized(); + + if (data.Mensaje == "") return BadRequest(new {message = "El campo Mensaje esta vacio"}); + if (data.Idpropiedad <= 0) return BadRequest(new {message = "La id de propiedad no puede ser 0 o menor"}); + + Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(data.Idpropiedad); + if (cont == null || cont.DniinquilinoNavigation == null || cont.DnipropietarioNavigation == null || cont.IdpropiedadNavigation == null) return BadRequest(new { message = "no hay un contrato por esa id"}); + + var n = new NotificacioneBuilder() + .SetAccion("Notificacion Inquilino") + .SetMensaje(data.Mensaje) + .SetLeido(false) + .SetDnicliente(cont.DniinquilinoNavigation.Dni) + .SetDniremitente(cont.DnipropietarioNavigation.Dni) + .SetIdpropiedad(cont.IdpropiedadNavigation.Id) + .SetFecha(DateTime.Now) + .Build(); + var ret = RepositorioNotificaciones.Singleton.AltaNotificacion(n); + return ret? + Ok(new { message = "se envio el aviso" }):BadRequest(new { message = "Fallo al intentar enviar el aviso" }); + } +} \ No newline at end of file diff --git a/Aspnet/Controllers/PermisosController.cs b/Aspnet/Controllers/PermisosController.cs index 3ec45df..a63f9a1 100644 --- a/Aspnet/Controllers/PermisosController.cs +++ b/Aspnet/Controllers/PermisosController.cs @@ -7,7 +7,11 @@ namespace AlquilaFacil.Controllers; [ApiController] public class PermisosController: ControllerBase { [HttpPost("api/admin/permisos")] - public IActionResult CrearPermisos([FromBody] AdminPermiso permiso) { + public IActionResult CrearPermisos([FromBody] AdminPermiso permiso, [FromHeader(Name = "Auth")] string Auth) { + if (!string.IsNullOrEmpty(Auth)) return BadRequest(); + var ret2 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 11); + if (ret2 == false) return BadRequest(ret2); + if (String.IsNullOrEmpty(permiso.descripcion)) return BadRequest(); bool ret = RepositorioPermisos.Singleton.CrearPermiso(permiso.descripcion); diff --git a/Aspnet/Controllers/PropiedadesController.cs b/Aspnet/Controllers/PropiedadesController.cs index b81634e..26f34b6 100644 --- a/Aspnet/Controllers/PropiedadesController.cs +++ b/Aspnet/Controllers/PropiedadesController.cs @@ -1,8 +1,258 @@ +using Entidades; +using Entidades.Dto; using Microsoft.AspNetCore.Mvc; +using Modelo; namespace AlquilaFacil.Controllers; [ApiController] public class PropiedadesController: ControllerBase { + [HttpGet("api/propiedades")] + public IActionResult ListarPropiedades([FromHeader(Name = "Auth")] string Auth, int pag = 0) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10); + if (validacion1 == false) validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2); + if (validacion1 == false) return Unauthorized(); -} \ No newline at end of file + IQueryable ret; + + if (pag == 0){ + ret = RepositorioPropiedades.Singleton.ListarPropiedades(); + } else{ + ret = RepositorioPropiedades.Singleton.ListarPropiedadesPorPagina(pag); + } + + return Ok(ret); + } + + [HttpGet("api/propiedad")] + public IActionResult ObtenerPropiedadPorId(int Id, [FromHeader(Name = "Auth")] string Auth) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10); + if (validacion1 == false) return Unauthorized(); + + if (Id < 0) return BadRequest(new {message ="la id de propiedad no puede ser negativa"}); + + var ret = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(Id); + if (ret == null) return BadRequest(new {message ="No existe la propiedad"}); + return Ok(ret); + } + + [HttpGet("api/propiedad/cantPagina")] + public IActionResult ObtenerCantidadDePaginas([FromHeader(Name = "Auth")] string Auth, int estado = 0) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10); + if (validacion1 == false) return Unauthorized(); + + if (estado < 0) return BadRequest(new {message = "No puede tener un numero menor a 0"}); + int cant; + + if(estado == 0){ + cant = RepositorioPropiedades.Singleton.CuantasPaginas(); + }else{ + cant = RepositorioPropiedades.Singleton.CuantasPaginas(estado); + } + + return Ok(new {message = cant}); + + } + + [HttpGet("api/propiedades/Propietario")] + public IActionResult ObtenerPropiedadesPorPropietario ( + [FromHeader(Name = "Email")] string email, + [FromHeader(Name = "Auth")] string Auth) { + + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2); + if (validacion1 == false) return Unauthorized(); + + email = email.Trim(); + if (String.IsNullOrEmpty(email)) return BadRequest(new {message ="falta campo email"}); + + IQueryable ret = RepositorioPropiedades.Singleton.ObtenerPropiedadesPorEmail(email); + return Ok(ret); + } + + [HttpGet("api/propiedades/Propietario/Bajas")] + public IActionResult ObtenerPropiedadesPorPropietarioBajas ( + [FromHeader(Name = "Email")] string email, + [FromHeader(Name = "Auth")] string Auth) { + + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 8); + if (validacion1 == false) return Unauthorized(); + + email = email.Trim(); + if (String.IsNullOrEmpty(email)) return BadRequest(new {message ="falta campo email"}); + + IQueryable ret = RepositorioPropiedades.Singleton.ObtenerPropiedadesDeBajaPorEmail(email); + return Ok(ret); + } + + [HttpPost("api/propiedad")] + public IActionResult AltaPropiedad([FromBody] AltaPropiedadDto 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{ + Canthabitaciones = propiedad.Canthabitaciones, + Dnipropietario = cli.Dni, + Idtipropiedad = propiedad.Idtipropiedad, + Ubicacion = propiedad.Ubicacion, + Letra = propiedad.Letra ?? null, + Piso = propiedad.Piso ?? null, + Monto = propiedad.Monto, + Iddivisa = propiedad.Iddivisa, + }; + + var ret = RepositorioPropiedades.Singleton.AñadirPropiedad(Prop); + return (ret)? + Ok(new { message = "Fue Cargado Correctamente"}) : + 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, 2); + 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"}); + + List servs = RepositorioServicios.Singleton.ObtenerServiciosPorDescripcion(propiedad.Servicios); + + 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, + IdServicios = servs, + Monto = propiedad.Monto, + Iddivisa = propiedad.Iddivisa, + }; + + 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(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2); + if (validacion1 == false) return Unauthorized(); + + if (String.IsNullOrEmpty(email)) return BadRequest(new { message = "Fallo al identificarse el usuario"}); + if (id <= 0) return BadRequest(new { message = "No es una id valida"}); + + Cliente? propie = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(email); + var ret = RepositorioPropiedades.Singleton.BajaPropiedad(id, propie); + + return ret ? + Ok(new { message = $"Se Cambio el estado de la propiedad con id {id}"}): + BadRequest(new {message="Fallo al cambiar el estado de la propiedad"}); + } + + [HttpPut("api/propiedades/addServicio")] + public IActionResult AñadirServicio([FromBody] ServicioAPropiedadDto Servicios, [FromHeader(Name = "Auth")] string Auth) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2); + if (validacion1 == false) return Unauthorized(); + + if (Servicios.propiedadid <= 0) return BadRequest(new {message ="No puede tener una id negativa o cero"}); + if (Servicios.idServicios.Count() < 1) return BadRequest(new {message ="Falta añadir servicios"}); + if (Servicios.idServicios.Any(x => x<= 0)) return BadRequest(new {message ="No tienen haber ids negativas o cero de servicio"}); + + var serv = RepositorioServicios.Singleton.ObtenerServiciosPorPropiedad(Servicios.propiedadid); + + bool validacion2 = Servicios.idServicios.Any(x => serv.Contains(x)); + + if (validacion2 == true) return BadRequest(new {message ="Hay elementos repetidos"}); + + bool ret = RepositorioPropiedades. + Singleton.AñadirServicioAPropiedad(Servicios.propiedadid, Servicios.idServicios); + + return ret ? + Ok(new {message ="Los Servicios Se Cargaron correctamente a la propiedad"}) : BadRequest(new {message ="No se pudo Cargar los Servicios a la propiedad"}); + + } + + [HttpPut("api/propiedades/RmServicio")] + public IActionResult EliminarServicio([FromBody] ServicioAPropiedadDto servicio, [FromHeader(Name = "Auth")] string Auth) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2); + if (validacion1 == false) return Unauthorized(); + + if (servicio.propiedadid <= 0) return BadRequest(new {message ="No puede tener una id negativa o cero"}); + if (servicio.idServicios.Count() < 1) return BadRequest(new {message ="Falta añadir servicios"}); + if (servicio.idServicios.Any(x => x<= 0)) return BadRequest(new {message ="No tienen haber ids negativas o cero de servicio"}); + + var serv = RepositorioServicios.Singleton.ObtenerServiciosPorPropiedad(servicio.propiedadid); + + var repetidos = serv.Intersect(servicio.idServicios); + + bool ret = RepositorioPropiedades.Singleton.BajaServiciosAPropiedad(servicio.propiedadid, servicio.idServicios); + + return ret ? + Ok(new {message ="Se Eliminaron los servicios seleccionados de la propiedad"}) : BadRequest(new {message ="Fallo al eliminarse los servicios de la propiedad"}); + + } + + private string ValidarPropiedad(AltaPropiedadDto prop) { + if (prop == null) return "Esta mal formado el body de la request"; + + 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\n"; + + if (String.IsNullOrEmpty(prop.Ubicacion)) ret += "Tiene que definir la ubicacion de la propiedad\n"; + + if (prop.Monto<=1) ret += "El monto tiene que ser como minimo mayor a 0"; + + if (prop.Iddivisa<0 || prop.Iddivisa>1) ret += "se tiene que elejir entre AR$ y US$"; + + 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\n"; + + 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\n"; + + if (String.IsNullOrEmpty(prop.Ubicacion)) ret += "Tiene que definir la ubicacion de la propiedad\n"; + + if (prop.Monto<=1) ret += "El monto tiene que ser como minimo mayor a 0"; + + if (prop.Iddivisa<0 || prop.Iddivisa>1) ret += "se tiene que elejir entre AR$ y US$"; + + return ret; + + } +} diff --git a/Aspnet/Controllers/PropietarioController.cs b/Aspnet/Controllers/PropietarioController.cs index 6b0d395..590e4da 100644 --- a/Aspnet/Controllers/PropietarioController.cs +++ b/Aspnet/Controllers/PropietarioController.cs @@ -2,6 +2,7 @@ using System.Security.Cryptography; using System.Text; using Entidades; using Entidades.Dto; +using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; using Modelo; @@ -11,14 +12,20 @@ namespace AlquilaFacil.Controllers; public class PropietarioController: ControllerBase { [HttpGet("api/propietario")] - public IActionResult ListarPropietarios([FromHeader(Name = "Auth")] string Auth) { - return Ok(); + public IActionResult ObtenerPropietarioPorDni(long Dni, [FromHeader(Name ="Auth")] string Auth) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 14); + if (validacion1 == false) return Unauthorized(); + + var ret = RepositorioPropietario.Singleton.ObtenerPropietarioPorDni(Dni); + return Ok(ret); } - [HttpPost("api/propietarios")] - public IActionResult AltaPropietario([FromBody]CrearClienteDto Propietario,[FromHeader(Name = "Auth")] string Auth) { + [HttpPost("api/propietario")] + public IActionResult AltaPropietario([FromBody]CrearClienteDto Propietario, + [FromHeader(Name = "Auth")] string Auth) { if (String.IsNullOrEmpty(Auth)) return Unauthorized(); - var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, Request.Path); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 5); if (validacion1 == false) return Unauthorized(); string validacion2 = verificarCrearUsuario(Propietario); @@ -38,6 +45,30 @@ public class PropietarioController: ControllerBase { return ret ? Ok(new {message = "Se añadio el propietario exitosamente"}) : BadRequest(); } + + [HttpPatch("api/propietarios")] + public IActionResult PatchPropietario([FromBody]CrearClienteDto Propietario, [FromHeader(Name = "Auth")] string Auth){ + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 5); + if (validacion1 == false) return Unauthorized(); + + string validacion2 = verificarCrearUsuario(Propietario); + if (validacion2 != "") return BadRequest(validacion2); + + var cli = new Cliente { + Dni = Propietario.dni, + Nombre = Propietario.nombre, + Domicilio = Propietario.domicilio, + Apellido = Propietario.apellido, + Celular = Propietario.celular, + Email = Propietario.email, + Contraseña = Encoding.UTF8.GetBytes(HacerHash(Propietario.contraseña)) + }; + var ret = RepositorioUsuarios.Singleton.ActualizarPropietario(cli); + return ret ? + Ok(new {message = "Se Modifico el propietario exitosamente"}) : BadRequest(); + } + private string verificarCrearUsuario(CrearClienteDto cid) { string msg = ""; diff --git a/Aspnet/Facade/DocumentoFacade.cs b/Aspnet/Facade/DocumentoFacade.cs new file mode 100644 index 0000000..71f3d64 --- /dev/null +++ b/Aspnet/Facade/DocumentoFacade.cs @@ -0,0 +1,24 @@ +using System.Runtime; +using System.Text; +using Entidades; +using Entidades.Dto; + +namespace AlquilaFacil.Facade; + +public class DocumentoFacade { + private readonly DocumentoGeneradorHtml d1 = new(); + private readonly DocumentoGeneradorPdf d2 = new(); + + public void GenerarHtml(ContratoDto cd, Recibo r, MemoryStream memoryStream) { + string str = d1.GenerarHTML(cd, r); + StreamWriter writer = new StreamWriter(memoryStream, Encoding.UTF8); + writer.WriteAsync(str).Wait(); + writer.FlushAsync().Wait(); + memoryStream.Position = 0; + } + public void GenerarPdf(ContratoDto cd, Recibo r, MemoryStream memoryStream) { + var mem = d2.GenerarPdf(cd, r); + mem.CopyToAsync(memoryStream).Wait(); + memoryStream.Position = 0; + } +} \ No newline at end of file diff --git a/Aspnet/Facade/DocumentoGeneradorHtml.cs b/Aspnet/Facade/DocumentoGeneradorHtml.cs new file mode 100644 index 0000000..f6ff529 --- /dev/null +++ b/Aspnet/Facade/DocumentoGeneradorHtml.cs @@ -0,0 +1,45 @@ +using Entidades; +using Entidades.Dto; +using Microsoft.AspNetCore.Routing.Template; + +namespace AlquilaFacil.Facade; +public class DocumentoGeneradorHtml { + public string GenerarHTML(ContratoDto cd, Recibo r) { + string tmpl =$""" + + + + + + +
+
+
+ AlquilaFácil +
+
+
Detalles
+

+ ID: {cd.id}
+ Ubicación: {cd.Ubicacion}
+ Tipo de Propiedad: {cd.TipoPropiedad}
+ Fecha de Inicio: {cd.Fechainicio}
+ Inquilino: {cd.Inquilino}
+ Propietario: {cd.Propietario}
+

+
+
Detalles del Recibo
+

+ ID del Recibo: {r.Id}
+ Fecha: {r.Fecha}
+ Monto: {r.Monto}
+

PAGO

+

+
+
+
+ + + """; return tmpl; + } + } diff --git a/Aspnet/Facade/DocumentoGeneradorPdf.cs b/Aspnet/Facade/DocumentoGeneradorPdf.cs new file mode 100644 index 0000000..e1e8279 --- /dev/null +++ b/Aspnet/Facade/DocumentoGeneradorPdf.cs @@ -0,0 +1,67 @@ +using Entidades; +using Entidades.Dto; +using QuestPDF.Fluent; +using QuestPDF.Helpers; +using QuestPDF.Infrastructure; +using System.IO; + +namespace AlquilaFacil.Facade; +public class DocumentoGeneradorPdf { + public MemoryStream GenerarPdf(ContratoDto cd, Recibo r) + { + var pdfStream = new MemoryStream(); + QuestPDF.Settings.License = LicenseType.Community; + Document.Create(container => + { + container.Page(page => + { + page.Size(PageSizes.A4); + page.Margin(2, Unit.Centimetre); + page.Header().Text("AlquilaFácil").FontSize(20).SemiBold().FontColor(Colors.White); + page.Content().Column(column => + { + column.Spacing(10); + + column.Item().Border(1).Padding(10).Column(card => + { + card.Item().Row(row => + { + row.RelativeItem().Text("Detalles").FontSize(16).SemiBold(); + }); + + card.Item().Column(body => + { + body.Spacing(5); + body.Item().Text($"ID: {cd.id}").FontSize(12).Bold(); + body.Item().Text($"Ubicación: {cd.Ubicacion}").FontSize(12); + body.Item().Text($"Tipo de Propiedad: {cd.TipoPropiedad}").FontSize(12); + body.Item().Text($"Fecha de Inicio: {cd.Fechainicio}").FontSize(12); + body.Item().Text($"Inquilino: {cd.Inquilino}").FontSize(12); + body.Item().Text($"Propietario: {cd.Propietario}").FontSize(12); + }); + }); + + column.Item().Border(1).Padding(10).Column(card => + { + card.Item().Row(row => + { + row.RelativeItem().Text("Detalles del Recibo").FontSize(16).SemiBold(); + }); + + card.Item().Column(body => + { + body.Spacing(5); + body.Item().Text($"ID del Recibo: {r.Id}").FontSize(12).Bold(); + body.Item().Text($"Fecha: {r.Fecha}").FontSize(12); + body.Item().Text($"Monto: {r.Monto}").FontSize(12); + body.Item().AlignCenter().Text("PAGO").FontSize(20).Bold(); + }); + }); + }); + }); + }).GeneratePdf(pdfStream); + + pdfStream.Position = 0; + return pdfStream; + } +} \ No newline at end of file diff --git a/Aspnet/Program.cs b/Aspnet/Program.cs index e83391e..4ad5df2 100644 --- a/Aspnet/Program.cs +++ b/Aspnet/Program.cs @@ -1,10 +1,29 @@ +using System.Text.Json; +using Minio; +using AlquilaFacil.Config; +using Microsoft.AspNetCore.Http.Features; + var builder = WebApplication.CreateBuilder(args); + +MinioConfigcus? mcon = JsonSerializer.Deserialize(File.ReadAllText("./settings.json"))?? null; +if (mcon == null) return; + // Add services to the container. builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +builder.Services.AddMinio(options => options + .WithCredentials(mcon.usr, mcon.scrt) + .WithEndpoint("192.168.1.11:9000") + .WithSSL(false) + .Build()); + +builder.Services.Configure(options => +{ + options.MultipartBodyLengthLimit = 50 * 1024 * 1024; // 50 MB +}); builder.Services.AddCors(options => { diff --git a/Aspnet/Strategy/Busqueda/BusquedaContext.cs b/Aspnet/Strategy/Busqueda/BusquedaContext.cs new file mode 100644 index 0000000..497272b --- /dev/null +++ b/Aspnet/Strategy/Busqueda/BusquedaContext.cs @@ -0,0 +1,29 @@ +namespace AlquilaFacil.StrategyBusqueda; + +public class BusquedaContext +{ + private static readonly BusquedaContext singleton = new(); + public static BusquedaContext Singleton {get { return singleton; } } + + private readonly Dictionary _estrategias; + + public BusquedaContext() + { + _estrategias = new Dictionary + { + { "000", new BusquedaSinParametros() }, + { "100", new BusquedaPorHabitaciones() }, + { "010", new BusquedaPorTipo() }, + { "001", new BusquedaPorServicios() }, + { "110", new BusquedaPorHabitacionesTipo() }, + { "101", new BusquedaPorHabitacionesServicios() }, + { "011", new BusquedaTipoServicios() }, + { "111", new BusquedaFull() } + }; + } + + public IBusquedaStrategy ObtenerEstrategia(string clave) + { + return _estrategias.ContainsKey(clave) ? _estrategias[clave] : new BusquedaSinParametros(); + } +} \ No newline at end of file diff --git a/Aspnet/Strategy/Busqueda/Filtros.cs b/Aspnet/Strategy/Busqueda/Filtros.cs new file mode 100644 index 0000000..e50c434 --- /dev/null +++ b/Aspnet/Strategy/Busqueda/Filtros.cs @@ -0,0 +1,52 @@ +using Entidades.Dto; +using Modelo; + +namespace AlquilaFacil.StrategyBusqueda; + +public class BusquedaSinParametros : IBusquedaStrategy { + public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad) { + return RepositorioPropiedades.Singleton.ListarPropiedades(); + } +} + +public class BusquedaPorHabitaciones : IBusquedaStrategy { + public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorHabitaciones(cantidadHabitaciones); + } +} + +public class BusquedaPorTipo : IBusquedaStrategy { + public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorTipo(tipoPropiedad); + } +} + +public class BusquedaPorServicios : IBusquedaStrategy { + public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorServicios(servicios); + } +} + +public class BusquedaPorHabitacionesTipo : IBusquedaStrategy { + public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorHabitaciones_Tipo(cantidadHabitaciones, tipoPropiedad); + } +} + +public class BusquedaPorHabitacionesServicios : IBusquedaStrategy { + public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorHabitaciones_Servicios(cantidadHabitaciones, servicios); + } +} + +public class BusquedaTipoServicios : IBusquedaStrategy { + public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorTipo_Servicios(tipoPropiedad, servicios); + } +} + +public class BusquedaFull : IBusquedaStrategy { + public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorHabitaciones_Tipo_Servicios(cantidadHabitaciones, tipoPropiedad, servicios); + } +} \ No newline at end of file diff --git a/Aspnet/Strategy/Busqueda/IBusquedaStrategy.cs b/Aspnet/Strategy/Busqueda/IBusquedaStrategy.cs new file mode 100644 index 0000000..4a3f411 --- /dev/null +++ b/Aspnet/Strategy/Busqueda/IBusquedaStrategy.cs @@ -0,0 +1,6 @@ +namespace AlquilaFacil.StrategyBusqueda; +using Entidades.Dto; +public interface IBusquedaStrategy { + IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad); +} + diff --git a/Aspnet/Strategy/BusquedaAdmin/AdminBusquedaContext.cs b/Aspnet/Strategy/BusquedaAdmin/AdminBusquedaContext.cs new file mode 100644 index 0000000..801557b --- /dev/null +++ b/Aspnet/Strategy/BusquedaAdmin/AdminBusquedaContext.cs @@ -0,0 +1,29 @@ +namespace AlquilaFacil.StrategyBusquedaAdmin; + +public class AdminBusquedaContext +{ + private static readonly AdminBusquedaContext singleton = new(); + public static AdminBusquedaContext Singleton {get { return singleton; } } + + private readonly Dictionary _estrategias; + + public AdminBusquedaContext() + { + _estrategias = new Dictionary + { + { "000", new BusquedaSinParametros() }, + { "100", new BusquedaPorHabitaciones() }, + { "010", new BusquedaPorTipo() }, + { "001", new BusquedaPorServicios() }, + { "110", new BusquedaPorHabitacionesTipo() }, + { "101", new BusquedaPorHabitacionesServicios() }, + { "011", new BusquedaTipoServicios() }, + { "111", new BusquedaFull() } + }; + } + + public IAdminBusquedaStrategy ObtenerEstrategia(string clave) + { + return _estrategias.ContainsKey(clave) ? _estrategias[clave] : new BusquedaSinParametros(); + } +} \ No newline at end of file diff --git a/Aspnet/Strategy/BusquedaAdmin/Filtros.cs b/Aspnet/Strategy/BusquedaAdmin/Filtros.cs new file mode 100644 index 0000000..8506bd9 --- /dev/null +++ b/Aspnet/Strategy/BusquedaAdmin/Filtros.cs @@ -0,0 +1,52 @@ +using Entidades.Admin; +using Modelo; + +namespace AlquilaFacil.StrategyBusquedaAdmin; + +public class BusquedaSinParametros : IAdminBusquedaStrategy { + public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad, int pag) { + return RepositorioPropiedades.Singleton.ListarPropiedadesPorPaginaAdmin(pag); + } +} + +public class BusquedaPorHabitaciones : IAdminBusquedaStrategy { +public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad, int pag) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorHabitacionesPaginado(cantidadHabitaciones, pag); + } +} + +public class BusquedaPorTipo : IAdminBusquedaStrategy { +public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad, int pag) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorTipoPaginado(tipoPropiedad, pag); + } +} + +public class BusquedaPorServicios : IAdminBusquedaStrategy { +public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad, int pag) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorServiciosPaginado(servicios, pag); + } +} + +public class BusquedaPorHabitacionesTipo : IAdminBusquedaStrategy { +public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad, int pag) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorHabitaciones_TipoPaginado(cantidadHabitaciones, tipoPropiedad, pag); + } +} + +public class BusquedaPorHabitacionesServicios : IAdminBusquedaStrategy { +public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad, int pag) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorHabitaciones_Servicios_Paginado(cantidadHabitaciones, servicios, pag); + } +} + +public class BusquedaTipoServicios : IAdminBusquedaStrategy { +public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad, int pag) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorTipo_Servicios_Paginado(tipoPropiedad, servicios, pag); + } +} + +public class BusquedaFull : IAdminBusquedaStrategy { +public IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad, int pag) { + return RepositorioPropiedades.Singleton.ObtenerPropiedesPorHabitaciones_Tipo_Servicios_Paginado(cantidadHabitaciones, tipoPropiedad, servicios, pag); + } +} \ No newline at end of file diff --git a/Aspnet/Strategy/BusquedaAdmin/IAdminBusquedaStrategy.cs b/Aspnet/Strategy/BusquedaAdmin/IAdminBusquedaStrategy.cs new file mode 100644 index 0000000..9151de7 --- /dev/null +++ b/Aspnet/Strategy/BusquedaAdmin/IAdminBusquedaStrategy.cs @@ -0,0 +1,6 @@ +namespace AlquilaFacil.StrategyBusquedaAdmin; +using Entidades.Admin; +public interface IAdminBusquedaStrategy { + IQueryable Filtrar(string servicios, int cantidadHabitaciones, int tipoPropiedad, int pag); +} + diff --git a/Aspnet/bin/Debug/net8.0/settings.json b/Aspnet/bin/Debug/net8.0/settings.json new file mode 100644 index 0000000..a595e0c --- /dev/null +++ b/Aspnet/bin/Debug/net8.0/settings.json @@ -0,0 +1,4 @@ +{ + "usr":"aVO9C3PqeK1hiPCyqZCj", + "scrt":"szj58kceWG3GcRZ8P1QCQiv5tSjMI7iD5zfjneTT" +} \ No newline at end of file diff --git a/Aspnet/makefile b/Aspnet/makefile index 46aa736..e528264 100644 --- a/Aspnet/makefile +++ b/Aspnet/makefile @@ -1,2 +1,2 @@ run: - dotnet watch run + dotnet watch run --project AlquilaFacil.csproj diff --git a/Aspnet/settings.json b/Aspnet/settings.json new file mode 100644 index 0000000..a595e0c --- /dev/null +++ b/Aspnet/settings.json @@ -0,0 +1,4 @@ +{ + "usr":"aVO9C3PqeK1hiPCyqZCj", + "scrt":"szj58kceWG3GcRZ8P1QCQiv5tSjMI7iD5zfjneTT" +} \ No newline at end of file diff --git a/Entidades/Admin/EmailGrupo.cs b/Entidades/Admin/EmailGrupo.cs new file mode 100644 index 0000000..3db517c --- /dev/null +++ b/Entidades/Admin/EmailGrupo.cs @@ -0,0 +1,2 @@ +namespace Entidades.Admin; +public record EmailGrupo(string email, string grupo); \ No newline at end of file diff --git a/Entidades/Admin/GrupoAdmin.cs b/Entidades/Admin/GrupoAdmin.cs new file mode 100644 index 0000000..a25dd9c --- /dev/null +++ b/Entidades/Admin/GrupoAdmin.cs @@ -0,0 +1,7 @@ +namespace Entidades.Admin; + +public class GrupoAdmin { + public int Id {get; set;} = 0; + public String Descripcion {get; set;} = ""; + public List Permisos {get; set;} = new(); +} \ No newline at end of file diff --git a/Entidades/Admin/PermisosAdmin.cs b/Entidades/Admin/PermisosAdmin.cs new file mode 100644 index 0000000..aba95e0 --- /dev/null +++ b/Entidades/Admin/PermisosAdmin.cs @@ -0,0 +1,6 @@ +namespace Entidades.Admin; + +public class PermisoAdmin { + public int Id {get; set;} + public String Descripcion {get; set;} = ""; +} \ No newline at end of file diff --git a/Entidades/Admin/PropiedadesAdmin.cs b/Entidades/Admin/PropiedadesAdmin.cs new file mode 100644 index 0000000..38149b7 --- /dev/null +++ b/Entidades/Admin/PropiedadesAdmin.cs @@ -0,0 +1,13 @@ +namespace Entidades.Admin; +public class PropiedadesAdmin { + public int id { get; set; } + public string Ubicacion { get; set; } = ""; + public int canthabitaciones { get; set; } + public int piso { get; set; } + public string letra { get; set; } = ""; + public string Tipo { get; set; } = ""; + public string? Servicios {get;set;} = ""; + public int Monto { get; set; } + public string Estado { get; set; } = ""; + public int Iddivisa { get; set; } +} diff --git a/Entidades/Admin/UsuarioAdmin.cs b/Entidades/Admin/UsuarioAdmin.cs new file mode 100644 index 0000000..6833961 --- /dev/null +++ b/Entidades/Admin/UsuarioAdmin.cs @@ -0,0 +1,8 @@ +namespace Entidades.Admin; + +public record UsuarioAdmin { + public long Dni { get; set; } = 0; + public string Nombre { get; set; } = ""; + public string Email { get; set; } = ""; + public ulong Habilitado { get; set; } +} \ No newline at end of file diff --git a/Entidades/Alquilafacilcontext.cs b/Entidades/Alquilafacilcontext.cs index a422bc2..afd29c8 100644 --- a/Entidades/Alquilafacilcontext.cs +++ b/Entidades/Alquilafacilcontext.cs @@ -23,6 +23,10 @@ public partial class AlquilaFacilContext : DbContext public virtual DbSet Defectos { get; set; } + public virtual DbSet Divisas { get; set; } + + public virtual DbSet EstadoPropiedads { get; set; } + public virtual DbSet Estadodefectos { get; set; } public virtual DbSet Estadoventas { get; set; } @@ -31,12 +35,16 @@ public partial class AlquilaFacilContext : DbContext public virtual DbSet Grupos { get; set; } + public virtual DbSet Notificaciones { get; set; } + public virtual DbSet Permisos { get; set; } public virtual DbSet Propiedades { get; set; } public virtual DbSet Recibos { get; set; } + public virtual DbSet Servicios { get; set; } + public virtual DbSet TipoPropiedads { get; set; } public virtual DbSet Ventas { get; set; } @@ -99,6 +107,10 @@ public partial class AlquilaFacilContext : DbContext entity.Property(e => e.Email) .HasMaxLength(50) .HasColumnName("email"); + entity.Property(e => e.Habilitado) + .HasDefaultValueSql("b'1'") + .HasColumnType("bit(1)") + .HasColumnName("habilitado"); entity.Property(e => e.Nombre) .HasMaxLength(20) .HasColumnName("nombre"); @@ -143,9 +155,14 @@ public partial class AlquilaFacilContext : DbContext entity.HasIndex(e => e.Idventa, "FK_CON_VEN"); + entity.HasIndex(e => e.Iddivisa, "FK_contdiv"); + entity.Property(e => e.Id) .HasColumnType("bigint(20)") .HasColumnName("id"); + entity.Property(e => e.Cancelado) + .HasColumnType("bit(1)") + .HasColumnName("cancelado"); entity.Property(e => e.Cantgarantemin) .HasColumnType("int(11)") .HasColumnName("cantgarantemin"); @@ -158,6 +175,12 @@ public partial class AlquilaFacilContext : DbContext entity.Property(e => e.Fechainicio) .HasColumnType("date") .HasColumnName("fechainicio"); + entity.Property(e => e.Habilitado) + .HasColumnType("bit(1)") + .HasColumnName("habilitado"); + entity.Property(e => e.Iddivisa) + .HasColumnType("int(11)") + .HasColumnName("iddivisa"); entity.Property(e => e.Idpropiedad) .HasColumnType("int(11)") .HasColumnName("idpropiedad"); @@ -167,12 +190,17 @@ public partial class AlquilaFacilContext : DbContext entity.Property(e => e.Indiceactualizacion) .HasPrecision(8) .HasColumnName("indiceactualizacion"); + entity.Property(e => e.MesesDurationContrato).HasColumnType("int(11)"); + entity.Property(e => e.MesesHastaAumento).HasColumnType("int(11)"); entity.Property(e => e.Monto) .HasPrecision(12) .HasColumnName("monto"); entity.Property(e => e.Tieneopcionventa) .HasColumnType("bit(1)") .HasColumnName("tieneopcionventa"); + entity.Property(e => e.UrlContrato) + .HasMaxLength(100) + .HasColumnName("urlContrato"); entity.HasOne(d => d.DniinquilinoNavigation).WithMany(p => p.ContratoDniinquilinoNavigations) .HasForeignKey(d => d.Dniinquilino) @@ -184,6 +212,11 @@ public partial class AlquilaFacilContext : DbContext .OnDelete(DeleteBehavior.Restrict) .HasConstraintName("FK_CON_PROPI"); + entity.HasOne(d => d.IddivisaNavigation).WithMany(p => p.Contratos) + .HasForeignKey(d => d.Iddivisa) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("FK_contdiv"); + entity.HasOne(d => d.IdpropiedadNavigation).WithMany(p => p.Contratos) .HasForeignKey(d => d.Idpropiedad) .OnDelete(DeleteBehavior.Restrict) @@ -229,6 +262,8 @@ public partial class AlquilaFacilContext : DbContext entity.HasIndex(e => e.Idestado, "FK_DEF_EST"); + entity.HasIndex(e => e.Iddivisa, "FK_defdiv"); + entity.Property(e => e.Id) .HasColumnType("bigint(20)") .HasColumnName("id"); @@ -236,11 +271,14 @@ public partial class AlquilaFacilContext : DbContext .HasPrecision(12) .HasColumnName("costo"); entity.Property(e => e.Descripcion) - .HasMaxLength(40) + .HasMaxLength(100) .HasColumnName("descripcion"); entity.Property(e => e.Idcontrato) .HasColumnType("bigint(20)") .HasColumnName("idcontrato"); + entity.Property(e => e.Iddivisa) + .HasColumnType("int(11)") + .HasColumnName("iddivisa"); entity.Property(e => e.Idestado) .HasColumnType("int(11)") .HasColumnName("idestado"); @@ -253,12 +291,43 @@ public partial class AlquilaFacilContext : DbContext .OnDelete(DeleteBehavior.Restrict) .HasConstraintName("FK_DEF_CON"); + entity.HasOne(d => d.IddivisaNavigation).WithMany(p => p.Defectos) + .HasForeignKey(d => d.Iddivisa) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("FK_defdiv"); + entity.HasOne(d => d.IdestadoNavigation).WithMany(p => p.Defectos) .HasForeignKey(d => d.Idestado) .OnDelete(DeleteBehavior.Restrict) .HasConstraintName("FK_DEF_EST"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PRIMARY"); + + entity.Property(e => e.Id) + .HasColumnType("int(11)") + .HasColumnName("id"); + entity.Property(e => e.Signo) + .HasMaxLength(3) + .HasColumnName("signo"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PRIMARY"); + + entity.ToTable("EstadoPropiedad"); + + entity.Property(e => e.Id) + .HasColumnType("int(11)") + .HasColumnName("id"); + entity.Property(e => e.Descripcion) + .HasMaxLength(11) + .HasColumnName("descripcion"); + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("PRIMARY"); @@ -287,17 +356,20 @@ public partial class AlquilaFacilContext : DbContext modelBuilder.Entity(entity => { - entity.HasKey(e => e.Dni).HasName("PRIMARY"); + entity.HasKey(e => e.Id).HasName("PRIMARY"); - entity.Property(e => e.Dni) - .HasColumnType("bigint(20)") - .HasColumnName("dni"); + entity.Property(e => e.Id) + .HasColumnType("int(11)") + .HasColumnName("id"); entity.Property(e => e.Apellido) .HasMaxLength(20) .HasColumnName("apellido"); entity.Property(e => e.Celular) .HasMaxLength(40) .HasColumnName("celular"); + entity.Property(e => e.Dni) + .HasColumnType("bigint(20)") + .HasColumnName("dni"); entity.Property(e => e.Domicilio) .HasMaxLength(40) .HasColumnName("domicilio"); @@ -308,7 +380,7 @@ public partial class AlquilaFacilContext : DbContext .HasMaxLength(20) .HasColumnName("nombre"); - entity.HasMany(d => d.Idcontratos).WithMany(p => p.Dnigarantes) + entity.HasMany(d => d.Idcontratos).WithMany(p => p.Idgarantes) .UsingEntity>( "ContratoGarante", r => r.HasOne().WithMany() @@ -316,17 +388,17 @@ public partial class AlquilaFacilContext : DbContext .OnDelete(DeleteBehavior.Restrict) .HasConstraintName("FK_CONGAR_CON"), l => l.HasOne().WithMany() - .HasForeignKey("Dnigarante") + .HasForeignKey("Idgarante") .OnDelete(DeleteBehavior.Restrict) .HasConstraintName("FK_CONGAR_GAR"), j => { - j.HasKey("Dnigarante", "Idcontrato").HasName("PRIMARY"); + j.HasKey("Idgarante", "Idcontrato").HasName("PRIMARY"); j.ToTable("contrato_garantes"); j.HasIndex(new[] { "Idcontrato" }, "FK_CONGAR_CON"); - j.IndexerProperty("Dnigarante") - .HasColumnType("bigint(20)") - .HasColumnName("dnigarante"); + j.IndexerProperty("Idgarante") + .HasColumnType("int(11)") + .HasColumnName("idgarante"); j.IndexerProperty("Idcontrato") .HasColumnType("bigint(20)") .HasColumnName("idcontrato"); @@ -345,6 +417,50 @@ public partial class AlquilaFacilContext : DbContext .HasColumnName("nombre"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.Dnicliente, e.Fecha }).HasName("PRIMARY"); + + entity.HasIndex(e => e.Idpropiedad, "FK_NOTPROP"); + + entity.HasIndex(e => e.Dniremitente, "FK_NOTREM"); + + entity.Property(e => e.Dnicliente) + .HasColumnType("bigint(20)") + .HasColumnName("dnicliente"); + entity.Property(e => e.Fecha) + .HasColumnType("datetime") + .HasColumnName("fecha"); + entity.Property(e => e.Accion) + .HasMaxLength(30) + .HasColumnName("accion"); + entity.Property(e => e.Dniremitente) + .HasColumnType("bigint(20)") + .HasColumnName("dniremitente"); + entity.Property(e => e.Idpropiedad) + .HasColumnType("int(11)") + .HasColumnName("idpropiedad"); + entity.Property(e => e.Leido).HasColumnName("leido"); + entity.Property(e => e.Mensaje) + .HasMaxLength(255) + .HasColumnName("mensaje"); + + entity.HasOne(d => d.DniclienteNavigation).WithMany(p => p.NotificacioneDniclienteNavigations) + .HasForeignKey(d => d.Dnicliente) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("FK_NOTCLI"); + + entity.HasOne(d => d.DniremitenteNavigation).WithMany(p => p.NotificacioneDniremitenteNavigations) + .HasForeignKey(d => d.Dniremitente) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("FK_NOTREM"); + + entity.HasOne(d => d.IdpropiedadNavigation).WithMany(p => p.Notificaciones) + .HasForeignKey(d => d.Idpropiedad) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("FK_NOTPROP"); + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("PRIMARY"); @@ -353,7 +469,7 @@ public partial class AlquilaFacilContext : DbContext .HasColumnType("int(11)") .HasColumnName("id"); entity.Property(e => e.Descripcion) - .HasMaxLength(15) + .HasMaxLength(25) .HasColumnName("descripcion"); entity.HasMany(d => d.Idgrupos).WithMany(p => p.Idpermisos) @@ -385,10 +501,14 @@ public partial class AlquilaFacilContext : DbContext { entity.HasKey(e => e.Id).HasName("PRIMARY"); + entity.HasIndex(e => e.Idestado, "FK_PROP_EST"); + entity.HasIndex(e => e.Dnipropietario, "FK_PROP_PROPI"); entity.HasIndex(e => e.Idtipropiedad, "FK_PROP_TIPO"); + entity.HasIndex(e => e.Iddivisa, "FK_propdiv"); + entity.Property(e => e.Id) .HasColumnType("int(11)") .HasColumnName("id"); @@ -398,6 +518,12 @@ public partial class AlquilaFacilContext : DbContext entity.Property(e => e.Dnipropietario) .HasColumnType("bigint(20)") .HasColumnName("dnipropietario"); + entity.Property(e => e.Iddivisa) + .HasColumnType("int(11)") + .HasColumnName("iddivisa"); + entity.Property(e => e.Idestado) + .HasColumnType("int(11)") + .HasColumnName("idestado"); entity.Property(e => e.Idtipropiedad) .HasColumnType("int(11)") .HasColumnName("idtipropiedad"); @@ -405,6 +531,9 @@ public partial class AlquilaFacilContext : DbContext .HasMaxLength(1) .IsFixedLength() .HasColumnName("letra"); + entity.Property(e => e.Monto) + .HasPrecision(10) + .HasColumnName("monto"); entity.Property(e => e.Piso) .HasColumnType("int(11)") .HasColumnName("piso"); @@ -417,6 +546,16 @@ public partial class AlquilaFacilContext : DbContext .OnDelete(DeleteBehavior.Restrict) .HasConstraintName("FK_PROP_PROPI"); + entity.HasOne(d => d.IddivisaNavigation).WithMany(p => p.Propiedades) + .HasForeignKey(d => d.Iddivisa) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("FK_propdiv"); + + entity.HasOne(d => d.IdestadoNavigation).WithMany(p => p.Propiedades) + .HasForeignKey(d => d.Idestado) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("FK_PROP_EST"); + entity.HasOne(d => d.IdtipropiedadNavigation).WithMany(p => p.Propiedades) .HasForeignKey(d => d.Idtipropiedad) .OnDelete(DeleteBehavior.Restrict) @@ -440,6 +579,42 @@ public partial class AlquilaFacilContext : DbContext .HasColumnName("monto"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PRIMARY"); + + entity.Property(e => e.Id) + .HasColumnType("int(11)") + .HasColumnName("id"); + entity.Property(e => e.Descripcion) + .HasMaxLength(20) + .HasColumnName("descripcion"); + + entity.HasMany(d => d.IdPropiedads).WithMany(p => p.IdServicios) + .UsingEntity>( + "ServicioPropiedad", + r => r.HasOne().WithMany() + .HasForeignKey("IdPropiedad") + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("Servicio_Propiedad_ibfk_2"), + l => l.HasOne().WithMany() + .HasForeignKey("IdServicio") + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("Servicio_Propiedad_ibfk_1"), + j => + { + j.HasKey("IdServicio", "IdPropiedad").HasName("PRIMARY"); + j.ToTable("Servicio_Propiedad"); + j.HasIndex(new[] { "IdPropiedad" }, "idPropiedad"); + j.IndexerProperty("IdServicio") + .HasColumnType("int(11)") + .HasColumnName("idServicio"); + j.IndexerProperty("IdPropiedad") + .HasColumnType("int(11)") + .HasColumnName("idPropiedad"); + }); + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("PRIMARY"); @@ -466,6 +641,8 @@ public partial class AlquilaFacilContext : DbContext entity.HasIndex(e => e.Idpropiedad, "FK_VEN_PROP"); + entity.HasIndex(e => e.Iddivisa, "FK_ventdiv"); + entity.Property(e => e.Id) .HasColumnType("bigint(20)") .HasColumnName("id"); @@ -481,6 +658,9 @@ public partial class AlquilaFacilContext : DbContext entity.Property(e => e.IdVendedor) .HasColumnType("bigint(20)") .HasColumnName("idVendedor"); + entity.Property(e => e.Iddivisa) + .HasColumnType("int(11)") + .HasColumnName("iddivisa"); entity.Property(e => e.Idestado) .HasColumnType("int(11)") .HasColumnName("idestado"); @@ -501,6 +681,11 @@ public partial class AlquilaFacilContext : DbContext .OnDelete(DeleteBehavior.Restrict) .HasConstraintName("FK_VEN_PROL"); + entity.HasOne(d => d.IddivisaNavigation).WithMany(p => p.Venta) + .HasForeignKey(d => d.Iddivisa) + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("FK_ventdiv"); + entity.HasOne(d => d.IdestadoNavigation).WithMany(p => p.Venta) .HasForeignKey(d => d.Idestado) .OnDelete(DeleteBehavior.Restrict) diff --git a/Entidades/Cliente.cs b/Entidades/Cliente.cs index e4a2b2d..9f69cbb 100644 --- a/Entidades/Cliente.cs +++ b/Entidades/Cliente.cs @@ -21,10 +21,16 @@ public partial class Cliente public string? Token { get; set; } + public ulong Habilitado { get; set; } + public virtual ICollection ContratoDniinquilinoNavigations { get; set; } = new List(); public virtual ICollection ContratoDnipropietarioNavigations { get; set; } = new List(); + public virtual ICollection NotificacioneDniclienteNavigations { get; set; } = new List(); + + public virtual ICollection NotificacioneDniremitenteNavigations { get; set; } = new List(); + public virtual ICollection Propiedades { get; set; } = new List(); public virtual ICollection VentaIdCompradorNavigations { get; set; } = new List(); diff --git a/Entidades/Contrato.cs b/Entidades/Contrato.cs index c7fd30f..bf539d2 100644 --- a/Entidades/Contrato.cs +++ b/Entidades/Contrato.cs @@ -25,17 +25,31 @@ public partial class Contrato public long? Idventa { get; set; } + public ulong Habilitado { get; set; } + + public int MesesHastaAumento { get; set; } + + public string? UrlContrato { get; set; } + + public ulong Cancelado { get; set; } + + public int Iddivisa { get; set; } + + public int MesesDurationContrato { get; set; } + public virtual ICollection Defectos { get; set; } = new List(); public virtual Cliente? DniinquilinoNavigation { get; set; } public virtual Cliente? DnipropietarioNavigation { get; set; } + public virtual Divisa IddivisaNavigation { get; set; } = null!; + public virtual Propiedade? IdpropiedadNavigation { get; set; } public virtual Venta? IdventaNavigation { get; set; } - public virtual ICollection Dnigarantes { get; set; } = new List(); - public virtual ICollection Idcanons { get; set; } = new List(); + + public virtual ICollection Idgarantes { get; set; } = new List(); } diff --git a/Entidades/Defecto.cs b/Entidades/Defecto.cs index 1147a55..6cc2269 100644 --- a/Entidades/Defecto.cs +++ b/Entidades/Defecto.cs @@ -17,7 +17,11 @@ public partial class Defecto public ulong Pagainquilino { get; set; } + public int Iddivisa { get; set; } + public virtual Contrato? IdcontratoNavigation { get; set; } + public virtual Divisa IddivisaNavigation { get; set; } = null!; + public virtual Estadodefecto? IdestadoNavigation { get; set; } } diff --git a/Entidades/Divisa.cs b/Entidades/Divisa.cs new file mode 100644 index 0000000..f9a5cb1 --- /dev/null +++ b/Entidades/Divisa.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace Entidades; + +public partial class Divisa +{ + public int Id { get; set; } + + public string Signo { get; set; } = null!; + + public virtual ICollection Contratos { get; set; } = new List(); + + public virtual ICollection Defectos { get; set; } = new List(); + + public virtual ICollection Propiedades { get; set; } = new List(); + + public virtual ICollection Venta { get; set; } = new List(); +} diff --git a/Entidades/Dto/AccionesDeGrupo.cs b/Entidades/Dto/AccionesDeGrupo.cs new file mode 100644 index 0000000..a3e4b29 --- /dev/null +++ b/Entidades/Dto/AccionesDeGrupo.cs @@ -0,0 +1,2 @@ +namespace Entidades.Dto; +public record AccionesPorGrupoDto(string Email, string Grupo); \ No newline at end of file diff --git a/Entidades/Dto/AceptarContratoDto.cs b/Entidades/Dto/AceptarContratoDto.cs new file mode 100644 index 0000000..35ba502 --- /dev/null +++ b/Entidades/Dto/AceptarContratoDto.cs @@ -0,0 +1,5 @@ +namespace Entidades.Dto; +public class AceptarContratoDto { + public long Idcontrato { get; set; } + public DateTime Fecha { get; set; } +} \ No newline at end of file diff --git a/Entidades/Dto/AltaDefectoDto.cs b/Entidades/Dto/AltaDefectoDto.cs new file mode 100644 index 0000000..c8105ac --- /dev/null +++ b/Entidades/Dto/AltaDefectoDto.cs @@ -0,0 +1,8 @@ +namespace Entidades.Dto; +public class AltaDefectoDto { + public string Descripcion { get; set; } =""; + public Decimal Costo { get; set; } + public ulong Pagainquilino { get; set; } + public int Iddivisa { get; set; } + public long Idcontrato { get; set; } +} \ No newline at end of file diff --git a/Entidades/Dto/AltaGarantesDto.cs b/Entidades/Dto/AltaGarantesDto.cs new file mode 100644 index 0000000..c1971b9 --- /dev/null +++ b/Entidades/Dto/AltaGarantesDto.cs @@ -0,0 +1,9 @@ +namespace Entidades.Dto; + +public class AltaGarantesDto { + public string EmailInquilino { get; set; } = ""; + public int Idpropiedad {get; set;} + public DateTime fecha { get; set;} + public List garantes{ get; set; } = new(); + +} \ 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/AltaPropiedadDto.cs b/Entidades/Dto/AltaPropiedadDto.cs new file mode 100644 index 0000000..8517bd2 --- /dev/null +++ b/Entidades/Dto/AltaPropiedadDto.cs @@ -0,0 +1,11 @@ +namespace Entidades.Dto; +public class AltaPropiedadDto { + public string Ubicacion { get; set; } = null!; + public int Canthabitaciones { get; set; } + public int? Piso { get; set; } = null; + public string? Letra { get; set; } = null; + public string Email { get; set; } = string.Empty; + public int Idtipropiedad { get; set; } + public int Monto { get; set; } + public int Iddivisa { get; set; } +} \ No newline at end of file diff --git a/Entidades/Dto/AvisoInquilinoDto.cs b/Entidades/Dto/AvisoInquilinoDto.cs new file mode 100644 index 0000000..eb5b886 --- /dev/null +++ b/Entidades/Dto/AvisoInquilinoDto.cs @@ -0,0 +1,5 @@ +namespace Entidades.Dto; +public class AvisoInquilinoDto { + public string Mensaje { get; set; } =""; + public long Idpropiedad { get; set; } +} \ No newline at end of file diff --git a/Entidades/Dto/BusquedaDto.cs b/Entidades/Dto/BusquedaDto.cs new file mode 100644 index 0000000..bae05d0 --- /dev/null +++ b/Entidades/Dto/BusquedaDto.cs @@ -0,0 +1,3 @@ +namespace Entidades.Dto; + +public record BusquedaDto(int Id, string Ubicacion, string? Servicios = ""); diff --git a/Entidades/Dto/CancelarPrecontratoDto.cs b/Entidades/Dto/CancelarPrecontratoDto.cs new file mode 100644 index 0000000..3372b09 --- /dev/null +++ b/Entidades/Dto/CancelarPrecontratoDto.cs @@ -0,0 +1,8 @@ +namespace Entidades.Dto; +public class CancelarPrecontratoDto { + public string EmailPropietario { get; set; } =""; + public string EmailInquilino { get; set; } =""; + public DateTime fecha { get; set; } + + public int idpropiedad { get; set; } = 0; +} \ No newline at end of file diff --git a/Entidades/Dto/CanonDto.cs b/Entidades/Dto/CanonDto.cs new file mode 100644 index 0000000..21f7f59 --- /dev/null +++ b/Entidades/Dto/CanonDto.cs @@ -0,0 +1,10 @@ +namespace Entidades.Dto; +public class CanonDto{ + public long Id { get; set;} + public int MesNum { get; set;} + public DateTime Mes { get; set;} + public Decimal Monto { get; set;} + public string Divisa { get; set;} = ""; + public bool Pago { get; set;} + +} \ No newline at end of file diff --git a/Entidades/Dto/Chart/Chartjs.cs b/Entidades/Dto/Chart/Chartjs.cs new file mode 100644 index 0000000..c208dd5 --- /dev/null +++ b/Entidades/Dto/Chart/Chartjs.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; + +public class ChartData +{ + [JsonPropertyName("labels")] + public List Labels { get; set; }=new(); + + [JsonPropertyName("datasets")] + public List Datasets { get; set; }=new(); +} + +public class Dataset +{ + [JsonPropertyName("label")] + public string Label { get; set; } =""; + + [JsonPropertyName("data")] + public List Data { get; set; }= new(); + + [JsonPropertyName("borderWidth")] + public int BorderWidth { get; set; }=1; +} diff --git a/Entidades/Dto/ContratoDto.cs b/Entidades/Dto/ContratoDto.cs new file mode 100644 index 0000000..5cd9cac --- /dev/null +++ b/Entidades/Dto/ContratoDto.cs @@ -0,0 +1,11 @@ +namespace Entidades.Dto; +public class ContratoDto { + public long id { get; set; } + public string Ubicacion { get; set; }=""; + public string TipoPropiedad { get; set; }=""; + public DateTime Fechainicio { get; set; } + public string Inquilino { get; set; }=""; + public string Propietario { get; set; }=""; + public string Estado {get; set;}=""; + +} \ No newline at end of file diff --git a/Entidades/Dto/ContratoPropiedadDto.cs b/Entidades/Dto/ContratoPropiedadDto.cs new file mode 100644 index 0000000..e19e368 --- /dev/null +++ b/Entidades/Dto/ContratoPropiedadDto.cs @@ -0,0 +1,8 @@ +namespace Entidades.Dto; +public class ContratoPropiedadDto : ContratoDto { + public int Habitaciones { get; set; } + public int Piso { get; set;} + public string Letra { get; set; } = ""; + public int MesesAumento { get; set; } + public int MesesDuracion { get; set; } +} \ No newline at end of file diff --git a/Entidades/Dto/CrearCanonsDto.cs b/Entidades/Dto/CrearCanonsDto.cs new file mode 100644 index 0000000..6d2fabc --- /dev/null +++ b/Entidades/Dto/CrearCanonsDto.cs @@ -0,0 +1,6 @@ +namespace Entidades.Dto; + +public class CrearCanonsDto { + public long idcontrato{ get; set; } + public decimal aumento{ get; set; } +} \ No newline at end of file diff --git a/Entidades/Dto/DefectoDto.cs b/Entidades/Dto/DefectoDto.cs new file mode 100644 index 0000000..d28ea26 --- /dev/null +++ b/Entidades/Dto/DefectoDto.cs @@ -0,0 +1,10 @@ +namespace Entidades.Dto; +public class DefectoDto { + public long Id { get; set;} + public string Descripcion { get; set;} =""; + public Decimal Costo { get; set;} + public string Estado { get; set;} =""; + public long Idcontrato { get; set;} + public string Pagainquilino { get; set;} =""; + public string Divisa { get; set;} =""; +} \ No newline at end of file diff --git a/Entidades/Dto/GaranteDto.cs b/Entidades/Dto/GaranteDto.cs new file mode 100644 index 0000000..736473e --- /dev/null +++ b/Entidades/Dto/GaranteDto.cs @@ -0,0 +1,16 @@ +namespace Entidades.Dto; + +public class GaranteDto { + public long Dni { get; set; } + + public string Nombre { get; set; } = null!; + + public string Apellido { get; set; } = null!; + + public string Domicilio { get; set; } = null!; + + public string Celular { get; set; } = null!; + + public string Domiciliolaboral { get; set; } = null!; + +} \ No newline at end of file diff --git a/Entidades/Dto/MarcarPagoDto.cs b/Entidades/Dto/MarcarPagoDto.cs new file mode 100644 index 0000000..789fd6e --- /dev/null +++ b/Entidades/Dto/MarcarPagoDto.cs @@ -0,0 +1,6 @@ +namespace Entidades.Dto; +public class MarcarPagoDto { + public long Idcontrato { get; set; } + public DateTime fecha { 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..9daa73e --- /dev/null +++ b/Entidades/Dto/NotificacionDto.cs @@ -0,0 +1,9 @@ +namespace Entidades.Dto; +public class NotificacionDto { + public string Remitente { get; set; } =""; + public string Accion { get; set; } =""; + public string Receptor { 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/Entidades/Dto/PatchPropiedadDto.cs b/Entidades/Dto/PatchPropiedadDto.cs new file mode 100644 index 0000000..3c2ec20 --- /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, List Servicios, int Monto, int Iddivisa); diff --git a/Entidades/Dto/PrecontratoDto.cs b/Entidades/Dto/PrecontratoDto.cs new file mode 100644 index 0000000..650e075 --- /dev/null +++ b/Entidades/Dto/PrecontratoDto.cs @@ -0,0 +1,11 @@ +namespace Entidades.Dto; +public class PrecontratoDto { + public string EmailInquilino { get; set; } = ""; + public string EmailPropietario { get; set; } = ""; + public int IdPropiedad { get; set; } + public int CantidadGarantes { get; set; } + public int MesesHastaAumento { get; set; } + public bool TieneOpcionVenta { get; set; } + public string fechaprimernotificacion { get; set; } = ""; + public int MesesDuracionContrato { get; set; } +} \ No newline at end of file diff --git a/Entidades/Dto/PropiedadesDto.cs b/Entidades/Dto/PropiedadesDto.cs new file mode 100644 index 0000000..d5e2c13 --- /dev/null +++ b/Entidades/Dto/PropiedadesDto.cs @@ -0,0 +1,12 @@ +namespace Entidades.Dto; +public class PropiedadesDto { + public int id { get; set; } + public string Ubicacion { get; set; } = ""; + public int canthabitaciones { get; set; } + public int piso { get; set; } + public string letra { get; set; } = ""; + public string Tipo { get; set; } = ""; + public string? Servicios {get;set;} = ""; + public int Monto { get; set; } + public int Iddivisa { get; set; } +} diff --git a/Entidades/Dto/RechazarContratoDto.cs b/Entidades/Dto/RechazarContratoDto.cs new file mode 100644 index 0000000..6e735fb --- /dev/null +++ b/Entidades/Dto/RechazarContratoDto.cs @@ -0,0 +1,5 @@ +namespace Entidades.Dto; +public class RechazarPreContrato { + public long Idcontrato { get; set; } + public DateTime Fecha { get; set; } +} \ No newline at end of file diff --git a/Entidades/Dto/ServicioAPropiedadDto.cs b/Entidades/Dto/ServicioAPropiedadDto.cs new file mode 100644 index 0000000..79cd5ab --- /dev/null +++ b/Entidades/Dto/ServicioAPropiedadDto.cs @@ -0,0 +1,2 @@ +namespace Entidades.Dto; +public record ServicioAPropiedadDto(int propiedadid, List idServicios); \ No newline at end of file diff --git a/Entidades/Dto/SubirContratoDto.cs b/Entidades/Dto/SubirContratoDto.cs new file mode 100644 index 0000000..adb224b --- /dev/null +++ b/Entidades/Dto/SubirContratoDto.cs @@ -0,0 +1,6 @@ +using System.Configuration; + +namespace Entidades.Dto; +public class SubirContratoDto{ + public int IdContrato { get; set; } +} diff --git a/Entidades/Estadopropiedad.cs b/Entidades/Estadopropiedad.cs new file mode 100644 index 0000000..a220579 --- /dev/null +++ b/Entidades/Estadopropiedad.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace Entidades; + +public partial class EstadoPropiedad +{ + public int Id { get; set; } + + public string Descripcion { get; set; } = null!; + + public virtual ICollection Propiedades { get; set; } = new List(); +} diff --git a/Entidades/Garante.cs b/Entidades/Garante.cs index d95318b..39359d1 100644 --- a/Entidades/Garante.cs +++ b/Entidades/Garante.cs @@ -5,6 +5,8 @@ namespace Entidades; public partial class Garante { + public int Id { get; set; } + public long Dni { get; set; } public string Nombre { get; set; } = null!; diff --git a/Entidades/Grupo.cs b/Entidades/Grupo.cs index 8a1a624..420bc05 100644 --- a/Entidades/Grupo.cs +++ b/Entidades/Grupo.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace Entidades; @@ -9,6 +10,7 @@ public partial class Grupo public string Nombre { get; set; } = null!; + [JsonIgnore] public virtual ICollection Idclientes { get; set; } = new List(); public virtual ICollection Idpermisos { get; set; } = new List(); diff --git a/Entidades/Informes/InfomesAlquiler.cs b/Entidades/Informes/InfomesAlquiler.cs new file mode 100644 index 0000000..a5900ff --- /dev/null +++ b/Entidades/Informes/InfomesAlquiler.cs @@ -0,0 +1,6 @@ +namespace Entidades.Informes; +public class InformesAlquiler { + public long Id { get; set; } + public string Ubicacion { get; set; }=""; + public string Divisa { get; set; }=""; +} \ No newline at end of file diff --git a/Entidades/Informes/InformeMeses.cs b/Entidades/Informes/InformeMeses.cs new file mode 100644 index 0000000..7442417 --- /dev/null +++ b/Entidades/Informes/InformeMeses.cs @@ -0,0 +1,17 @@ +namespace Entidades.Informes; +public class InformesMeses { + public int Meses { get; set; } + public int Repes{ get; set; } + public string Semaforizacion {get { + switch(Repes.CompareTo(2)){ + case 1: + return "🟢"; + case 0: + return "🟡"; + case -1: + return "🔴"; + default: + return ""; + } + }} +} \ No newline at end of file diff --git a/Entidades/Notificacione.cs b/Entidades/Notificacione.cs new file mode 100644 index 0000000..d44a5f4 --- /dev/null +++ b/Entidades/Notificacione.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; + +namespace Entidades; + +public partial class Notificacione +{ + public long Dnicliente { get; set; } + + public long Dniremitente { get; set; } + + public DateTime Fecha { get; set; } + + public string Mensaje { get; set; } = null!; + + public string Accion { get; set; } = null!; + + public int Idpropiedad { get; set; } + + public bool Leido { get; set; } + + public virtual Cliente DniclienteNavigation { get; set; } = null!; + + public virtual Cliente DniremitenteNavigation { get; set; } = null!; + + public virtual Propiedade IdpropiedadNavigation { get; set; } = null!; +} diff --git a/Entidades/Permiso.cs b/Entidades/Permiso.cs index ffaa3cb..e8da1b5 100644 --- a/Entidades/Permiso.cs +++ b/Entidades/Permiso.cs @@ -8,7 +8,7 @@ public partial class Permiso { public int Id { get; set; } - public string? Descripcion { get; set; } + public string Descripcion { get; set; } = null!; [JsonIgnore] public virtual ICollection Idgrupos { get; set; } = new List(); diff --git a/Entidades/Propiedade.cs b/Entidades/Propiedade.cs index d0abc4f..268fa3d 100644 --- a/Entidades/Propiedade.cs +++ b/Entidades/Propiedade.cs @@ -19,11 +19,25 @@ public partial class Propiedade public int Idtipropiedad { get; set; } + public int? Idestado { get; set; } + + public decimal Monto { get; set; } + + public int Iddivisa { get; set; } + public virtual ICollection Contratos { get; set; } = new List(); public virtual Cliente? DnipropietarioNavigation { get; set; } + public virtual Divisa IddivisaNavigation { get; set; } = null!; + + public virtual EstadoPropiedad? IdestadoNavigation { get; set; } + public virtual TipoPropiedad IdtipropiedadNavigation { get; set; } = null!; + public virtual ICollection Notificaciones { get; set; } = new List(); + public virtual ICollection Venta { get; set; } = new List(); + + public virtual ICollection IdServicios { get; set; } = new List(); } diff --git a/Entidades/Servicio.cs b/Entidades/Servicio.cs new file mode 100644 index 0000000..b0246e0 --- /dev/null +++ b/Entidades/Servicio.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Entidades; + +public partial class Servicio +{ + public int Id { get; set; } + + public string Descripcion { get; set; } = null!; + + [JsonIgnore] + public virtual ICollection IdPropiedads { get; set; } = new List(); +} diff --git a/Entidades/Venta.cs b/Entidades/Venta.cs index 4620380..200b45c 100644 --- a/Entidades/Venta.cs +++ b/Entidades/Venta.cs @@ -21,12 +21,16 @@ public partial class Venta public DateTime? Fechafinal { get; set; } + public int Iddivisa { get; set; } + public virtual ICollection Contratos { get; set; } = new List(); public virtual Cliente? IdCompradorNavigation { get; set; } public virtual Cliente? IdVendedorNavigation { get; set; } + public virtual Divisa IddivisaNavigation { get; set; } = null!; + public virtual Estadoventa? IdestadoNavigation { get; set; } public virtual Propiedade? IdpropiedadNavigation { get; set; } diff --git a/Front/.prettierrc b/Front/.prettierrc new file mode 100644 index 0000000..5a938ce --- /dev/null +++ b/Front/.prettierrc @@ -0,0 +1,4 @@ +{ + "tabWidth": 4, + "useTabs": false +} diff --git a/Front/bun.lockb b/Front/bun.lockb index 14f40ba..dba69aa 100755 Binary files a/Front/bun.lockb and b/Front/bun.lockb differ diff --git a/Front/index.html b/Front/index.html index 9df6701..89c9c3f 100644 --- a/Front/index.html +++ b/Front/index.html @@ -2,10 +2,15 @@ - + - + + AlquilaFacil diff --git a/Front/package-lock.json b/Front/package-lock.json new file mode 100644 index 0000000..44b5093 --- /dev/null +++ b/Front/package-lock.json @@ -0,0 +1,723 @@ +{ + "name": "front", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "front", + "version": "0.0.0", + "dependencies": { + "@sveltejs/kit": "^2.7.3", + "@sveltestrap/sveltestrap": "^6.2.7", + "chartjs": "^0.3.24", + "svelte-routing": "^2.13.0" + }, + "devDependencies": { + "@sveltejs/vite-plugin-svelte": "^4.0.0", + "@tsconfig/svelte": "^5.0.4", + "prettier": "^3.4.2", + "prettier-plugin-svelte": "^3.3.3", + "svelte": "^5.0.0", + "svelte-check": "^4.0.5", + "tslib": "^2.8.0", + "typescript": "^5.6.3", + "vite": "^5.4.10" + } + }, + "node_modules/@ampproject/remapping": { + "version": "2.3.0", + "license": "Apache-2.0", + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.24" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.21.5", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.5", + "license": "MIT", + "dependencies": { + "@jridgewell/set-array": "^1.2.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.24" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/set-array": { + "version": "1.2.1", + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.0", + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.25", + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@polka/url": { + "version": "1.0.0-next.28", + "license": "MIT" + }, + "node_modules/@popperjs/core": { + "version": "2.11.8", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/popperjs" + } + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.24.0", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.24.0", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@sveltejs/kit": { + "version": "2.7.3", + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "@types/cookie": "^0.6.0", + "cookie": "^0.6.0", + "devalue": "^5.1.0", + "esm-env": "^1.0.0", + "import-meta-resolve": "^4.1.0", + "kleur": "^4.1.5", + "magic-string": "^0.30.5", + "mrmime": "^2.0.0", + "sade": "^1.8.1", + "set-cookie-parser": "^2.6.0", + "sirv": "^3.0.0", + "tiny-glob": "^0.2.9" + }, + "bin": { + "svelte-kit": "svelte-kit.js" + }, + "engines": { + "node": ">=18.13" + }, + "peerDependencies": { + "@sveltejs/vite-plugin-svelte": "^3.0.0 || ^4.0.0-next.1", + "svelte": "^4.0.0 || ^5.0.0-next.0", + "vite": "^5.0.3" + } + }, + "node_modules/@sveltejs/vite-plugin-svelte": { + "version": "4.0.0", + "license": "MIT", + "dependencies": { + "@sveltejs/vite-plugin-svelte-inspector": "^3.0.0-next.0||^3.0.0", + "debug": "^4.3.7", + "deepmerge": "^4.3.1", + "kleur": "^4.1.5", + "magic-string": "^0.30.12", + "vitefu": "^1.0.3" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22" + }, + "peerDependencies": { + "svelte": "^5.0.0-next.96 || ^5.0.0", + "vite": "^5.0.0" + } + }, + "node_modules/@sveltejs/vite-plugin-svelte-inspector": { + "version": "3.0.1", + "license": "MIT", + "dependencies": { + "debug": "^4.3.7" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22" + }, + "peerDependencies": { + "@sveltejs/vite-plugin-svelte": "^4.0.0-next.0||^4.0.0", + "svelte": "^5.0.0-next.96 || ^5.0.0", + "vite": "^5.0.0" + } + }, + "node_modules/@sveltestrap/sveltestrap": { + "version": "6.2.7", + "license": "MIT", + "dependencies": { + "@popperjs/core": "^2.11.8" + }, + "peerDependencies": { + "svelte": "^4.0.0 || ^5.0.0 || ^5.0.0-next.0" + } + }, + "node_modules/@tsconfig/svelte": { + "version": "5.0.4", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/cookie": { + "version": "0.6.0", + "license": "MIT" + }, + "node_modules/@types/estree": { + "version": "1.0.6", + "license": "MIT" + }, + "node_modules/acorn": { + "version": "8.12.1", + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-typescript": { + "version": "1.4.13", + "license": "MIT", + "peerDependencies": { + "acorn": ">=8.9.0" + } + }, + "node_modules/aria-query": { + "version": "5.3.2", + "license": "Apache-2.0", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/axobject-query": { + "version": "4.1.0", + "license": "Apache-2.0", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/chartjs": { + "version": "0.3.24", + "license": "MIT" + }, + "node_modules/chokidar": { + "version": "4.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "readdirp": "^4.0.1" + }, + "engines": { + "node": ">= 14.16.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/cookie": { + "version": "0.6.0", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/debug": { + "version": "4.3.7", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/deepmerge": { + "version": "4.3.1", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/devalue": { + "version": "5.1.1", + "license": "MIT" + }, + "node_modules/esbuild": { + "version": "0.21.5", + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.21.5", + "@esbuild/android-arm": "0.21.5", + "@esbuild/android-arm64": "0.21.5", + "@esbuild/android-x64": "0.21.5", + "@esbuild/darwin-arm64": "0.21.5", + "@esbuild/darwin-x64": "0.21.5", + "@esbuild/freebsd-arm64": "0.21.5", + "@esbuild/freebsd-x64": "0.21.5", + "@esbuild/linux-arm": "0.21.5", + "@esbuild/linux-arm64": "0.21.5", + "@esbuild/linux-ia32": "0.21.5", + "@esbuild/linux-loong64": "0.21.5", + "@esbuild/linux-mips64el": "0.21.5", + "@esbuild/linux-ppc64": "0.21.5", + "@esbuild/linux-riscv64": "0.21.5", + "@esbuild/linux-s390x": "0.21.5", + "@esbuild/linux-x64": "0.21.5", + "@esbuild/netbsd-x64": "0.21.5", + "@esbuild/openbsd-x64": "0.21.5", + "@esbuild/sunos-x64": "0.21.5", + "@esbuild/win32-arm64": "0.21.5", + "@esbuild/win32-ia32": "0.21.5", + "@esbuild/win32-x64": "0.21.5" + } + }, + "node_modules/esm-env": { + "version": "1.0.0", + "license": "MIT" + }, + "node_modules/esrap": { + "version": "1.2.2", + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.4.15", + "@types/estree": "^1.0.1" + } + }, + "node_modules/fdir": { + "version": "6.4.0", + "dev": true, + "license": "MIT", + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/globalyzer": { + "version": "0.1.0", + "license": "MIT" + }, + "node_modules/globrex": { + "version": "0.1.2", + "license": "MIT" + }, + "node_modules/import-meta-resolve": { + "version": "4.1.0", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/is-reference": { + "version": "3.0.2", + "license": "MIT", + "dependencies": { + "@types/estree": "*" + } + }, + "node_modules/kleur": { + "version": "4.1.5", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/locate-character": { + "version": "3.0.0", + "license": "MIT" + }, + "node_modules/magic-string": { + "version": "0.30.12", + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0" + } + }, + "node_modules/mri": { + "version": "1.2.0", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/mrmime": { + "version": "2.0.0", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "license": "MIT" + }, + "node_modules/nanoid": { + "version": "3.3.7", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/picocolors": { + "version": "1.1.0", + "license": "ISC" + }, + "node_modules/postcss": { + "version": "8.4.47", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.7", + "picocolors": "^1.1.0", + "source-map-js": "^1.2.1" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/prettier": { + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", + "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/prettier-plugin-svelte": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier-plugin-svelte/-/prettier-plugin-svelte-3.3.3.tgz", + "integrity": "sha512-yViK9zqQ+H2qZD1w/bH7W8i+bVfKrD8GIFjkFe4Thl6kCT9SlAsXVNmt3jCvQOCsnOhcvYgsoVlRV/Eu6x5nNw==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "prettier": "^3.0.0", + "svelte": "^3.2.0 || ^4.0.0-next.0 || ^5.0.0-next.0" + } + }, + "node_modules/readdirp": { + "version": "4.0.2", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14.16.0" + }, + "funding": { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/rollup": { + "version": "4.24.0", + "license": "MIT", + "dependencies": { + "@types/estree": "1.0.6" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.24.0", + "@rollup/rollup-android-arm64": "4.24.0", + "@rollup/rollup-darwin-arm64": "4.24.0", + "@rollup/rollup-darwin-x64": "4.24.0", + "@rollup/rollup-linux-arm-gnueabihf": "4.24.0", + "@rollup/rollup-linux-arm-musleabihf": "4.24.0", + "@rollup/rollup-linux-arm64-gnu": "4.24.0", + "@rollup/rollup-linux-arm64-musl": "4.24.0", + "@rollup/rollup-linux-powerpc64le-gnu": "4.24.0", + "@rollup/rollup-linux-riscv64-gnu": "4.24.0", + "@rollup/rollup-linux-s390x-gnu": "4.24.0", + "@rollup/rollup-linux-x64-gnu": "4.24.0", + "@rollup/rollup-linux-x64-musl": "4.24.0", + "@rollup/rollup-win32-arm64-msvc": "4.24.0", + "@rollup/rollup-win32-ia32-msvc": "4.24.0", + "@rollup/rollup-win32-x64-msvc": "4.24.0", + "fsevents": "~2.3.2" + } + }, + "node_modules/sade": { + "version": "1.8.1", + "license": "MIT", + "dependencies": { + "mri": "^1.1.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/set-cookie-parser": { + "version": "2.7.0", + "license": "MIT" + }, + "node_modules/sirv": { + "version": "3.0.0", + "license": "MIT", + "dependencies": { + "@polka/url": "^1.0.0-next.24", + "mrmime": "^2.0.0", + "totalist": "^3.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/source-map-js": { + "version": "1.2.1", + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/svelte": { + "version": "5.1.9", + "license": "MIT", + "dependencies": { + "@ampproject/remapping": "^2.3.0", + "@jridgewell/sourcemap-codec": "^1.5.0", + "@types/estree": "^1.0.5", + "acorn": "^8.12.1", + "acorn-typescript": "^1.4.13", + "aria-query": "^5.3.1", + "axobject-query": "^4.1.0", + "esm-env": "^1.0.0", + "esrap": "^1.2.2", + "is-reference": "^3.0.2", + "locate-character": "^3.0.0", + "magic-string": "^0.30.11", + "zimmerframe": "^1.1.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/svelte-check": { + "version": "4.0.5", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "^0.3.25", + "chokidar": "^4.0.1", + "fdir": "^6.2.0", + "picocolors": "^1.0.0", + "sade": "^1.7.4" + }, + "bin": { + "svelte-check": "bin/svelte-check" + }, + "engines": { + "node": ">= 18.0.0" + }, + "peerDependencies": { + "svelte": "^4.0.0 || ^5.0.0-next.0", + "typescript": ">=5.0.0" + } + }, + "node_modules/svelte-routing": { + "version": "2.13.0", + "license": "MIT" + }, + "node_modules/tiny-glob": { + "version": "0.2.9", + "license": "MIT", + "dependencies": { + "globalyzer": "0.1.0", + "globrex": "^0.1.2" + } + }, + "node_modules/totalist": { + "version": "3.0.1", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/tslib": { + "version": "2.8.0", + "dev": true, + "license": "0BSD" + }, + "node_modules/typescript": { + "version": "5.6.3", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/vite": { + "version": "5.4.10", + "license": "MIT", + "dependencies": { + "esbuild": "^0.21.3", + "postcss": "^8.4.43", + "rollup": "^4.20.0" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^18.0.0 || >=20.0.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^18.0.0 || >=20.0.0", + "less": "*", + "lightningcss": "^1.21.0", + "sass": "*", + "sass-embedded": "*", + "stylus": "*", + "sugarss": "*", + "terser": "^5.4.0" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "less": { + "optional": true + }, + "lightningcss": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + } + } + }, + "node_modules/vitefu": { + "version": "1.0.3", + "license": "MIT", + "workspaces": [ + "tests/deps/*", + "tests/projects/*" + ], + "peerDependencies": { + "vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0-beta.0" + }, + "peerDependenciesMeta": { + "vite": { + "optional": true + } + } + }, + "node_modules/zimmerframe": { + "version": "1.1.2", + "license": "MIT" + } + } +} diff --git a/Front/package.json b/Front/package.json index 6a4b9fc..6f2b870 100644 --- a/Front/package.json +++ b/Front/package.json @@ -12,6 +12,8 @@ "devDependencies": { "@sveltejs/vite-plugin-svelte": "^4.0.0", "@tsconfig/svelte": "^5.0.4", + "prettier": "^3.4.2", + "prettier-plugin-svelte": "^3.3.3", "svelte": "^5.0.0", "svelte-check": "^4.0.5", "tslib": "^2.8.0", @@ -21,6 +23,8 @@ "dependencies": { "@sveltejs/kit": "^2.7.3", "@sveltestrap/sveltestrap": "^6.2.7", + "chartjs": "^0.3.24", + "svelte-chartjs": "^3.1.5", "svelte-routing": "^2.13.0" } } diff --git a/Front/public/bell.svg b/Front/public/bell.svg new file mode 100644 index 0000000..8a1f51e --- /dev/null +++ b/Front/public/bell.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Front/public/favicon.png b/Front/public/favicon.png deleted file mode 100644 index bc2d027..0000000 Binary files a/Front/public/favicon.png and /dev/null differ diff --git a/Front/public/favicon.svg b/Front/public/favicon.svg new file mode 100644 index 0000000..fbd876d --- /dev/null +++ b/Front/public/favicon.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Front/public/toggle-left.svg b/Front/public/toggle-left.svg new file mode 100644 index 0000000..9f7d915 --- /dev/null +++ b/Front/public/toggle-left.svg @@ -0,0 +1,14 @@ + + + + + diff --git a/Front/public/toggle-right.svg b/Front/public/toggle-right.svg new file mode 100644 index 0000000..28a184b --- /dev/null +++ b/Front/public/toggle-right.svg @@ -0,0 +1,14 @@ + + + + + diff --git a/Front/public/zoom.svg b/Front/public/zoom.svg new file mode 100644 index 0000000..6371d03 --- /dev/null +++ b/Front/public/zoom.svg @@ -0,0 +1,19 @@ + + + + + diff --git a/Front/src/App.svelte b/Front/src/App.svelte index 2f9e3d0..8575022 100644 --- a/Front/src/App.svelte +++ b/Front/src/App.svelte @@ -1,33 +1,128 @@ - + + - - + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Front/src/Componentes/AdminPanelBusqueda.svelte b/Front/src/Componentes/AdminPanelBusqueda.svelte new file mode 100644 index 0000000..ef212a4 --- /dev/null +++ b/Front/src/Componentes/AdminPanelBusqueda.svelte @@ -0,0 +1,86 @@ + + +
+ +
Busqueda Filtrada +
+
+ +
+ + +
+ +
+
Servicios
+ {#each servicios as servicio} +
+ + +
+ {/each} +
+ +
+ + +
+ + +
+ \ No newline at end of file diff --git a/Front/src/Componentes/AdminPropiedad.svelte b/Front/src/Componentes/AdminPropiedad.svelte new file mode 100644 index 0000000..bb1ce56 --- /dev/null +++ b/Front/src/Componentes/AdminPropiedad.svelte @@ -0,0 +1,65 @@ + + +
+
+
{prop.tipo}
+
+
+
+ +
+
{prop.ubicacion}
+

+ Habitaciones: {prop.canthabitaciones}
+ Piso: {prop.piso || "N/A"}
+ Letra: {prop.letra || "N/A"}
+ Servicios: {prop.servicios || "Sin servicios especificados"}
+ Monto: + {#if prop.iddivisa == 0} + AR$ + {:else} + US$ + {/if} + {prop.monto}
+ Estado: {prop.estado}
+

+ {#if prop.estado == "Disponible"} + + {:else} + + {/if} +
+ +
+ \ No newline at end of file diff --git a/Front/src/lib/BarraHorizontalConTexto.svelte b/Front/src/Componentes/BarraHorizontalConTexto.svelte similarity index 60% rename from Front/src/lib/BarraHorizontalConTexto.svelte rename to Front/src/Componentes/BarraHorizontalConTexto.svelte index 6a48406..82a7aba 100644 --- a/Front/src/lib/BarraHorizontalConTexto.svelte +++ b/Front/src/Componentes/BarraHorizontalConTexto.svelte @@ -1,11 +1,11 @@

-
{prop.text}
+
{text}

\ No newline at end of file diff --git a/Front/src/Componentes/BotonVolverArriba.svelte b/Front/src/Componentes/BotonVolverArriba.svelte new file mode 100644 index 0000000..3c576ad --- /dev/null +++ b/Front/src/Componentes/BotonVolverArriba.svelte @@ -0,0 +1,14 @@ + + + diff --git a/Front/src/Componentes/Estadisticas/fChart.svelte b/Front/src/Componentes/Estadisticas/fChart.svelte new file mode 100644 index 0000000..a57ec3c --- /dev/null +++ b/Front/src/Componentes/Estadisticas/fChart.svelte @@ -0,0 +1,59 @@ + + +
+ +
+ diff --git a/Front/src/Componentes/FormAltaDefecto.svelte b/Front/src/Componentes/FormAltaDefecto.svelte new file mode 100644 index 0000000..2cf9067 --- /dev/null +++ b/Front/src/Componentes/FormAltaDefecto.svelte @@ -0,0 +1,94 @@ + + +
+
+
+ + + + {n}/100 + +
+ + +
+ $ + +
+ +
+
+ + +
+
+ + +
+
+ +
+ + +
+ + +
+
diff --git a/Front/src/lib/FormPostCli.svelte b/Front/src/Componentes/FormPostCli.svelte similarity index 91% rename from Front/src/lib/FormPostCli.svelte rename to Front/src/Componentes/FormPostCli.svelte index fa1c309..fb0b05e 100644 --- a/Front/src/lib/FormPostCli.svelte +++ b/Front/src/Componentes/FormPostCli.svelte @@ -18,16 +18,24 @@ let domicilio: string = $state("") let celular: string = $state("") + const token = sessionStorage.getItem("token"); + async function submitForm(event: any) { event.preventDefault(); try { let response = await fetch(url, { method: 'POST', headers: { + 'Auth' : String(token), 'Content-Type' : 'application/json', }, body: JSON.stringify({dni, nombre, apellido, domicilio, celular, email, contraseña}) }); + if (response.ok){ + const errorData = await response.json(); + errorMessage = errorData.message; + showAlert = true; + } if (!response.ok) { const errorData = await response.json(); errorMessage = errorData.message; diff --git a/Front/src/Componentes/ListaAcciones.svelte b/Front/src/Componentes/ListaAcciones.svelte new file mode 100644 index 0000000..c5674d3 --- /dev/null +++ b/Front/src/Componentes/ListaAcciones.svelte @@ -0,0 +1,53 @@ + + +
+ {#each $permisos as item} + + {item.descripcion} + + {/each} +
diff --git a/Front/src/lib/login.svelte b/Front/src/Componentes/LoginPanel.svelte similarity index 86% rename from Front/src/lib/login.svelte rename to Front/src/Componentes/LoginPanel.svelte index a98a8f3..9de9755 100644 --- a/Front/src/lib/login.svelte +++ b/Front/src/Componentes/LoginPanel.svelte @@ -1,11 +1,11 @@ - + Iniciar Sesión diff --git a/Front/src/Componentes/ModalAddGarantes.svelte b/Front/src/Componentes/ModalAddGarantes.svelte new file mode 100644 index 0000000..ca0e721 --- /dev/null +++ b/Front/src/Componentes/ModalAddGarantes.svelte @@ -0,0 +1,165 @@ + + + diff --git a/Front/src/Componentes/ModalCheckYContrato.svelte b/Front/src/Componentes/ModalCheckYContrato.svelte new file mode 100644 index 0000000..b46a5b3 --- /dev/null +++ b/Front/src/Componentes/ModalCheckYContrato.svelte @@ -0,0 +1,107 @@ + + + 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/ModalEstatico.svelte b/Front/src/Componentes/ModalEstatico.svelte new file mode 100644 index 0000000..03f801d --- /dev/null +++ b/Front/src/Componentes/ModalEstatico.svelte @@ -0,0 +1,18 @@ + + +
+ + {#if iscomponent == false} + {payload} + {:else} + {@render payload()} + {/if} + +
diff --git a/Front/src/Componentes/ModalNotificacion.svelte b/Front/src/Componentes/ModalNotificacion.svelte new file mode 100644 index 0000000..3c1ca23 --- /dev/null +++ b/Front/src/Componentes/ModalNotificacion.svelte @@ -0,0 +1,56 @@ + + + + diff --git a/Front/src/Componentes/ModalPedirDoc.svelte b/Front/src/Componentes/ModalPedirDoc.svelte new file mode 100644 index 0000000..1615f74 --- /dev/null +++ b/Front/src/Componentes/ModalPedirDoc.svelte @@ -0,0 +1,44 @@ + + + + \ No newline at end of file diff --git a/Front/src/Componentes/ModalPrecontrato.svelte b/Front/src/Componentes/ModalPrecontrato.svelte new file mode 100644 index 0000000..6f04d38 --- /dev/null +++ b/Front/src/Componentes/ModalPrecontrato.svelte @@ -0,0 +1,54 @@ + + + \ No newline at end of file diff --git a/Front/src/Componentes/ModalVeryAceptarContrato.svelte b/Front/src/Componentes/ModalVeryAceptarContrato.svelte new file mode 100644 index 0000000..92cbbd4 --- /dev/null +++ b/Front/src/Componentes/ModalVeryAceptarContrato.svelte @@ -0,0 +1,95 @@ + + + + + \ No newline at end of file diff --git a/Front/src/Componentes/NavBarAutocompletable.svelte b/Front/src/Componentes/NavBarAutocompletable.svelte new file mode 100644 index 0000000..2ef9085 --- /dev/null +++ b/Front/src/Componentes/NavBarAutocompletable.svelte @@ -0,0 +1,126 @@ + + + + + AlquilaFacil + +
+
+ + Volver al Menú + +
+ + +
+ (isOpen = !isOpen)} /> + + + +
diff --git a/Front/src/lib/NavBarLogin.svelte b/Front/src/Componentes/NavBarLogin.svelte similarity index 55% rename from Front/src/lib/NavBarLogin.svelte rename to Front/src/Componentes/NavBarLogin.svelte index 556024e..59c245f 100644 --- a/Front/src/lib/NavBarLogin.svelte +++ b/Front/src/Componentes/NavBarLogin.svelte @@ -2,7 +2,12 @@ import { Navbar, NavbarBrand, NavbarToggler, NavItem, Nav, NavLink, Collapse } from "@sveltestrap/sveltestrap"; let isOpen:boolean = false; - + let theme = $state(localStorage.getItem("theme") ?? "light"); + const toggleTheme = () => { + theme = theme === "light" ? "dark" : "light"; + document.body.setAttribute("data-bs-theme", theme); + localStorage.setItem("theme", theme); + }; @@ -10,6 +15,15 @@ AlquilaFacil +
+ +
(isOpen = !isOpen)} />