Skip to content

Commit

Permalink
feat: add support for custom names on daemons
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenSrcerer committed Apr 13, 2024
1 parent c5c7b2b commit 4da19cb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/online/danielstefani/paddy/daemon/Daemon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ open class Daemon() {
@Id @NotNull @Pattern(regexp = "\\d+")
var id: String? = null

var name: String? = null

var on: Boolean = false

// Wi-Fi Signal Strength
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.jboss.resteasy.reactive.RestResponse.*
@Produces(MediaType.APPLICATION_JSON)
@Authenticated
class DaemonController(
private val daemonRepository: DaemonRepository,
private val daemonService: DaemonService,
private val securityIdentity: SecurityIdentity
) {
Expand Down Expand Up @@ -47,6 +48,28 @@ class DaemonController(
}
}

@PATCH
@Path("/{id}")
fun patchDaemon(
@RestPath id: Long,
@NotNull daemon: Daemon
): RestResponse<Daemon> {
if (
daemon.name.isNullOrBlank() ||
daemon.name!!.length < 2 ||
daemon.name!!.length > 10
) {
return status(Response.Status.BAD_REQUEST)
}

val updatedDaemon = daemonRepository.update("$id") {
it.name = daemon.name
}

return if (updatedDaemon != null) ok(updatedDaemon)
else notFound()
}

@PATCH
@Path("/{id}/toggle")
fun toggleDaemon(@RestPath id: Long): RestResponse<Unit> {
Expand All @@ -62,12 +85,6 @@ class DaemonController(
?: status(Response.Status.NOT_FOUND)
}

@PATCH
@Path("/{id}")
fun patchDaemon(@RestPath id: Long): String {
return ":) Not Implemented Yet"
}

@DELETE
@Path("/{id}")
fun deleteDaemon(@RestPath id: Long): RestResponse<Daemon> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class DaemonRepository : AbstractNeo4jRepository() {

return Daemon().also {
it.id = id
it.name = "D-$id"
it.user = user

session().save(it)
Expand Down

0 comments on commit 4da19cb

Please sign in to comment.