Skip to content
Open
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
6 changes: 5 additions & 1 deletion NBXplorer.Client/ExplorerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,11 @@ public GenerateWalletResponse GenerateWallet(GenerateWalletRequest request = nul

public Task<GroupInformation> CreateGroupAsync(CancellationToken cancellationToken = default)
{
return SendAsync<GroupInformation>(HttpMethod.Post, null, $"v1/groups", cancellationToken);
return CreateGroupAsync(null, cancellationToken);
}
public Task<GroupInformation> CreateGroupAsync(CreateGroupRequest request, CancellationToken cancellationToken = default)
{
return SendAsync<GroupInformation>(HttpMethod.Post, request, $"v1/groups", cancellationToken);
}
public Task<GroupInformation> GetGroupAsync(string groupId, CancellationToken cancellationToken = default)
{
Expand Down
8 changes: 5 additions & 3 deletions NBXplorer.Client/Models/GroupInformation.cs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
4 changes: 4 additions & 0 deletions NBXplorer.Tests/UnitTest1.Groups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions NBXplorer/Controllers/GroupsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public GroupsController(
public NBXplorerNetworkProvider NetworkProvider { get; }

[HttpPost(CommonRoutes.BaseGroupEndpoint)]
public async Task<IActionResult> CreateGroup()
public async Task<IActionResult> 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));
Expand Down
81 changes: 16 additions & 65 deletions NBXplorer/wwwroot/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.",
Expand Down