diff --git a/src/Commands/Project/WacsdkProjectCommands.cs b/src/Commands/Project/WacsdkProjectCommands.cs index 6ae498c..8e405c6 100644 --- a/src/Commands/Project/WacsdkProjectCommands.cs +++ b/src/Commands/Project/WacsdkProjectCommands.cs @@ -53,6 +53,7 @@ public WacsdkProjectCommands(WacsdkCommandConfig config, Option repoOpti AddCommand(new WacsdkProjectGetCommand(config, repoOption)); AddCommand(new WacsdkProjectCreateCommand(config, repoOption, nameOption, descriptionOption)); AddCommand(new WacsdkProjectListCommand(config, repoOption)); + AddCommand(new WacsdkProjectDeleteCommand(config, repoOption)); // Add entity property management commands AddCommand(new EntityNameCommand(config, repoOption, projectIdOption, valueOption)); @@ -60,14 +61,14 @@ public WacsdkProjectCommands(WacsdkCommandConfig config, Option repoOpti AddCommand(new EntityExtendedDescription(config, repoOption, projectIdOption, valueOption)); AddCommand(new EntityIsUnlistedCommand(config, repoOption, projectIdOption, boolValueOption)); AddCommand(new EntityForgetMeCommand(config, repoOption, projectIdOption, nullableBoolValueOption)); - + // Add collection management commands AddCommand(new ConnectionsCommand(config, repoOption, projectIdOption, connectionIdOption, connectionValueOption)); AddCommand(new EntityImagesCommand(config, repoOption, projectIdOption, imagePathOption, optionalImageIdOption, requiredImageIdOption, imageNameOption)); AddCommand(new LinksCommand(config, repoOption, projectIdOption, linkIdOption, nameOption, urlOption, descriptionOption)); AddCommand(new UserRolesCommand(config, repoOption, projectIdOption, userIdOption, roleIdOption, roleNameOption, roleDescriptionOption)); AddCommand(new AccentColorCommand(config, repoOption, projectIdOption, colorOption)); - + // Add project-specific commands AddCommand(new CategoryCommand(config, repoOption, projectIdOption, categoryOption)); AddCommand(new FeaturesCommand(config, repoOption, projectIdOption, featureOption)); diff --git a/src/Commands/Project/WacsdkProjectDeleteCommand.cs b/src/Commands/Project/WacsdkProjectDeleteCommand.cs new file mode 100644 index 0000000..6b20398 --- /dev/null +++ b/src/Commands/Project/WacsdkProjectDeleteCommand.cs @@ -0,0 +1,63 @@ +using OwlCore.Diagnostics; +using OwlCore.Storage; +using System.CommandLine; +using WindowsAppCommunity.Sdk.Nomad; + +namespace WindowsAppCommunity.CommandLine.Project +{ + /// + /// Command to delete an existing project. + /// + public class WacsdkProjectDeleteCommand : Command + { + /// + /// Initializes a new instance of the class. + /// + public WacsdkProjectDeleteCommand(WacsdkCommandConfig config, Option repoOption) + : base(name: "delete", description: "Deletes a project.") + { + var projectIdOption = new Option( + name: "--project-id", + description: "The ID of the project to delete.") + { + IsRequired = true + }; + + AddOption(repoOption); + AddOption(projectIdOption); + this.SetHandler(InvokeAsync, repoOption, projectIdOption); + + Config = config; + } + + /// + /// Shared command configuration. + /// + public WacsdkCommandConfig Config { get; } + + /// + /// Handles the command. + /// + public async Task InvokeAsync(string repoId, string projectId) + { + var thisRepoStorage = (IModifiableFolder)await Config.RepositoryStorage.CreateFolderAsync(repoId, overwrite: false); + + Logger.LogInformation($"Getting repo store with ID {repoId} at {thisRepoStorage.GetType().Name} {thisRepoStorage.Id}"); + var repoSettings = new WacsdkNomadSettings(thisRepoStorage); + await repoSettings.LoadAsync(Config.CancellationToken); + + var repositoryContainer = new RepositoryContainer(Config.KuboOptions, Config.Client, repoSettings.ManagedKeys, repoSettings.ManagedUserConfigs, repoSettings.ManagedProjectConfigs, repoSettings.ManagedPublisherConfigs); + + Logger.LogInformation($"Getting project {projectId}"); + var project = (ModifiableProject)await repositoryContainer.ProjectRepository.GetAsync(projectId, Config.CancellationToken); + + Logger.LogInformation($"Deleting project {projectId}"); + await repositoryContainer.ProjectRepository.DeleteAsync(project, Config.CancellationToken); + + Logger.LogInformation($"Saving repository changes"); + await repoSettings.SaveAsync(Config.CancellationToken); + + Logger.LogInformation($"Deleted project {projectId}"); + } + } +} diff --git a/src/Commands/Publisher/WacsdkPublisherCommands.cs b/src/Commands/Publisher/WacsdkPublisherCommands.cs index aec8706..77202c4 100644 --- a/src/Commands/Publisher/WacsdkPublisherCommands.cs +++ b/src/Commands/Publisher/WacsdkPublisherCommands.cs @@ -57,6 +57,7 @@ public WacsdkPublisherCommands(WacsdkCommandConfig config, Option repoOp AddCommand(new WacsdkPublisherGetCommand(config, repoOption)); AddCommand(new WacsdkPublisherCreateCommand(config, repoOption)); AddCommand(new WacsdkPublisherListCommand(config, repoOption)); + AddCommand(new WacsdkPublisherDeleteCommand(config, repoOption)); // Add entity property management commands AddCommand(new EntityNameCommand(config, repoOption, publisherIdOption, valueOption)); @@ -64,7 +65,7 @@ public WacsdkPublisherCommands(WacsdkCommandConfig config, Option repoOp AddCommand(new EntityExtendedDescription(config, repoOption, publisherIdOption, valueOption)); AddCommand(new EntityIsUnlistedCommand(config, repoOption, publisherIdOption, boolValueOption)); AddCommand(new EntityForgetMeCommand(config, repoOption, publisherIdOption, nullableBoolValueOption)); - + // Add collection management commands AddCommand(new ConnectionsCommand(config, repoOption, publisherIdOption, connectionIdOption, connectionValueOption)); AddCommand(new EntityImagesCommand(config, repoOption, publisherIdOption, imagePathOption, requiredImageIdOption, optionalImageIdOption, imageNameOption)); diff --git a/src/Commands/Publisher/WacsdkPublisherDeleteCommand.cs b/src/Commands/Publisher/WacsdkPublisherDeleteCommand.cs new file mode 100644 index 0000000..c683b35 --- /dev/null +++ b/src/Commands/Publisher/WacsdkPublisherDeleteCommand.cs @@ -0,0 +1,63 @@ +using OwlCore.Diagnostics; +using OwlCore.Storage; +using System.CommandLine; +using WindowsAppCommunity.Sdk.Nomad; + +namespace WindowsAppCommunity.CommandLine.Publisher +{ + /// + /// Command to delete an existing publisher. + /// + public class WacsdkPublisherDeleteCommand : Command + { + /// + /// Initializes a new instance of the class. + /// + public WacsdkPublisherDeleteCommand(WacsdkCommandConfig config, Option repoOption) + : base(name: "delete", description: "Deletes a publisher.") + { + var publisherIdOption = new Option( + name: "--publisher-id", + description: "The ID of the publisher to delete.") + { + IsRequired = true + }; + + AddOption(repoOption); + AddOption(publisherIdOption); + this.SetHandler(InvokeAsync, repoOption, publisherIdOption); + + Config = config; + } + + /// + /// Shared command configuration. + /// + public WacsdkCommandConfig Config { get; } + + /// + /// Handles the command. + /// + public async Task InvokeAsync(string repoId, string publisherId) + { + var thisRepoStorage = (IModifiableFolder)await Config.RepositoryStorage.CreateFolderAsync(repoId, overwrite: false); + + Logger.LogInformation($"Getting repo store with ID {repoId} at {thisRepoStorage.GetType().Name} {thisRepoStorage.Id}"); + var repoSettings = new WacsdkNomadSettings(thisRepoStorage); + await repoSettings.LoadAsync(Config.CancellationToken); + + var repositoryContainer = new RepositoryContainer(Config.KuboOptions, Config.Client, repoSettings.ManagedKeys, repoSettings.ManagedUserConfigs, repoSettings.ManagedProjectConfigs, repoSettings.ManagedPublisherConfigs); + + Logger.LogInformation($"Getting publisher {publisherId}"); + var publisher = (ModifiablePublisher)await repositoryContainer.PublisherRepository.GetAsync(publisherId, Config.CancellationToken); + + Logger.LogInformation($"Deleting publisher {publisherId}"); + await repositoryContainer.PublisherRepository.DeleteAsync(publisher, Config.CancellationToken); + + Logger.LogInformation($"Saving repository changes"); + await repoSettings.SaveAsync(Config.CancellationToken); + + Logger.LogInformation($"Deleted publisher {publisherId}"); + } + } +} diff --git a/src/Commands/User/WacsdkUserCommands.cs b/src/Commands/User/WacsdkUserCommands.cs index fa0c880..e95a2d9 100644 --- a/src/Commands/User/WacsdkUserCommands.cs +++ b/src/Commands/User/WacsdkUserCommands.cs @@ -44,20 +44,21 @@ public WacsdkUserCommands(WacsdkCommandConfig config, Option repoOption) var roleIdOption = new Option("--role-id", "The ID of the role."); var roleNameOption = new Option("--role-name", "The name of the role."); var roleDescriptionOption = new Option("--role-description", "The description of the role."); - - + + // Add high-level user operations AddCommand(new WacsdkUserGetCommand(config, repoOption)); AddCommand(new WacsdkUserCreateCommand(config, repoOption, nameOption, descriptionOption)); - AddCommand(new WacsdkUserListCommand(config, repoOption)); - + AddCommand(new WacsdkUserListCommand(config, repoOption)); + AddCommand(new WacsdkUserDeleteCommand(config, repoOption)); + // Add entity property management commands AddCommand(new EntityNameCommand(config, repoOption, userIdOption, valueOption)); AddCommand(new EntityDescription(config, repoOption, userIdOption, valueOption)); AddCommand(new EntityExtendedDescription(config, repoOption, userIdOption, valueOption)); AddCommand(new EntityIsUnlistedCommand(config, repoOption, userIdOption, boolValueOption)); AddCommand(new EntityForgetMeCommand(config, repoOption, userIdOption, nullableBoolValueOption)); - + // Add collection management commands AddCommand(new ConnectionsCommand(config, repoOption, userIdOption, connectionIdOption, connectionValueOption)); AddCommand(new EntityImagesCommand(config, repoOption, userIdOption, imagePathOption, imageNameOption, optionalImageIdOption, requiredImageIdOption)); diff --git a/src/Commands/User/WacsdkUserDeleteCommand.cs b/src/Commands/User/WacsdkUserDeleteCommand.cs new file mode 100644 index 0000000..644d725 --- /dev/null +++ b/src/Commands/User/WacsdkUserDeleteCommand.cs @@ -0,0 +1,64 @@ +using OwlCore.Diagnostics; +using OwlCore.Storage; +using System.CommandLine; +using WindowsAppCommunity.Sdk.Nomad; + +namespace WindowsAppCommunity.CommandLine.User +{ + /// + /// Command to delete an existing user. + /// + public class WacsdkUserDeleteCommand : Command + { + /// + /// Initializes a new instance of the class. + /// + public WacsdkUserDeleteCommand(WacsdkCommandConfig config, Option repoOption) + : base(name: "delete", description: "Deletes a user.") + { + var userIdOption = new Option( + name: "--user-id", + description: "The ID of the user to delete.") + { + IsRequired = true + }; + + AddOption(repoOption); + AddOption(userIdOption); + + this.SetHandler(InvokeAsync, repoOption, userIdOption); + + Config = config; + } + + /// + /// Shared command configuration. + /// + public WacsdkCommandConfig Config { get; } + + /// + /// Handles the command. + /// + public async Task InvokeAsync(string repoId, string userId) + { + var thisRepoStorage = (IModifiableFolder)await Config.RepositoryStorage.CreateFolderAsync(repoId, overwrite: false); + + Logger.LogInformation($"Getting repo store with ID {repoId} at {thisRepoStorage.GetType().Name} {thisRepoStorage.Id}"); + var repoSettings = new WacsdkNomadSettings(thisRepoStorage); + await repoSettings.LoadAsync(Config.CancellationToken); + + var repositoryContainer = new RepositoryContainer(Config.KuboOptions, Config.Client, repoSettings.ManagedKeys, repoSettings.ManagedUserConfigs, repoSettings.ManagedProjectConfigs, repoSettings.ManagedPublisherConfigs); + + Logger.LogInformation($"Getting user {userId}"); + var user = (ModifiableUser)await repositoryContainer.UserRepository.GetAsync(userId, Config.CancellationToken); + + Logger.LogInformation($"Deleting user {userId}"); + await repositoryContainer.UserRepository.DeleteAsync(user, Config.CancellationToken); + + Logger.LogInformation($"Saving repository changes"); + await repoSettings.SaveAsync(Config.CancellationToken); + + Logger.LogInformation($"Deleted user {userId}"); + } + } +}