From 08e672aff447b760a8d619ea167e0fc51b925083 Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Thu, 19 Mar 2020 07:59:49 -0700 Subject: [PATCH] Scaffold alert models and controller. --- Server/API/AlertsController.cs | 39 ++++++++++++++++++++++++++++++++++ Shared/Models/Alert.cs | 18 ++++++++++++++++ Shared/Models/AlertOptions.cs | 23 ++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 Server/API/AlertsController.cs create mode 100644 Shared/Models/Alert.cs create mode 100644 Shared/Models/AlertOptions.cs diff --git a/Server/API/AlertsController.cs b/Server/API/AlertsController.cs new file mode 100644 index 00000000..81594d09 --- /dev/null +++ b/Server/API/AlertsController.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Mvc; +using Remotely.Server.Auth; +using Remotely.Shared.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Remotely.Server.API +{ + [Route("api/[controller]")] + [ApiController] + [ServiceFilter(typeof(ApiAuthorizationFilter))] + public class AlertsController : ControllerBase + { + [HttpPost("Create")] + public async Task Create(AlertOptions alertOptions) + { + Request.Headers.TryGetValue("OrganizationID", out var orgID); + + if (alertOptions.ShouldAlert) + { + var alert = new Alert() + { + CreatedOn = DateTimeOffset.Now, + DeviceID = alertOptions.AlertDeviceID, + Message = alertOptions.AlertMessage + }; + // TODO: Add alert. + } + + // TODO: Email. + + // TODO: API request. + + return Ok(); + } + } +} diff --git a/Shared/Models/Alert.cs b/Shared/Models/Alert.cs new file mode 100644 index 00000000..384dbb12 --- /dev/null +++ b/Shared/Models/Alert.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace Remotely.Shared.Models +{ + public class Alert + { + [Key] + public string ID { get; set; } = Guid.NewGuid().ToString(); + public DateTimeOffset CreatedOn { get; set; } = DateTimeOffset.Now; + public Device Device { get; set; } + public string DeviceID { get; set; } + public string Message { get; set; } + public ICollection SeenBy { get; set; } + } +} diff --git a/Shared/Models/AlertOptions.cs b/Shared/Models/AlertOptions.cs new file mode 100644 index 00000000..57af5749 --- /dev/null +++ b/Shared/Models/AlertOptions.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; + +namespace Remotely.Shared.Models +{ + public class AlertOptions + { + public string AlertDeviceID { get; set; } + public string AlertMessage { get; set; } + public string ApiRequestBody { get; set; } + public Dictionary ApiRequestHeaders { get; set; } + public string ApiRequestMethod { get; set; } + public string ApiRequestUrl { get; set; } + public string EmailBody { get; set; } + public string EmailSubject { get; set; } + public string EmailTo { get; set; } + public bool ShouldAlert { get; set; } + public bool ShouldEmail { get; set; } + public bool ShouldSendApiRequest { get; set; } + } +}