Skip to content

Commit 2660ec8

Browse files
authored
Merge pull request #36 from simplecloudapp/feat/update-server
feat: updateServer api implementation
2 parents 74b8b29 + bf1df31 commit 2660ec8

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

controller-api/src/main/kotlin/app/simplecloud/controller/api/ServerApi.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ interface ServerApi {
107107
stopCause: ServerStopCause = ServerStopCause.API_STOP
108108
): CompletableFuture<List<Server>>
109109

110+
/**
111+
* @param server the [Server] to update.
112+
* @return the updated [Server].
113+
*/
114+
fun updateServer(server: Server): CompletableFuture<Server>
115+
110116
/**
111117
* @param id the id of the server.
112118
* @param state the new state of the server.
@@ -218,6 +224,12 @@ interface ServerApi {
218224
stopCause: ServerStopCause = ServerStopCause.API_STOP
219225
): List<Server>
220226

227+
/**
228+
* @param server the [Server] to update.
229+
* @return the updated [Server].
230+
*/
231+
suspend fun updateServer(server: Server): Server
232+
221233
/**
222234
* @param id the id of the server.
223235
* @param state the new state of the server.

controller-api/src/main/kotlin/app/simplecloud/controller/api/impl/coroutines/ServerApiCoroutineImpl.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ class ServerApiCoroutineImpl(
120120
}
121121
}
122122

123+
override suspend fun updateServer(server: Server): Server {
124+
return Server.fromDefinition(
125+
serverServiceStub.updateServer(updateServerRequest {
126+
this.server = server.toDefinition()
127+
})
128+
)
129+
}
130+
123131
override suspend fun updateServerState(id: String, state: ServerState): Server {
124132
return Server.fromDefinition(
125133
serverServiceStub.updateServerState(

controller-api/src/main/kotlin/app/simplecloud/controller/api/impl/future/ServerApiFutureImpl.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ class ServerApiFutureImpl(
133133
}
134134
}
135135

136+
override fun updateServer(server: Server): CompletableFuture<Server> {
137+
return serverServiceStub.updateServer(
138+
UpdateServerRequest.newBuilder()
139+
.setServer(server.toDefinition())
140+
.build()
141+
).toCompletable().thenApply {
142+
return@thenApply Server.fromDefinition(it)
143+
}
144+
}
145+
136146
override fun updateServerState(id: String, state: ServerState): CompletableFuture<Server> {
137147
return serverServiceStub.updateServerState(
138148
UpdateServerStateRequest.newBuilder()

0 commit comments

Comments
 (0)