-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a endpoint to provide system overview
- add new system route to handle system overview requests - implement system controller to manage system overview logic - create system service and service implementation for data retrieval - define new data classes for VO representations of system overview - update instance center to include system service initialization
- Loading branch information
Showing
6 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/main/kotlin/io/sakurasou/controller/SystemController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.sakurasou.controller | ||
|
||
import io.github.smiley4.ktorswaggerui.dsl.routing.get | ||
import io.github.smiley4.ktorswaggerui.dsl.routing.route | ||
import io.ktor.http.* | ||
import io.ktor.server.routing.* | ||
import io.sakurasou.constant.SETTING_READ | ||
import io.sakurasou.controller.vo.CommonResponse | ||
import io.sakurasou.controller.vo.SystemOverviewVO | ||
import io.sakurasou.extension.success | ||
import io.sakurasou.plugins.AuthorizationPlugin | ||
import io.sakurasou.service.system.SystemService | ||
|
||
/** | ||
* @author Shiina Kin | ||
* 2024/11/18 20:12 | ||
*/ | ||
|
||
fun Route.systemRoute(systemService: SystemService) { | ||
val controller = SystemController(systemService) | ||
route("system", { | ||
tags("system") | ||
protected = true | ||
}) { | ||
install(AuthorizationPlugin) { | ||
permission = SETTING_READ | ||
} | ||
systemOverview(controller) | ||
} | ||
} | ||
|
||
private fun Route.systemOverview(controller: SystemController) { | ||
route { | ||
get("overview", { | ||
response { | ||
HttpStatusCode.OK to { | ||
body<CommonResponse<SystemOverviewVO>> { | ||
description = "system overview" | ||
} | ||
} | ||
} | ||
}) { | ||
val systemOverviewVO = controller.handleSystemOverview() | ||
call.success(systemOverviewVO) | ||
} | ||
} | ||
} | ||
|
||
class SystemController( | ||
private val systemService: SystemService | ||
) { | ||
suspend fun handleSystemOverview(): SystemOverviewVO { | ||
val systemOverviewVO = systemService.fetchSystemOverview() | ||
return systemOverviewVO | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/src/main/kotlin/io/sakurasou/service/system/SystemService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.sakurasou.service.system | ||
|
||
import io.sakurasou.controller.vo.SystemOverviewVO | ||
|
||
/** | ||
* @author Shiina Kin | ||
* 2024/11/18 20:17 | ||
*/ | ||
interface SystemService { | ||
suspend fun fetchSystemOverview(): SystemOverviewVO | ||
} |
52 changes: 52 additions & 0 deletions
52
app/src/main/kotlin/io/sakurasou/service/system/SystemServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.sakurasou.service.system | ||
|
||
import io.sakurasou.controller.vo.HoshizoraStatusVO | ||
import io.sakurasou.controller.vo.SystemOverviewVO | ||
import io.sakurasou.controller.vo.SystemStatusVO | ||
import io.sakurasou.model.DatabaseSingleton.dbQuery | ||
import kotlinx.datetime.TimeZone | ||
import org.jetbrains.exposed.sql.transactions.TransactionManager | ||
import java.util.* | ||
|
||
/** | ||
* @author Shiina Kin | ||
* 2024/11/18 20:18 | ||
*/ | ||
class SystemServiceImpl: SystemService { | ||
override suspend fun fetchSystemOverview(): SystemOverviewVO { | ||
val buildRecord = Properties().also { | ||
it.load(this::class.java.classLoader.getResourceAsStream("buildRecord.properties")) | ||
} | ||
|
||
val hoshizoraStatus = HoshizoraStatusVO( | ||
buildTime = buildRecord["buildTime"] as String, | ||
commitId = buildRecord["commitId"] as String, | ||
version = buildRecord["version"] as String | ||
) | ||
|
||
val javaVersion = System.getProperty("java.version") | ||
val databaseVersion = dbQuery { | ||
TransactionManager.current().exec("SELECT VERSION()") { resultSet -> | ||
resultSet.next() | ||
resultSet.getString(1) | ||
} | ||
}!! | ||
val osName = System.getProperty("os.name") | ||
val osVersion = System.getProperty("os.version") | ||
val serverTimeZone = TimeZone.currentSystemDefault().id | ||
val serverLanguage = Locale.getDefault().language | ||
|
||
val systemStatusVO = SystemStatusVO( | ||
javaVersion = javaVersion, | ||
databaseVersion = databaseVersion, | ||
operatingSystem = "$osName $osVersion", | ||
serverTimeZone = serverTimeZone, | ||
serverLanguage = serverLanguage | ||
) | ||
|
||
return SystemOverviewVO( | ||
hoshizoraStatus = hoshizoraStatus, | ||
systemStatus = systemStatusVO | ||
) | ||
} | ||
} |