-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into support-http-etags-and-if-none-match-header
- Loading branch information
Showing
34 changed files
with
460 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Applications/AdminCli/src/AdminCli/Commands/Announcements/AnnouncementCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.CommandLine; | ||
|
||
namespace Backbone.AdminCli.Commands.Announcements; | ||
|
||
public class AnnouncementCommand : Command | ||
{ | ||
public AnnouncementCommand(SendAnnouncementCommand sendAnnouncementCommand) : base("announcement") | ||
{ | ||
AddCommand(sendAnnouncementCommand); | ||
} | ||
} |
152 changes: 152 additions & 0 deletions
152
Applications/AdminCli/src/AdminCli/Commands/Announcements/SendAnnouncementCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
using System.CommandLine; | ||
using System.Text.Json; | ||
using Backbone.AdminCli.Commands.BaseClasses; | ||
using Backbone.Modules.Announcements.Application.Announcements.Commands.CreateAnnouncement; | ||
using Backbone.Modules.Announcements.Domain.Entities; | ||
using MediatR; | ||
|
||
namespace Backbone.AdminCli.Commands.Announcements; | ||
|
||
public class SendAnnouncementCommand : AdminCliCommand | ||
{ | ||
public SendAnnouncementCommand(IMediator mediator) : base(mediator, "send") | ||
{ | ||
var expiresAt = new Option<string?>("--expiration") | ||
{ | ||
IsRequired = false, | ||
Description = "The expiration date of the announcement." | ||
}; | ||
|
||
var severity = new Option<string?>("--severity") | ||
{ | ||
IsRequired = true, | ||
Description = "The severity of the announcement. Possible values: Low, Medium, High" | ||
}; | ||
|
||
AddOption(expiresAt); | ||
AddOption(severity); | ||
|
||
this.SetHandler(SendAnnouncement, severity, expiresAt); | ||
} | ||
|
||
private async Task SendAnnouncement(string? severityInput, string? expiresAtInput) | ||
{ | ||
try | ||
{ | ||
var severity = severityInput switch | ||
{ | ||
_ when Enum.TryParse<AnnouncementSeverity>(severityInput, ignoreCase: true, out var parsedSeverity) => parsedSeverity, | ||
_ => throw new ArgumentException($@"Specified severity '{severityInput}' is not a valid severity.") | ||
}; | ||
|
||
DateTime? expiresAt = expiresAtInput switch | ||
{ | ||
_ when string.IsNullOrWhiteSpace(expiresAtInput) => null, | ||
_ when DateTime.TryParse(expiresAtInput, out var parsedDateTime) => parsedDateTime, | ||
_ => throw new ArgumentException($@"Specified expiration datetime '{expiresAtInput}' is not a valid DateTime.") | ||
}; | ||
|
||
var texts = ReadTextsFromCommandLineInput(); | ||
|
||
if (texts.Count == 0) | ||
{ | ||
Console.WriteLine(@"No texts provided. Exiting..."); | ||
return; | ||
} | ||
|
||
Console.WriteLine(@"You entered the following texts:"); | ||
Console.WriteLine(JsonSerializer.Serialize(texts, JSON_SERIALIZER_OPTIONS)); | ||
if (!PromptForConfirmation(@"Do you want to proceed?")) return; | ||
|
||
Console.WriteLine(@"Sending announcement..."); | ||
|
||
try | ||
{ | ||
var response = await _mediator.Send(new CreateAnnouncementCommand | ||
{ | ||
Texts = texts, | ||
Severity = severity, | ||
ExpiresAt = expiresAt | ||
}, CancellationToken.None); | ||
|
||
Console.WriteLine(@"Announcement sent successfully"); | ||
Console.WriteLine(JsonSerializer.Serialize(response, JSON_SERIALIZER_OPTIONS)); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine($@"An error occurred: {e.Message}"); | ||
} | ||
} | ||
|
||
private static List<CreateAnnouncementCommandText> ReadTextsFromCommandLineInput() | ||
{ | ||
var texts = new List<CreateAnnouncementCommandText>(); | ||
|
||
var englishTitle = PromptForInput(@"Enter english title: "); | ||
var englishBody = PromptForInput(@"Enter english body: "); | ||
|
||
if (englishTitle == null || englishBody == null) return texts; | ||
|
||
texts.Add(new CreateAnnouncementCommandText | ||
{ | ||
Language = "en", | ||
Title = englishTitle, | ||
Body = englishBody | ||
}); | ||
|
||
while (PromptForConfirmation(@"Do you want to add another language?")) | ||
{ | ||
var language = PromptForInput(@"Enter a two-letter language code (e.g. de, it, nl): "); | ||
var title = PromptForInput(@"Enter title: "); | ||
var body = PromptForInput(@"Enter body: "); | ||
|
||
if (language == null || title == null || body == null) | ||
{ | ||
break; | ||
} | ||
|
||
texts.Add(new CreateAnnouncementCommandText | ||
{ | ||
Language = language, | ||
Title = title, | ||
Body = body | ||
}); | ||
} | ||
|
||
return texts; | ||
} | ||
|
||
private static string? PromptForInput(string prompt, bool allowEmpty = false) | ||
{ | ||
Console.Write(prompt); | ||
var input = Console.ReadLine(); | ||
|
||
while (!allowEmpty && string.IsNullOrWhiteSpace(input)) | ||
{ | ||
Console.WriteLine(@"Input cannot be empty. Press x to exit."); | ||
Console.Write(prompt); | ||
input = Console.ReadLine(); | ||
|
||
if (string.IsNullOrWhiteSpace(input)) | ||
continue; | ||
if (input.Trim().Equals("x", StringComparison.CurrentCultureIgnoreCase)) | ||
return null; | ||
|
||
break; | ||
} | ||
|
||
return input; | ||
} | ||
|
||
private static bool PromptForConfirmation(string prompt) | ||
{ | ||
var input = PromptForInput($"{prompt} ([y]es/[N]o): ", true); | ||
return input?.Trim().ToLower() is "yes" or "y"; | ||
} | ||
} |
9 changes: 5 additions & 4 deletions
9
Applications/AdminCli/src/AdminCli/Commands/BaseClasses/AdminCliCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
using System.CommandLine; | ||
using System.Text.Json; | ||
using MediatR; | ||
|
||
namespace Backbone.AdminCli.Commands.BaseClasses; | ||
|
||
public abstract class AdminCliCommand : Command | ||
{ | ||
protected readonly IMediator _mediator; | ||
|
||
protected static readonly JsonSerializerOptions JSON_SERIALIZER_OPTIONS = | ||
new() { WriteIndented = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; | ||
|
||
protected readonly ServiceLocator _serviceLocator; | ||
|
||
protected AdminCliCommand(string name, ServiceLocator serviceLocator, string? description = null) : base(name, description) | ||
protected AdminCliCommand(IMediator mediator, string name, string? description = null) : base(name, description) | ||
{ | ||
_serviceLocator = serviceLocator; | ||
_mediator = mediator; | ||
} | ||
} |
64 changes: 0 additions & 64 deletions
64
Applications/AdminCli/src/AdminCli/Commands/BaseClasses/AdminCliDbCommand.cs
This file was deleted.
Oops, something went wrong.
12 changes: 6 additions & 6 deletions
12
Applications/AdminCli/src/AdminCli/Commands/Clients/ClientCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
using Backbone.AdminCli.Commands.BaseClasses; | ||
using System.CommandLine; | ||
|
||
namespace Backbone.AdminCli.Commands.Clients; | ||
|
||
public class ClientCommand : AdminCliCommand | ||
public class ClientCommand : Command | ||
{ | ||
public ClientCommand(ServiceLocator serviceLocator) : base("client", serviceLocator) | ||
public ClientCommand(CreateClientCommand createClientCommand, ListClientsCommand listClientsCommand, DeleteClientsCommand deleteClientsCommand) : base("client") | ||
{ | ||
AddCommand(new CreateClientCommand(serviceLocator)); | ||
AddCommand(new ListClientsCommand(serviceLocator)); | ||
AddCommand(new DeleteClientsCommand(serviceLocator)); | ||
AddCommand(createClientCommand); | ||
AddCommand(listClientsCommand); | ||
AddCommand(deleteClientsCommand); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.