Skip to content

Commit

Permalink
feat: add onRouterCreate event
Browse files Browse the repository at this point in the history
  • Loading branch information
duruer committed Jun 5, 2024
1 parent 6a1bfe0 commit a078778
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package co.statu.parsek.api.event

import co.statu.parsek.model.Route
import io.vertx.ext.web.Router

interface RouterEventListener : ParsekEventListener {

fun onInitRouteList(routes: MutableList<Route>)

fun onRouterCreate(router: Router)
}
6 changes: 5 additions & 1 deletion src/main/kotlin/co/statu/parsek/route/RouterProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ class RouterProvider private constructor(
val routerConfig = configManager.getConfig().getJsonObject("router")

val routeList = mutableListOf<Route>()
val routerEventHandlers = PluginEventManager.getParsekEventListeners<RouterEventListener>()

routerEventHandlers.forEach { eventHandler ->
eventHandler.onRouterCreate(router)
}

routeList.addAll(applicationContext.getBeansWithAnnotation(Endpoint::class.java).map { it.value as Route })
routeList.addAll(pluginManager.plugins.map {
Expand All @@ -76,7 +81,6 @@ class RouterProvider private constructor(
)
}.flatMap { it.values }.map { it as Route })

val routerEventHandlers = PluginEventManager.getParsekEventListeners<RouterEventListener>()

routerEventHandlers.forEach { eventHandler ->
eventHandler.onInitRouteList(routeList)
Expand Down

0 comments on commit a078778

Please sign in to comment.