Scaffold alert models and controller.

This commit is contained in:
Jared Goodwin 2020-03-19 07:59:49 -07:00
parent 521534f433
commit 08e672aff4
3 changed files with 80 additions and 0 deletions

View File

@ -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<IActionResult> 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();
}
}
}

18
Shared/Models/Alert.cs Normal file
View File

@ -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<RemotelyUser> SeenBy { get; set; }
}
}

View File

@ -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<string, string> 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; }
}
}