RestApiModule: Support binding a RestView for resource creation
Instead of handling resource creation by implementing AcceptsCreate in the RestCollection, add a new RestCreateView that can be bound via RestApiModule. This improves code readability since by reading the Module class we can now directly see which REST collections support resource creation. In addition we no longer need factories to create the REST view that creates the resource. This allows us at Google to bind a different REST view for the resource creation internally while we still use the upstream REST collection for parsing and listing. Without this change we would need to subclass the upstream RestCollection and override the create method which is error-prone. This change adds REST tests for creating a resource on a root collection (com.google.gerrit.acceptance.rest.account.CreateAccountIT#createAccountRestApi) and for creating a resource on a child collection (com.google.gerrit.acceptance.rest.account.CreateBranchIT#createBranchRestApi), however it doesn't test resource creation via REST for all possible resource types. There are more things that we likely also want to replace by bindings (AcceptsPost, AcceptsDelete, listing members). This should be done by follow-up changes. Change-Id: I5cd61f77aad2a59a02333b5f68b86bda6c353879 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -91,7 +91,7 @@ final class CreateGroupCommand extends SshCommand {
|
||||
initialGroups.add(id);
|
||||
}
|
||||
|
||||
@Inject private CreateGroup.Factory createGroupFactory;
|
||||
@Inject private CreateGroup createGroup;
|
||||
|
||||
@Inject private GroupsCollection groups;
|
||||
|
||||
@@ -126,7 +126,8 @@ final class CreateGroupCommand extends SshCommand {
|
||||
input.ownerId = String.valueOf(ownerGroupId.get());
|
||||
}
|
||||
|
||||
GroupInfo group = createGroupFactory.create(groupName).apply(TopLevelResource.INSTANCE, input);
|
||||
GroupInfo group =
|
||||
createGroup.apply(TopLevelResource.INSTANCE, IdString.fromDecoded(groupName), input);
|
||||
return groups.parse(TopLevelResource.INSTANCE, IdString.fromUrl(group.id));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user