mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Scaffold alert models and controller.
This commit is contained in:
parent
521534f433
commit
08e672aff4
39
Server/API/AlertsController.cs
Normal file
39
Server/API/AlertsController.cs
Normal 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
18
Shared/Models/Alert.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
23
Shared/Models/AlertOptions.cs
Normal file
23
Shared/Models/AlertOptions.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user