Finish mail settings management api
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package top.fatweb.api.service.system
|
||||
|
||||
import top.fatweb.api.param.system.MailSendParam
|
||||
import top.fatweb.api.param.system.MailSettingsParam
|
||||
import top.fatweb.api.vo.system.SettingsVo
|
||||
import top.fatweb.api.vo.system.MailSettingsVo
|
||||
|
||||
/**
|
||||
* Settings service interface
|
||||
@@ -11,21 +12,32 @@ import top.fatweb.api.vo.system.SettingsVo
|
||||
*/
|
||||
interface ISettingsService {
|
||||
/**
|
||||
* Get all settings
|
||||
* Get mail settings
|
||||
*
|
||||
* @return SettingVo object
|
||||
* @return MailSettingVo object
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see SettingsVo
|
||||
* @see MailSettingsVo
|
||||
*/
|
||||
fun get(): SettingsVo
|
||||
fun getMail(): MailSettingsVo?
|
||||
|
||||
/**
|
||||
* Update mail settings
|
||||
*
|
||||
* @param mailSettingsParam Mail settings parameters
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see MailSettingsParam
|
||||
*/
|
||||
fun updateMail(mailSettingsParam: MailSettingsParam)
|
||||
|
||||
/**
|
||||
* Send mail
|
||||
*
|
||||
* @param mailSendParam Send mail parameters
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see MailSettingsParam
|
||||
*/
|
||||
fun sendMail(mailSendParam: MailSendParam)
|
||||
}
|
||||
@@ -2,11 +2,14 @@ package top.fatweb.api.service.system.impl
|
||||
|
||||
import org.springframework.stereotype.Service
|
||||
import top.fatweb.api.converter.system.SettingsConverter
|
||||
import top.fatweb.api.param.system.MailSendParam
|
||||
import top.fatweb.api.param.system.MailSettingsParam
|
||||
import top.fatweb.api.properties.ServerProperties
|
||||
import top.fatweb.api.service.system.ISettingsService
|
||||
import top.fatweb.api.settings.MailSettings
|
||||
import top.fatweb.api.settings.SettingsOperator
|
||||
import top.fatweb.api.vo.system.SettingsVo
|
||||
import top.fatweb.api.util.MailUtil
|
||||
import top.fatweb.api.vo.system.MailSettingsVo
|
||||
|
||||
/**
|
||||
* Settings service implement
|
||||
@@ -17,15 +20,33 @@ import top.fatweb.api.vo.system.SettingsVo
|
||||
*/
|
||||
@Service
|
||||
class SettingsServiceImpl : ISettingsService {
|
||||
override fun get(): SettingsVo = SettingsConverter.systemSettingsToSettingsVo(SettingsOperator.settings())
|
||||
override fun getMail(): MailSettingsVo? = SettingsOperator.settings().mail?.let {
|
||||
SettingsConverter.mailSettingsToMailSettingsVo(
|
||||
it
|
||||
)
|
||||
}
|
||||
|
||||
override fun updateMail(mailSettingsParam: MailSettingsParam) {
|
||||
mailSettingsParam.apply {
|
||||
SettingsOperator.setMailValue(MailSettings::host, host)
|
||||
SettingsOperator.setMailValue(MailSettings::port, port)
|
||||
SettingsOperator.setMailValue(MailSettings::securityType, securityType)
|
||||
SettingsOperator.setMailValue(MailSettings::username, username)
|
||||
SettingsOperator.setMailValue(MailSettings::password, password)
|
||||
SettingsOperator.setMailValue(MailSettings::from, from)
|
||||
SettingsOperator.setMailValue(MailSettings::fromName, fromName)
|
||||
}
|
||||
|
||||
MailUtil.init()
|
||||
}
|
||||
|
||||
override fun sendMail(mailSendParam: MailSendParam) {
|
||||
mailSendParam.to?.let {
|
||||
MailUtil.sendSimpleMail(
|
||||
"${ServerProperties.appName} Test Message",
|
||||
"This is a test email sent when testing the system email sending service.",
|
||||
it
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user