Complete core functions #9
4
pom.xml
4
pom.xml
@@ -89,6 +89,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
<artifactId>jackson-module-kotlin</artifactId>
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package top.fatweb.api.controller.system
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation
|
||||
import io.swagger.v3.oas.annotations.tags.Tag
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import top.fatweb.api.entity.common.ResponseResult
|
||||
import top.fatweb.api.param.system.SettingParam
|
||||
import top.fatweb.api.service.system.ISysSettingService
|
||||
import top.fatweb.api.vo.system.SettingVo
|
||||
|
||||
/**
|
||||
* System setting controller
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Tag(name = "系统设置", description = "系统设置相关接口")
|
||||
@RequestMapping("/system/setting")
|
||||
@RestController
|
||||
class SettingController(
|
||||
private val sysSettingService: ISysSettingService
|
||||
) {
|
||||
@Operation(summary = "获取")
|
||||
fun get(): ResponseResult<SettingVo> = ResponseResult.success(data = sysSettingService.get())
|
||||
|
||||
@Operation(summary = "更新")
|
||||
fun update(settingParam: SettingParam): ResponseResult<Nothing> {
|
||||
sysSettingService.update(settingParam)
|
||||
return ResponseResult.success()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package top.fatweb.api.converter.system
|
||||
|
||||
import top.fatweb.api.param.system.SettingParam
|
||||
import top.fatweb.api.setting.MailSetting
|
||||
import top.fatweb.api.setting.SystemSetting
|
||||
import top.fatweb.api.vo.system.SettingVo
|
||||
|
||||
object SettingConverter {
|
||||
fun mailSettingToMailSettingVo(mailSetting: MailSetting) = SettingVo.MailSettingVo(
|
||||
host = mailSetting.host,
|
||||
port = mailSetting.port,
|
||||
username = mailSetting.username,
|
||||
password = mailSetting.password,
|
||||
from = mailSetting.from
|
||||
)
|
||||
|
||||
fun systemSettingToSettingVo(sysSetting: SystemSetting) = SettingVo(
|
||||
mail = sysSetting.mail?.let { mailSettingToMailSettingVo(it) }
|
||||
)
|
||||
|
||||
fun mailSettingParamToMailSetting(mailSettingParam: SettingParam.MailSettingParam) = MailSetting(
|
||||
host = mailSettingParam.host,
|
||||
port = mailSettingParam.port,
|
||||
username = mailSettingParam.username,
|
||||
password = mailSettingParam.password,
|
||||
from = mailSettingParam.from
|
||||
)
|
||||
|
||||
fun settingParamToSystemSetting(settingParam: SettingParam) = SystemSetting(
|
||||
mail = settingParam.mail?.let { mailSettingParamToMailSetting(it) }
|
||||
)
|
||||
}
|
||||
13
src/main/kotlin/top/fatweb/api/param/system/SettingParam.kt
Normal file
13
src/main/kotlin/top/fatweb/api/param/system/SettingParam.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package top.fatweb.api.param.system
|
||||
|
||||
data class SettingParam (
|
||||
val mail: MailSettingParam?
|
||||
) {
|
||||
data class MailSettingParam (
|
||||
val host: String,
|
||||
val port: Int,
|
||||
val username: String,
|
||||
val password: String,
|
||||
val from: String
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package top.fatweb.api.service.system
|
||||
|
||||
import top.fatweb.api.param.system.SettingParam
|
||||
import top.fatweb.api.vo.system.SettingVo
|
||||
|
||||
interface ISysSettingService {
|
||||
fun get(): SettingVo
|
||||
|
||||
fun update(settingParam: SettingParam)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package top.fatweb.api.service.system.impl
|
||||
|
||||
import org.springframework.stereotype.Service
|
||||
import top.fatweb.api.param.system.SettingParam
|
||||
import top.fatweb.api.service.system.ISysSettingService
|
||||
import top.fatweb.api.vo.system.SettingVo
|
||||
|
||||
@Service
|
||||
class SysSettingServiceImpl : ISysSettingService {
|
||||
override fun get(): SettingVo {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun update(settingParam: SettingParam) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
9
src/main/kotlin/top/fatweb/api/setting/MailSetting.kt
Normal file
9
src/main/kotlin/top/fatweb/api/setting/MailSetting.kt
Normal file
@@ -0,0 +1,9 @@
|
||||
package top.fatweb.api.setting
|
||||
|
||||
data class MailSetting(
|
||||
var host: String? = null,
|
||||
var port: Int? = null,
|
||||
var username: String? = null,
|
||||
var password: String? = null,
|
||||
var from: String? = null,
|
||||
)
|
||||
31
src/main/kotlin/top/fatweb/api/setting/SettingOperator.kt
Normal file
31
src/main/kotlin/top/fatweb/api/setting/SettingOperator.kt
Normal file
@@ -0,0 +1,31 @@
|
||||
package top.fatweb.api.setting
|
||||
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
object SettingOperator {
|
||||
const val SETTING_FILE_NAME = "data/config/setting.yaml"
|
||||
private val yamlMapper = YAMLMapper()
|
||||
|
||||
var systemSetting: SystemSetting? = null
|
||||
|
||||
fun init() {
|
||||
|
||||
}
|
||||
|
||||
fun getFromSettingFile(): SystemSetting {
|
||||
val settingFile = File(SETTING_FILE_NAME)
|
||||
if (!settingFile.isFile) {
|
||||
if (!settingFile.parentFile.isDirectory) {
|
||||
if (!settingFile.parentFile.mkdirs()) {
|
||||
throw IOException("Can not make directory: ${settingFile.parentFile.absolutePath}")
|
||||
}
|
||||
}
|
||||
settingFile.delete()
|
||||
settingFile.createNewFile()
|
||||
}
|
||||
return yamlMapper.readValue<SystemSetting>(settingFile)
|
||||
}
|
||||
}
|
||||
5
src/main/kotlin/top/fatweb/api/setting/SystemSetting.kt
Normal file
5
src/main/kotlin/top/fatweb/api/setting/SystemSetting.kt
Normal file
@@ -0,0 +1,5 @@
|
||||
package top.fatweb.api.setting
|
||||
|
||||
data class SystemSetting(
|
||||
var mail: MailSetting? = null
|
||||
)
|
||||
13
src/main/kotlin/top/fatweb/api/vo/system/SettingVo.kt
Normal file
13
src/main/kotlin/top/fatweb/api/vo/system/SettingVo.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package top.fatweb.api.vo.system
|
||||
|
||||
data class SettingVo(
|
||||
val mail: MailSettingVo?
|
||||
) {
|
||||
data class MailSettingVo(
|
||||
val host: String?,
|
||||
val port: Int?,
|
||||
val username: String?,
|
||||
val password: String?,
|
||||
val from: String?
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user