Skip to content

Commit cbb98b0

Browse files
committed
feat: proper properties api for groups
1 parent 8861e64 commit cbb98b0

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

api/src/main/java/app/simplecloud/api/group/GroupApi.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.jetbrains.annotations.Nullable;
44

55
import java.util.List;
6+
import java.util.Map;
67
import java.util.concurrent.CompletableFuture;
78

89
/**
@@ -75,5 +76,23 @@ default CompletableFuture<List<Group>> getAllGroups() {
7576
* @return a CompletableFuture that completes when the group is deleted
7677
*/
7778
CompletableFuture<Void> deleteGroup(String id);
79+
80+
/**
81+
* Updates group properties by merging with existing properties (deep merge).
82+
*
83+
* @param id the unique ID of the server group
84+
* @param properties the properties to merge
85+
* @return a CompletableFuture that completes with the updated properties
86+
*/
87+
CompletableFuture<Map<String, Object>> updateGroupProperties(String id, Map<String, Object> properties);
88+
89+
/**
90+
* Deletes specific property keys from a server group.
91+
*
92+
* @param id the unique ID of the server group
93+
* @param keys the property keys to delete
94+
* @return a CompletableFuture that completes with the remaining properties
95+
*/
96+
CompletableFuture<Map<String, Object>> deleteGroupProperties(String id, List<String> keys);
7897
}
7998

api/src/main/java/app/simplecloud/api/internal/group/GroupApiImpl.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import app.simplecloud.api.web.apis.ServerGroupsApi;
77
import app.simplecloud.api.web.models.*;
88

9+
import java.util.HashMap;
910
import java.util.List;
11+
import java.util.Map;
1012
import java.util.concurrent.CompletableFuture;
1113

1214
public class GroupApiImpl implements GroupApi {
@@ -291,5 +293,49 @@ public CompletableFuture<Void> deleteGroup(String id) {
291293
}
292294
});
293295
}
296+
297+
@Override
298+
public CompletableFuture<Map<String, Object>> updateGroupProperties(String id, Map<String, Object> properties) {
299+
return CompletableFuture.supplyAsync(() -> {
300+
try {
301+
ModelsPatchPropertiesRequest request = new ModelsPatchPropertiesRequest();
302+
request.setProperties(properties);
303+
304+
ModelsPatchPropertiesResponse response = serverGroupsApi.v0ServerGroupsPropertiesPatch(
305+
this.options.getNetworkId(),
306+
this.options.getNetworkSecret(),
307+
id,
308+
request
309+
);
310+
311+
Map<String, Object> result = response.getProperties();
312+
return result != null ? result : new HashMap<>();
313+
} catch (ApiException e) {
314+
throw new RuntimeException(e);
315+
}
316+
});
317+
}
318+
319+
@Override
320+
public CompletableFuture<Map<String, Object>> deleteGroupProperties(String id, List<String> keys) {
321+
return CompletableFuture.supplyAsync(() -> {
322+
try {
323+
ModelsDeletePropertiesRequest request = new ModelsDeletePropertiesRequest();
324+
request.setKeys(keys);
325+
326+
ModelsDeletePropertiesResponse response = serverGroupsApi.v0ServerGroupsPropertiesDelete(
327+
this.options.getNetworkId(),
328+
this.options.getNetworkSecret(),
329+
id,
330+
request
331+
);
332+
333+
Map<String, Object> result = response.getProperties();
334+
return result != null ? result : new HashMap<>();
335+
} catch (ApiException e) {
336+
throw new RuntimeException(e);
337+
}
338+
});
339+
}
294340
}
295341

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
`signing`
1010
}
1111

12-
val baseVersion = "0.1.0-platform.2"
12+
val baseVersion = "0.1.0-platform.3"
1313
val commitHash = System.getenv("COMMIT_HASH")
1414
val isSnapshot = commitHash != null
1515

0 commit comments

Comments
 (0)