Skip to content

Commit

Permalink
feat: add logic to reply with daemon status on ping
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenSrcerer committed Mar 17, 2024
1 parent 87a37d8 commit 74a047f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class DaemonService(
private val rxMqttClient: RxMqttClient,
@RestClient private val paddyAuth: JwtAuthClient
) {
fun getDaemon(daemonId: String): Daemon? {
return daemonRepository.get(daemonId)
}

fun getAllUserDaemons(username: String): List<Daemon> {
val user = userRepository.get(username)
return daemonRepository.getAllUserDaemons(user!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ package online.danielstefani.paddy.mqtt

import io.quarkus.logging.Log
import jakarta.enterprise.context.ApplicationScoped
import online.danielstefani.paddy.daemon.DaemonService

@ApplicationScoped
class MqttController(
private val mqtt: RxMqttClient
private val mqtt: RxMqttClient,
private val daemonService: DaemonService
) {
@DaemonAction("hello")
@DaemonAction("ping")
fun hello(daemonId: String, body: String?) {
mqtt.publish(daemonId, "hello back!")
val on = daemonService.getDaemon(daemonId)?.on ?: return

mqtt.publish(daemonId, if (on) "1" else "0")
?.subscribe()
}

Expand Down

0 comments on commit 74a047f

Please sign in to comment.