Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/Commands/Publisher/ChildPublishers/AddChildPublisherCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ public class AddChildPublisherCommand : Command
/// <summary>
/// Initializes a new instance of the <see cref="AddChildPublisherCommand"/> class.
/// </summary>
public AddChildPublisherCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption)
public AddChildPublisherCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption, Option<string> roleIdOption, Option<string> roleNameOption, Option<string> roleDescriptionOption)
: base("add", "Adds a child publisher to the Publisher.")
{
AddOption(repoOption);
AddOption(idOption);
AddOption(publisherIdOption);
AddOption(roleIdOption);
AddOption(roleNameOption);
AddOption(roleDescriptionOption);

this.SetHandler(InvokeAsync, repoOption, idOption, publisherIdOption);
this.SetHandler(InvokeAsync, repoOption, idOption, publisherIdOption, roleIdOption, roleNameOption, roleDescriptionOption);
this.Config = config;
}

protected WacsdkCommandConfig Config { get; init; }

public async Task InvokeAsync(string repo, string id, string publisherId)
public async Task InvokeAsync(string repo, string id, string publisherId, string roleId, string roleName, string roleDescription)
{
Guard.IsNotNullOrWhiteSpace(publisherId);

Expand All @@ -43,8 +46,19 @@ public async Task InvokeAsync(string repo, string id, string publisherId)
var childPublisher = await GetPublisherByIdAsync(repo, publisherId, cancellationToken);
Logger.LogInformation($"Got {nameof(childPublisher.Id)}: {childPublisher.Id}");

var role = new Role
{
Id = roleId,
Name = roleName,
Description = roleDescription
};

var readOnlyPublisher = childPublisher is ModifiablePublisher modifiablePublisher ? modifiablePublisher.InnerPublisher : (ReadOnlyPublisher)childPublisher;

var publisherRole = new ReadOnlyPublisherRole { Role = role, InnerPublisher = readOnlyPublisher };

Logger.LogInformation($"Adding child publisher to collection");
await publisher.ChildPublishers.AddPublisherAsync(childPublisher, cancellationToken);
await publisher.ChildPublishers.AddPublisherAsync(publisherRole, cancellationToken);

Logger.LogInformation($"Publishing changes");
await PublishAsync(publisher, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class ChildPublishersCommand : Command
/// <summary>
/// Initializes a new instance of the <see cref="ChildPublishersCommand"/> class.
/// </summary>
public ChildPublishersCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption)
public ChildPublishersCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption, Option<string> roleIdOption, Option<string> roleNameOption, Option<string> roleDescriptionOption)
: base("child-publishers", "Manages the child publishers of the Publisher.")
{
AddCommand(new GetChildPublishersCommand(config, repoOption, idOption));
AddCommand(new AddChildPublisherCommand(config, repoOption, idOption, publisherIdOption));
AddCommand(new AddChildPublisherCommand(config, repoOption, idOption, publisherIdOption, roleIdOption, roleNameOption, roleDescriptionOption));
AddCommand(new RemoveChildPublisherCommand(config, repoOption, idOption, publisherIdOption));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task InvokeAsync(string repo, string id, string publisherId)
Logger.LogInformation($"Got {nameof(publisher.Id)}: {publisher.Id}");

Logger.LogInformation($"Getting child publisher to remove");
var childPublisher = await GetPublisherByIdAsync(repo, publisherId, cancellationToken);
var childPublisher = await publisher.ChildPublishers.GetPublishersAsync(cancellationToken).FirstAsync(p => p.Id == publisherId, cancellationToken);
Logger.LogInformation($"Got {nameof(childPublisher.Id)}: {childPublisher.Id}");

Logger.LogInformation($"Removing child publisher from collection");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ public class AddParentPublisherCommand : Command
/// <summary>
/// Initializes a new instance of the <see cref="AddParentPublisherCommand"/> class.
/// </summary>
public AddParentPublisherCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption)
public AddParentPublisherCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption, Option<string> roleIdOption, Option<string> roleNameOption, Option<string> roleDescriptionOption)
: base("add", "Adds a parent publisher to the Publisher.")
{
AddOption(repoOption);
AddOption(idOption);
AddOption(publisherIdOption);
AddOption(roleIdOption);
AddOption(roleNameOption);
AddOption(roleDescriptionOption);

this.SetHandler(InvokeAsync, repoOption, idOption, publisherIdOption);
this.SetHandler(InvokeAsync, repoOption, idOption, publisherIdOption, roleIdOption, roleNameOption, roleDescriptionOption);
this.Config = config;
}

protected WacsdkCommandConfig Config { get; init; }

public async Task InvokeAsync(string repo, string id, string publisherId)
public async Task InvokeAsync(string repo, string id, string publisherId, string roleId, string roleName, string roleDescription)
{
Guard.IsNotNullOrWhiteSpace(publisherId);

Expand All @@ -40,11 +43,22 @@ public async Task InvokeAsync(string repo, string id, string publisherId)
Logger.LogInformation($"Got {nameof(publisher.Id)}: {publisher.Id}");

Logger.LogInformation($"Getting parent publisher");
var parentPublisher = await GetPublisherByIdAsync(repo, publisherId, cancellationToken);
Logger.LogInformation($"Got {nameof(parentPublisher.Id)}: {parentPublisher.Id}");
var childPublisher = await GetPublisherByIdAsync(repo, publisherId, cancellationToken);
Logger.LogInformation($"Got {nameof(childPublisher.Id)}: {childPublisher.Id}");

var role = new Role
{
Id = roleId,
Name = roleName,
Description = roleDescription
};

var readOnlyPublisher = childPublisher is ModifiablePublisher modifiablePublisher ? modifiablePublisher.InnerPublisher : (ReadOnlyPublisher)childPublisher;

var publisherRole = new ReadOnlyPublisherRole { Role = role, InnerPublisher = readOnlyPublisher };

Logger.LogInformation($"Adding parent publisher to collection");
await publisher.ParentPublishers.AddPublisherAsync(parentPublisher, cancellationToken);
await publisher.ParentPublishers.AddPublisherAsync(publisherRole, cancellationToken);

Logger.LogInformation($"Publishing changes");
await PublishAsync(publisher, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class ParentPublishersCommand : Command
/// <summary>
/// Initializes a new instance of the <see cref="ParentPublishersCommand"/> class.
/// </summary>
public ParentPublishersCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption)
public ParentPublishersCommand(WacsdkCommandConfig config, Option<string> repoOption, Option<string> idOption, Option<string> publisherIdOption, Option<string> roleIdOption, Option<string> roleNameOption, Option<string> roleDescriptionOption)
: base("parent-publishers", "Manages the parent publishers of the Publisher.")
{
AddCommand(new GetParentPublishersCommand(config, repoOption, idOption));
AddCommand(new AddParentPublisherCommand(config, repoOption, idOption, publisherIdOption));
AddCommand(new AddParentPublisherCommand(config, repoOption, idOption, publisherIdOption, roleIdOption, roleNameOption, roleDescriptionOption));
AddCommand(new RemoveParentPublisherCommand(config, repoOption, idOption, publisherIdOption));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task InvokeAsync(string repo, string id, string publisherId)
Logger.LogInformation($"Got {nameof(publisher.Id)}: {publisher.Id}");

Logger.LogInformation($"Getting parent publisher to remove");
var parentPublisher = await GetPublisherByIdAsync(repo, publisherId, cancellationToken);
var parentPublisher = await publisher.ParentPublishers.GetPublishersAsync(cancellationToken).FirstAsync(p => p.Id == publisherId, cancellationToken);
Logger.LogInformation($"Got {nameof(parentPublisher.Id)}: {parentPublisher.Id}");

Logger.LogInformation($"Removing parent publisher from collection");
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Publisher/WacsdkPublisherCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public WacsdkPublisherCommands(WacsdkCommandConfig config, Option<string> repoOp

// Add publisher-specific collection commands
AddCommand(new ProjectsCommand(config, repoOption, publisherIdOption, projectIdOption));
AddCommand(new ChildPublishersCommand(config, repoOption, parentPublisherIdOption, childPublisherIdOption));
AddCommand(new ParentPublishersCommand(config, repoOption, childPublisherIdOption, parentPublisherIdOption));
AddCommand(new ChildPublishersCommand(config, repoOption, parentPublisherIdOption, childPublisherIdOption, roleIdOption, roleNameOption, roleDescriptionOption));
AddCommand(new ParentPublishersCommand(config, repoOption, childPublisherIdOption, parentPublisherIdOption, roleIdOption, roleNameOption, roleDescriptionOption));
}
}
}
Loading