Fixes all request Records with Validations
This commit is contained in:
2025-09-17 23:59:26 +02:00
parent cf4ed8d61b
commit 55fb37d62b
7 changed files with 55 additions and 45 deletions

View File

@@ -89,11 +89,15 @@ public class NotificationConnectorController(NotificationsContext context) : Con
public async Task<Results<Created<string>, InternalServerError<string>>> CreateGotifyConnector ([FromBody]CreateGotifyConnectorRecord createGotifyConnectorData)
{
//TODO Validate Data
CreateNotificationConnectorRecord gotifyConnector = new (createGotifyConnectorData.Name,
createGotifyConnectorData.Url,
"POST",
$"{{\"message\": \"%text\", \"title\": \"%title\", \"Priority\": {createGotifyConnectorData.Priority}}}",
new () { { "X-Gotify-Key", createGotifyConnectorData.AppToken } });
CreateNotificationConnectorRecord gotifyConnector = new ()
{
Name = createGotifyConnectorData.Name,
Url = createGotifyConnectorData.Url,
HttpMethod = "POST",
Body =
$"{{\"message\": \"%text\", \"title\": \"%title\", \"Priority\": {createGotifyConnectorData.Priority}}}",
Headers = new() { { "X-Gotify-Key", createGotifyConnectorData.AppToken } }
};
return await CreateConnector(gotifyConnector);
}
@@ -112,11 +116,14 @@ public class NotificationConnectorController(NotificationsContext context) : Con
string authHeader = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{createNtfyConnectorRecord.Username}:{createNtfyConnectorRecord.Password}"));
string auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(authHeader)).Replace("=","");
CreateNotificationConnectorRecord ntfyConnector = new (createNtfyConnectorRecord.Name,
$"{createNtfyConnectorRecord.Url}?auth={auth}",
"POST",
$"{{\"message\": \"%text\", \"title\": \"%title\", \"Priority\": {createNtfyConnectorRecord.Priority} \"Topic\": \"{createNtfyConnectorRecord.Topic}\"}}",
new () {{"Authorization", auth}});
CreateNotificationConnectorRecord ntfyConnector = new ()
{
Name = createNtfyConnectorRecord.Name,
Url = $"{createNtfyConnectorRecord.Url}?auth={auth}",
HttpMethod = "POST",
Body = $"{{\"message\": \"%text\", \"title\": \"%title\", \"Priority\": {createNtfyConnectorRecord.Priority} \"Topic\": \"{createNtfyConnectorRecord.Topic}\"}}",
Headers = new () {{"Authorization", auth}}
};
return await CreateConnector(ntfyConnector);
}
@@ -132,11 +139,14 @@ public class NotificationConnectorController(NotificationsContext context) : Con
public async Task<Results<Created<string>, InternalServerError<string>>> CreatePushoverConnector ([FromBody]CreatePushoverConnectorRecord createPushoverConnectorRecord)
{
//TODO Validate Data
CreateNotificationConnectorRecord pushoverConnector = new (createPushoverConnectorRecord.Name,
$"https://api.pushover.net/1/messages.json",
"POST",
$"{{\"token\": \"{createPushoverConnectorRecord.AppToken}\", \"user\": \"{createPushoverConnectorRecord.Username}\", \"message:\":\"%text\", \"%title\" }}",
new ());
CreateNotificationConnectorRecord pushoverConnector = new ()
{
Name = createPushoverConnectorRecord.Name,
Url = "https://api.pushover.net/1/messages.json",
HttpMethod = "POST",
Body = $"{{\"token\": \"{createPushoverConnectorRecord.AppToken}\", \"user\": \"{createPushoverConnectorRecord.Username}\", \"message:\":\"%text\", \"%title\" }}",
Headers = new ()
};
return await CreateConnector(pushoverConnector);
}

View File

@@ -3,14 +3,14 @@ using System.ComponentModel.DataAnnotations;
namespace API.Controllers.Requests;
public record CreateGotifyConnectorRecord(string Name, string Url, string AppToken, int Priority)
public record CreateGotifyConnectorRecord
{
/// <summary>
/// The Name of the Notification Connector
/// </summary>
[Required]
[Description("The Name of the Notification Connector")]
public string Name { get; init; } = Name;
public required string Name { get; init; }
/// <summary>
/// The Url of the Instance
@@ -19,19 +19,19 @@ public record CreateGotifyConnectorRecord(string Name, string Url, string AppTok
[Required]
[Url]
[Description("The Url of the Instance")]
public string Url { get; internal set; } = Url;
public required string Url { get; init; }
/// <summary>
/// The Apptoken used for authentication
/// </summary>
[Required]
[Description("The Apptoken used for authentication")]
public string AppToken { get; init; } = AppToken;
public required string AppToken { get; init; }
/// <summary>
/// The Priority of Notifications
/// </summary>
[Required]
[Description("The Priority of Notifications")]
public int Priority { get; init; } = Priority;
public required int Priority { get; init; }
}

View File

@@ -4,14 +4,14 @@ using API.Schema.LibraryContext.LibraryConnectors;
namespace API.Controllers.Requests;
public sealed record CreateLibraryConnectorRecord(LibraryType LibraryType, string Url, string Username, string Password)
public sealed record CreateLibraryConnectorRecord
{
/// <summary>
/// The <see cref="LibraryType"/>
/// </summary>
[Required]
[Description("The Library Type")]
public LibraryType LibraryType { get; init; } = LibraryType;
public required LibraryType LibraryType { get; init; }
/// <summary>
/// The Url of the Library instance
@@ -19,19 +19,19 @@ public sealed record CreateLibraryConnectorRecord(LibraryType LibraryType, strin
[Required]
[Url]
[Description("The Url of the Library instance")]
public string Url { get; init; } = Url;
public required string Url { get; init; }
/// <summary>
/// The Username to authenticate to the Library instance
/// </summary>
[Required]
[Description("The Username to authenticate to the Library instance")]
public string Username { get; init; } = Username;
public required string Username { get; init; }
/// <summary>
/// The Password to authenticate to the Library instance
/// </summary>
[Required]
[Description("The Password to authenticate to the Library instance")]
public string Password { get; init; } = Password;
public required string Password { get; init; }
}

View File

@@ -3,19 +3,19 @@ using System.ComponentModel.DataAnnotations;
namespace API.Controllers.Requests;
public sealed record CreateLibraryRecord(string BasePath, string LibraryName)
public sealed record CreateLibraryRecord
{
/// <summary>
/// The directory Path of the library
/// </summary>
[Required]
[Description("The directory Path of the library")]
public string BasePath { get; init; } = BasePath;
public required string BasePath { get; init; }
/// <summary>
/// The Name of the library
/// </summary>
[Required]
[Description("The Name of the library")]
public string LibraryName { get; init; } = LibraryName;
public required string LibraryName { get; init; }
}

View File

@@ -3,14 +3,14 @@ using System.ComponentModel.DataAnnotations;
namespace API.Controllers.Requests;
public record CreateNotificationConnectorRecord(string Name, string Url, string HttpMethod, string Body, Dictionary<string, string> Headers)
public record CreateNotificationConnectorRecord
{
/// <summary>
/// The Name of the Notification Connector
/// </summary>
[Required]
[Description("The Name of the Notification Connector")]
public string Name { get; init; } = Name;
public required string Name { get; init; }
/// <summary>
/// The Url of the Instance
@@ -19,14 +19,14 @@ public record CreateNotificationConnectorRecord(string Name, string Url, string
[Required]
[Url]
[Description("The Url of the Instance")]
public string Url { get; internal set; } = Url;
public required string Url { get; init; }
/// <summary>
/// The HTTP Request Method to use for notifications
/// </summary>
[Required]
[Description("The HTTP Request Method to use for notifications")]
public string HttpMethod { get; internal set; } = HttpMethod;
public required string HttpMethod { get; init; }
/// <summary>
/// The Request Body to use to send notifications
@@ -34,7 +34,7 @@ public record CreateNotificationConnectorRecord(string Name, string Url, string
/// <remarks>Formatting placeholders: "%title" and "%text" will be replaced when notifications are sent</remarks>
[Required]
[Description("The Request Body to use to send notifications")]
public string Body { get; internal set; } = Body;
public required string Body { get; init; }
/// <summary>
/// The Request Headers to use to send notifications
@@ -42,5 +42,5 @@ public record CreateNotificationConnectorRecord(string Name, string Url, string
/// <remarks>Formatting placeholders: "%title" and "%text" will be replaced when notifications are sent</remarks>
[Required]
[Description("The Request Headers to use to send notifications")]
public Dictionary<string, string> Headers { get; internal set; } = Headers;
public required Dictionary<string, string> Headers { get; init; }
}

View File

@@ -3,14 +3,14 @@ using System.ComponentModel.DataAnnotations;
namespace API.Controllers.Requests;
public record CreateNtfyConnectorRecord(string Name, string Url, string Username, string Password, string Topic, int Priority)
public record CreateNtfyConnectorRecord
{
/// <summary>
/// The Name of the Notification Connector
/// </summary>
[Required]
[Description("The Name of the Notification Connector")]
public string Name { get; init; } = Name;
public required string Name { get; init; }
/// <summary>
/// The Url of the Instance
@@ -19,33 +19,33 @@ public record CreateNtfyConnectorRecord(string Name, string Url, string Username
[Required]
[Url]
[Description("The Url of the Instance")]
public string Url { get; internal set; } = Url;
public required string Url { get; init; }
/// <summary>
/// The Priority of Notifications
/// </summary>
[Required]
[Description("The Priority of Notifications")]
public int Priority { get; init; } = Priority;
public required int Priority { get; init; }
/// <summary>
/// The Username used for authentication
/// </summary>
[Required]
[Description("The Username used for authentication")]
public string Username { get; init; } = Username;
public required string Username { get; init; }
/// <summary>
/// The Password used for authentication
/// </summary>
[Required]
[Description("The Password used for authentication")]
public string Password { get; init; } = Password;
public required string Password { get; init; }
/// <summary>
/// The Topic of Notifications
/// </summary>
[Required]
[Description("The Topic of Notifications")]
public string Topic { get; init; } = Topic;
public required string Topic { get; init; }
}

View File

@@ -3,26 +3,26 @@ using System.ComponentModel.DataAnnotations;
namespace API.Controllers.Requests;
public record CreatePushoverConnectorRecord(string Name, string AppToken, string Username)
public record CreatePushoverConnectorRecord
{
/// <summary>
/// The Name of the Notification Connector
/// </summary>
[Required]
[Description("The Name of the Notification Connector")]
public string Name { get; init; } = Name;
public required string Name { get; init; }
/// <summary>
/// The Apptoken used for authentication
/// </summary>
[Required]
[Description("The Apptoken used for authentication")]
public string AppToken { get; init; } = AppToken;
public required string AppToken { get; init; }
/// <summary>
/// The Username used for authentication
/// </summary>
[Required]
[Description("The Username used for authentication")]
public string Username { get; init; } = Username;
public required string Username { get; init; }
}