eliminado checkgrupos en notificaciones controller
This commit is contained in:
@@ -7,79 +7,85 @@ using Modelo;
|
||||
namespace AlquilaFacil.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class NotificacionesController: ControllerBase {
|
||||
public class NotificacionesController : ControllerBase
|
||||
{
|
||||
[HttpGet("api/notificaciones")]
|
||||
public IActionResult GetNotificaciones([FromHeader(Name ="Auth")]string Auth, bool leido = false) {
|
||||
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?)"});
|
||||
|
||||
if (cli == null) return BadRequest(new { message = "Fallo al intentar encontrar tu usuario (puede que te hayas logeado desde otro dispositivo?)" });
|
||||
|
||||
IQueryable<Notificacione> notificaciones = RepositorioNotificaciones.Singleton.ObtenerNotificacionesDeUsuario(cli.Dni)
|
||||
.Where(x=>x.Leido == leido);
|
||||
|
||||
|
||||
.Where(x => x.Leido == leido);
|
||||
|
||||
|
||||
List<NotificacionDto> noti = new();
|
||||
foreach (Notificacione i in notificaciones) {
|
||||
if(i.DniclienteNavigation == null || i.DniremitenteNavigation==null) return BadRequest(new { message = "Esta mal cargado el precontrato"});
|
||||
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??"")
|
||||
.SetRemitente(i.DniremitenteNavigation.Email ?? "")
|
||||
.SetAccion(i.Accion ?? "")
|
||||
.SetMensaje(i.Mensaje ?? "")
|
||||
.SetFecha(i.Fecha)
|
||||
.SetPropiedad(i.Idpropiedad.ToString()??"")
|
||||
.SetReceptor(i.DniclienteNavigation.Email??"")
|
||||
.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) {
|
||||
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?)"});
|
||||
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});
|
||||
return Ok(new { message = ret });
|
||||
}
|
||||
|
||||
[HttpPut("api/notificaciones")]
|
||||
public IActionResult MarcarComoLeido([FromHeader(Name = "Auth")]string Auth, NotificacionMarcarLeidoDto nota) {
|
||||
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"});
|
||||
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 == 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" });
|
||||
|
||||
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"});
|
||||
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) {
|
||||
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 (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"});
|
||||
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 ????"});
|
||||
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)
|
||||
@@ -90,23 +96,24 @@ public class NotificacionesController: ControllerBase {
|
||||
.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"});
|
||||
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) {
|
||||
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"});
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 12);
|
||||
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"});
|
||||
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")
|
||||
@@ -118,41 +125,42 @@ public class NotificacionesController: ControllerBase {
|
||||
.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" });
|
||||
return ret ?
|
||||
Ok(new { message = "se envio el aviso" }) : BadRequest(new { message = "Fallo al intentar enviar el aviso" });
|
||||
}
|
||||
|
||||
[HttpPost("api/notificar/ConsultaCompra")]
|
||||
public IActionResult EnviarConsultaCompra([FromHeader(Name ="Auth")]string Auth, AltaNotificacionDto dto) {
|
||||
public IActionResult EnviarConsultaCompra([FromHeader(Name = "Auth")] string Auth, AltaNotificacionDto dto)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 16);
|
||||
if (validacion1 == false)
|
||||
{
|
||||
|
||||
return Unauthorized();
|
||||
|
||||
}
|
||||
|
||||
if (dto.Accion == "") return BadRequest(new{message = "El campo Accion esta vacio"});
|
||||
if (dto.Mensaje == "") return BadRequest(new {message = "El campo Mensaje esta vacio"});
|
||||
if (dto.Accion == "") return BadRequest(new { message = "El campo Accion esta vacio" });
|
||||
if (dto.Mensaje == "") return BadRequest(new { message = "El campo Mensaje esta vacio" });
|
||||
|
||||
Cliente?cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
|
||||
Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(dto.Propiedad);
|
||||
if (prop == null) return BadRequest(new { message = "No hay una propiedad con id 0 o menor"});
|
||||
if (prop == null) return BadRequest(new { message = "No hay una propiedad con id 0 o menor" });
|
||||
|
||||
var n = new NotificacioneBuilder()
|
||||
.SetAccion("Consulta Compra")
|
||||
.SetMensaje(dto.Mensaje)
|
||||
.SetLeido(false)
|
||||
.SetDnicliente(prop.Dnipropietario??0)
|
||||
.SetDnicliente(prop.Dnipropietario ?? 0)
|
||||
.SetDniremitente(cli.Dni)
|
||||
.SetIdpropiedad(prop.Id)
|
||||
.SetFecha(DateTime.Now)
|
||||
.Build();
|
||||
var ret2= RepositorioNotificaciones.Singleton.AltaNotificacion(n, cli.Dni);
|
||||
return ret2?
|
||||
Ok(new { message = "se envio el aviso" }):BadRequest(new { message = "Fallo al intentar enviar el aviso" });
|
||||
var ret2 = RepositorioNotificaciones.Singleton.AltaNotificacion(n, cli.Dni);
|
||||
return ret2 ?
|
||||
Ok(new { message = "se envio el aviso" }) : BadRequest(new { message = "Fallo al intentar enviar el aviso" });
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user