diff --git a/NBXplorer.Client/ExplorerClient.cs b/NBXplorer.Client/ExplorerClient.cs index 63281fa40..96dd9543a 100644 --- a/NBXplorer.Client/ExplorerClient.cs +++ b/NBXplorer.Client/ExplorerClient.cs @@ -585,7 +585,11 @@ public GenerateWalletResponse GenerateWallet(GenerateWalletRequest request = nul public Task CreateGroupAsync(CancellationToken cancellationToken = default) { - return SendAsync(HttpMethod.Post, null, $"v1/groups", cancellationToken); + return CreateGroupAsync(null, cancellationToken); + } + public Task CreateGroupAsync(CreateGroupRequest request, CancellationToken cancellationToken = default) + { + return SendAsync(HttpMethod.Post, request, $"v1/groups", cancellationToken); } public Task GetGroupAsync(string groupId, CancellationToken cancellationToken = default) { diff --git a/NBXplorer.Client/Models/GroupInformation.cs b/NBXplorer.Client/Models/GroupInformation.cs index 136b5ee57..957ec330e 100644 --- a/NBXplorer.Client/Models/GroupInformation.cs +++ b/NBXplorer.Client/Models/GroupInformation.cs @@ -1,10 +1,12 @@ using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Text; namespace NBXplorer.Models { + + public class CreateGroupRequest + { + public string GroupId { get; set; } + } public class GroupChild { [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] diff --git a/NBXplorer.Tests/UnitTest1.Groups.cs b/NBXplorer.Tests/UnitTest1.Groups.cs index 4b02dc93d..ca6af1887 100644 --- a/NBXplorer.Tests/UnitTest1.Groups.cs +++ b/NBXplorer.Tests/UnitTest1.Groups.cs @@ -15,7 +15,11 @@ public partial class UnitTest1 public async Task CanCRUDGroups() { using var tester = ServerTester.Create(); + var guid = Guid.NewGuid().ToString(); + var g222 = await tester.Client.CreateGroupAsync(new CreateGroupRequest() { GroupId = guid }); + Assert.Equal(g222.GroupId, guid); var g1 = await tester.Client.CreateGroupAsync(); + void AssertG1Empty() { Assert.NotNull(g1.GroupId); diff --git a/NBXplorer/Controllers/GroupsController.cs b/NBXplorer/Controllers/GroupsController.cs index e13f84484..d8e36714d 100644 --- a/NBXplorer/Controllers/GroupsController.cs +++ b/NBXplorer/Controllers/GroupsController.cs @@ -30,9 +30,9 @@ public GroupsController( public NBXplorerNetworkProvider NetworkProvider { get; } [HttpPost(CommonRoutes.BaseGroupEndpoint)] - public async Task CreateGroup() + public async Task CreateGroup([FromBody] CreateGroupRequest request) { - var group = GroupTrackedSource.Generate(); + var group = string.IsNullOrEmpty(request?.GroupId)? GroupTrackedSource.Generate(): new GroupTrackedSource(request.GroupId); await using var conn = await ConnectionFactory.CreateConnection(); await conn.ExecuteAsync(Repository.WalletInsertQuery, Repository.GetWalletKey(group)); return base.Ok(ToGroupInfo(group)); diff --git a/NBXplorer/wwwroot/api.json b/NBXplorer/wwwroot/api.json index 60bbce97b..a917ef45b 100644 --- a/NBXplorer/wwwroot/api.json +++ b/NBXplorer/wwwroot/api.json @@ -2524,10 +2524,25 @@ }, "/v1/groups": { "post": { - "summary": "Create a new empty group", + "summary": "Create a new group", "tags": [ "Groups" ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "groupId": { + "type": "string", + "description": "The id of the group to create. If not specified, a random one is generated." + } + } + } + } + } + }, "responses": { "200": { "description": "Group created successfully", @@ -2595,70 +2610,6 @@ } } }, - "post": { - "summary": "Create or overwrite a group", - "operationId": "Create", - "description": "Creates a new group with the specified groupId. If a group with the same groupId already exists, it will be overwritten.", - "tags": [ - "Groups" - ], - "parameters": [ - { - "$ref": "#/components/parameters/GroupId" - } - ], - "requestBody": { - "required": false, - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "children": { - "type": "array", - "items": { - "type": "string" - }, - "description": "An array of tracked sources (derivation schemes or other groups) to be included in the group." - } - } - }, - "example": { - "children": [ - "DERIVATIONSCHEME:xpub6CUGRUonZSQ4TWtTMmzXdrXDtypWKiK...", - "GROUP:my-other-group" - ] - } - } - } - }, - "responses": { - "200": { - "description": "Group created or overwritten successfully.", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Group" - } - } - } - }, - "400": { - "description": "Bad Request. Invalid groupId or children.", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ErrorResponse" - }, - "example": { - "error": "Invalid groupId or children.", - "code": 400 - } - } - } - } - } - }, "delete": { "summary": "Delete a group", "description": "Deletes an existing group specified by `groupId`. This will remove the group but will not delete any of its child tracked sources.",