Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create group with predetermined id #459

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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 @@ -549,7 +549,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
7 changes: 6 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,12 @@ Create a new empty group.

`HTTP POST v1/groups`

No body required
Optional request body:
```json
{
"groupId": "yourGroupId"
}
```

Response

Expand Down