From abca3486425663c1598b5bcdb3139fd04f8963f8 Mon Sep 17 00:00:00 2001 From: Shiina Kin Date: Tue, 24 Sep 2024 16:36:03 +0800 Subject: [PATCH] refactor: reorganize Exception --- .../io/sakurasou/controller/ImageController.kt | 2 +- .../io/sakurasou/controller/StrategyController.kt | 1 - .../sakurasou/exception/GroupNotExistException.kt | 12 ------------ .../exception/PermissionNotExistException.kt | 12 ------------ .../exception/PrincipalNotExistException.kt | 12 ------------ .../exception/StrategyNotExistException.kt | 12 ------------ .../access/PrincipalNotFoundException.kt | 14 ++++++++++++++ .../access}/SignupNotAllowedException.kt | 4 +++- .../{ => controller/param}/FileSizeException.kt | 4 +++- .../param}/PagingParameterWrongException.kt | 4 +++- .../param}/WrongParameterException.kt | 4 +++- .../status}/SiteNotInitializationException.kt | 4 +++- .../status}/SiteRepeatedInitializationException.kt | 4 +++- .../status}/UnauthorizedAccessException.kt | 4 +++- .../{ => dao}/MissingNecessaryColumnException.kt | 4 +++- .../service/group/GroupNotFoundException.kt | 14 ++++++++++++++ .../permission/PermissionNotFoundException.kt | 14 ++++++++++++++ .../role/RoleNotFoundException.kt} | 6 ++++-- .../setting}/ConfigTypeNotMatchException.kt | 4 +++- .../service/strategy/StrategyNotFoundException.kt | 14 ++++++++++++++ .../{ => service/user}/UserNotFoundException.kt | 6 ++++-- .../kotlin/io/sakurasou/extension/AuthExtension.kt | 6 ++---- .../io/sakurasou/extension/RouteExtension.kt | 2 +- .../io/sakurasou/model/dao/common/PaginationDao.kt | 2 +- .../kotlin/io/sakurasou/plugins/Authorization.kt | 6 +++--- .../main/kotlin/io/sakurasou/plugins/Routing.kt | 2 +- .../io/sakurasou/service/auth/AuthServiceImpl.kt | 4 ++-- .../sakurasou/service/common/CommonServiceImpl.kt | 2 +- .../io/sakurasou/service/group/GroupServiceImpl.kt | 8 ++++---- .../io/sakurasou/service/role/RoleServiceImpl.kt | 10 +++++----- .../service/setting/SettingServiceImpl.kt | 12 ++++++------ .../service/strategy/StrategyServiceImpl.kt | 4 ++-- .../io/sakurasou/service/user/UserServiceImpl.kt | 3 +-- .../io/sakurasou/service/auth/AuthServiceTest.kt | 4 ++-- .../sakurasou/service/common/CommonServiceTest.kt | 2 +- .../io/sakurasou/service/group/GroupServiceTest.kt | 4 ++-- .../service/strategy/StrategyServiceTest.kt | 4 ++-- .../io/sakurasou/service/user/UserServiceTest.kt | 2 +- 38 files changed, 129 insertions(+), 103 deletions(-) delete mode 100644 app/src/main/kotlin/io/sakurasou/exception/GroupNotExistException.kt delete mode 100644 app/src/main/kotlin/io/sakurasou/exception/PermissionNotExistException.kt delete mode 100644 app/src/main/kotlin/io/sakurasou/exception/PrincipalNotExistException.kt delete mode 100644 app/src/main/kotlin/io/sakurasou/exception/StrategyNotExistException.kt create mode 100644 app/src/main/kotlin/io/sakurasou/exception/controller/access/PrincipalNotFoundException.kt rename app/src/main/kotlin/io/sakurasou/exception/{ => controller/access}/SignupNotAllowedException.kt (70%) rename app/src/main/kotlin/io/sakurasou/exception/{ => controller/param}/FileSizeException.kt (70%) rename app/src/main/kotlin/io/sakurasou/exception/{ => controller/param}/PagingParameterWrongException.kt (69%) rename app/src/main/kotlin/io/sakurasou/exception/{ => controller/param}/WrongParameterException.kt (69%) rename app/src/main/kotlin/io/sakurasou/exception/{ => controller/status}/SiteNotInitializationException.kt (71%) rename app/src/main/kotlin/io/sakurasou/exception/{ => controller/status}/SiteRepeatedInitializationException.kt (71%) rename app/src/main/kotlin/io/sakurasou/exception/{ => controller/status}/UnauthorizedAccessException.kt (69%) rename app/src/main/kotlin/io/sakurasou/exception/{ => dao}/MissingNecessaryColumnException.kt (73%) create mode 100644 app/src/main/kotlin/io/sakurasou/exception/service/group/GroupNotFoundException.kt create mode 100644 app/src/main/kotlin/io/sakurasou/exception/service/permission/PermissionNotFoundException.kt rename app/src/main/kotlin/io/sakurasou/exception/{RoleNotExistException.kt => service/role/RoleNotFoundException.kt} (53%) rename app/src/main/kotlin/io/sakurasou/exception/{ => service/setting}/ConfigTypeNotMatchException.kt (70%) create mode 100644 app/src/main/kotlin/io/sakurasou/exception/service/strategy/StrategyNotFoundException.kt rename app/src/main/kotlin/io/sakurasou/exception/{ => service/user}/UserNotFoundException.kt (59%) diff --git a/app/src/main/kotlin/io/sakurasou/controller/ImageController.kt b/app/src/main/kotlin/io/sakurasou/controller/ImageController.kt index 3db8537e..5acb2d5e 100644 --- a/app/src/main/kotlin/io/sakurasou/controller/ImageController.kt +++ b/app/src/main/kotlin/io/sakurasou/controller/ImageController.kt @@ -12,7 +12,7 @@ import io.sakurasou.controller.vo.CommonResponse import io.sakurasou.controller.vo.ImagePageVO import io.sakurasou.controller.vo.ImageVO import io.sakurasou.controller.vo.PageResult -import io.sakurasou.exception.FileSizeException +import io.sakurasou.exception.controller.param.FileSizeException import io.sakurasou.extension.pageRequest import io.sakurasou.plugins.AuthorizationPlugin import java.io.ByteArrayOutputStream diff --git a/app/src/main/kotlin/io/sakurasou/controller/StrategyController.kt b/app/src/main/kotlin/io/sakurasou/controller/StrategyController.kt index a92f6d9c..82c445e5 100644 --- a/app/src/main/kotlin/io/sakurasou/controller/StrategyController.kt +++ b/app/src/main/kotlin/io/sakurasou/controller/StrategyController.kt @@ -20,7 +20,6 @@ import io.sakurasou.controller.vo.CommonResponse import io.sakurasou.controller.vo.PageResult import io.sakurasou.controller.vo.StrategyPageVO import io.sakurasou.controller.vo.StrategyVO -import io.sakurasou.exception.WrongParameterException import io.sakurasou.extension.id import io.sakurasou.extension.pageRequest import io.sakurasou.extension.success diff --git a/app/src/main/kotlin/io/sakurasou/exception/GroupNotExistException.kt b/app/src/main/kotlin/io/sakurasou/exception/GroupNotExistException.kt deleted file mode 100644 index c9958d35..00000000 --- a/app/src/main/kotlin/io/sakurasou/exception/GroupNotExistException.kt +++ /dev/null @@ -1,12 +0,0 @@ -package io.sakurasou.exception - -/** - * @author Shiina Kin - * 2024/9/24 13:59 - */ -class GroupNotExistException : ServiceThrowable() { - override val code: Int - get() = 4004 - override val message: String - get() = "Group Not Exist" -} \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/exception/PermissionNotExistException.kt b/app/src/main/kotlin/io/sakurasou/exception/PermissionNotExistException.kt deleted file mode 100644 index 9a86ab1e..00000000 --- a/app/src/main/kotlin/io/sakurasou/exception/PermissionNotExistException.kt +++ /dev/null @@ -1,12 +0,0 @@ -package io.sakurasou.exception - -/** - * @author ShiinaKin - * 2024/9/18 17:40 - */ -class PermissionNotExistException: ServiceThrowable() { - override val code: Int - get() = 4004 - override val message: String - get() = "Permission Not Exist" -} \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/exception/PrincipalNotExistException.kt b/app/src/main/kotlin/io/sakurasou/exception/PrincipalNotExistException.kt deleted file mode 100644 index a651bf5f..00000000 --- a/app/src/main/kotlin/io/sakurasou/exception/PrincipalNotExistException.kt +++ /dev/null @@ -1,12 +0,0 @@ -package io.sakurasou.exception - -/** - * @author Shiina Kin - * 2024/9/12 11:08 - */ -class PrincipalNotExistException : ServiceThrowable() { - override val code: Int - get() = 5001 - override val message: String - get() = "Principal not exist" -} \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/exception/StrategyNotExistException.kt b/app/src/main/kotlin/io/sakurasou/exception/StrategyNotExistException.kt deleted file mode 100644 index 7106680c..00000000 --- a/app/src/main/kotlin/io/sakurasou/exception/StrategyNotExistException.kt +++ /dev/null @@ -1,12 +0,0 @@ -package io.sakurasou.exception - -/** - * @author Shiina Kin - * 2024/9/23 08:22 - */ -class StrategyNotExistException : ServiceThrowable() { - override val code: Int - get() = 4004 - override val message: String - get() = "Strategy Not Exist" -} \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/exception/controller/access/PrincipalNotFoundException.kt b/app/src/main/kotlin/io/sakurasou/exception/controller/access/PrincipalNotFoundException.kt new file mode 100644 index 00000000..25c2673e --- /dev/null +++ b/app/src/main/kotlin/io/sakurasou/exception/controller/access/PrincipalNotFoundException.kt @@ -0,0 +1,14 @@ +package io.sakurasou.exception.controller.access + +import io.sakurasou.exception.ServiceThrowable + +/** + * @author Shiina Kin + * 2024/9/12 11:08 + */ +class PrincipalNotFoundException : ServiceThrowable() { + override val code: Int + get() = 5001 + override val message: String + get() = "Principal Not Found" +} \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/exception/SignupNotAllowedException.kt b/app/src/main/kotlin/io/sakurasou/exception/controller/access/SignupNotAllowedException.kt similarity index 70% rename from app/src/main/kotlin/io/sakurasou/exception/SignupNotAllowedException.kt rename to app/src/main/kotlin/io/sakurasou/exception/controller/access/SignupNotAllowedException.kt index c6cd1391..87f55a84 100644 --- a/app/src/main/kotlin/io/sakurasou/exception/SignupNotAllowedException.kt +++ b/app/src/main/kotlin/io/sakurasou/exception/controller/access/SignupNotAllowedException.kt @@ -1,4 +1,6 @@ -package io.sakurasou.exception +package io.sakurasou.exception.controller.access + +import io.sakurasou.exception.ServiceThrowable /** * @author Shiina Kin diff --git a/app/src/main/kotlin/io/sakurasou/exception/FileSizeException.kt b/app/src/main/kotlin/io/sakurasou/exception/controller/param/FileSizeException.kt similarity index 70% rename from app/src/main/kotlin/io/sakurasou/exception/FileSizeException.kt rename to app/src/main/kotlin/io/sakurasou/exception/controller/param/FileSizeException.kt index a6930a00..ce417e6d 100644 --- a/app/src/main/kotlin/io/sakurasou/exception/FileSizeException.kt +++ b/app/src/main/kotlin/io/sakurasou/exception/controller/param/FileSizeException.kt @@ -1,4 +1,6 @@ -package io.sakurasou.exception +package io.sakurasou.exception.controller.param + +import io.sakurasou.exception.ServiceThrowable /** * @author Shiina Kin diff --git a/app/src/main/kotlin/io/sakurasou/exception/PagingParameterWrongException.kt b/app/src/main/kotlin/io/sakurasou/exception/controller/param/PagingParameterWrongException.kt similarity index 69% rename from app/src/main/kotlin/io/sakurasou/exception/PagingParameterWrongException.kt rename to app/src/main/kotlin/io/sakurasou/exception/controller/param/PagingParameterWrongException.kt index 5d5fdca6..835791f5 100644 --- a/app/src/main/kotlin/io/sakurasou/exception/PagingParameterWrongException.kt +++ b/app/src/main/kotlin/io/sakurasou/exception/controller/param/PagingParameterWrongException.kt @@ -1,4 +1,6 @@ -package io.sakurasou.exception +package io.sakurasou.exception.controller.param + +import io.sakurasou.exception.ServiceThrowable /** * @author Shiina Kin diff --git a/app/src/main/kotlin/io/sakurasou/exception/WrongParameterException.kt b/app/src/main/kotlin/io/sakurasou/exception/controller/param/WrongParameterException.kt similarity index 69% rename from app/src/main/kotlin/io/sakurasou/exception/WrongParameterException.kt rename to app/src/main/kotlin/io/sakurasou/exception/controller/param/WrongParameterException.kt index adb56540..bee6369a 100644 --- a/app/src/main/kotlin/io/sakurasou/exception/WrongParameterException.kt +++ b/app/src/main/kotlin/io/sakurasou/exception/controller/param/WrongParameterException.kt @@ -1,4 +1,6 @@ -package io.sakurasou.exception +package io.sakurasou.exception.controller.param + +import io.sakurasou.exception.ServiceThrowable /** * @author Shiina Kin diff --git a/app/src/main/kotlin/io/sakurasou/exception/SiteNotInitializationException.kt b/app/src/main/kotlin/io/sakurasou/exception/controller/status/SiteNotInitializationException.kt similarity index 71% rename from app/src/main/kotlin/io/sakurasou/exception/SiteNotInitializationException.kt rename to app/src/main/kotlin/io/sakurasou/exception/controller/status/SiteNotInitializationException.kt index 6314768f..7cc5387c 100644 --- a/app/src/main/kotlin/io/sakurasou/exception/SiteNotInitializationException.kt +++ b/app/src/main/kotlin/io/sakurasou/exception/controller/status/SiteNotInitializationException.kt @@ -1,4 +1,6 @@ -package io.sakurasou.exception +package io.sakurasou.exception.controller.status + +import io.sakurasou.exception.ServiceThrowable /** * @author Shiina Kin diff --git a/app/src/main/kotlin/io/sakurasou/exception/SiteRepeatedInitializationException.kt b/app/src/main/kotlin/io/sakurasou/exception/controller/status/SiteRepeatedInitializationException.kt similarity index 71% rename from app/src/main/kotlin/io/sakurasou/exception/SiteRepeatedInitializationException.kt rename to app/src/main/kotlin/io/sakurasou/exception/controller/status/SiteRepeatedInitializationException.kt index 4de6d381..bfa817b1 100644 --- a/app/src/main/kotlin/io/sakurasou/exception/SiteRepeatedInitializationException.kt +++ b/app/src/main/kotlin/io/sakurasou/exception/controller/status/SiteRepeatedInitializationException.kt @@ -1,4 +1,6 @@ -package io.sakurasou.exception +package io.sakurasou.exception.controller.status + +import io.sakurasou.exception.ServiceThrowable /** * @author Shiina Kin diff --git a/app/src/main/kotlin/io/sakurasou/exception/UnauthorizedAccessException.kt b/app/src/main/kotlin/io/sakurasou/exception/controller/status/UnauthorizedAccessException.kt similarity index 69% rename from app/src/main/kotlin/io/sakurasou/exception/UnauthorizedAccessException.kt rename to app/src/main/kotlin/io/sakurasou/exception/controller/status/UnauthorizedAccessException.kt index f89d4f40..1307a73a 100644 --- a/app/src/main/kotlin/io/sakurasou/exception/UnauthorizedAccessException.kt +++ b/app/src/main/kotlin/io/sakurasou/exception/controller/status/UnauthorizedAccessException.kt @@ -1,4 +1,6 @@ -package io.sakurasou.exception +package io.sakurasou.exception.controller.status + +import io.sakurasou.exception.ServiceThrowable /** * @author Shiina Kin diff --git a/app/src/main/kotlin/io/sakurasou/exception/MissingNecessaryColumnException.kt b/app/src/main/kotlin/io/sakurasou/exception/dao/MissingNecessaryColumnException.kt similarity index 73% rename from app/src/main/kotlin/io/sakurasou/exception/MissingNecessaryColumnException.kt rename to app/src/main/kotlin/io/sakurasou/exception/dao/MissingNecessaryColumnException.kt index 6e482de9..31443818 100644 --- a/app/src/main/kotlin/io/sakurasou/exception/MissingNecessaryColumnException.kt +++ b/app/src/main/kotlin/io/sakurasou/exception/dao/MissingNecessaryColumnException.kt @@ -1,4 +1,6 @@ -package io.sakurasou.exception +package io.sakurasou.exception.dao + +import io.sakurasou.exception.ServiceThrowable /** * @author Shiina Kin diff --git a/app/src/main/kotlin/io/sakurasou/exception/service/group/GroupNotFoundException.kt b/app/src/main/kotlin/io/sakurasou/exception/service/group/GroupNotFoundException.kt new file mode 100644 index 00000000..b6b3a9c0 --- /dev/null +++ b/app/src/main/kotlin/io/sakurasou/exception/service/group/GroupNotFoundException.kt @@ -0,0 +1,14 @@ +package io.sakurasou.exception.service.group + +import io.sakurasou.exception.ServiceThrowable + +/** + * @author Shiina Kin + * 2024/9/24 13:59 + */ +class GroupNotFoundException : ServiceThrowable() { + override val code: Int + get() = 4004 + override val message: String + get() = "Group Not Found" +} \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/exception/service/permission/PermissionNotFoundException.kt b/app/src/main/kotlin/io/sakurasou/exception/service/permission/PermissionNotFoundException.kt new file mode 100644 index 00000000..3cd3c735 --- /dev/null +++ b/app/src/main/kotlin/io/sakurasou/exception/service/permission/PermissionNotFoundException.kt @@ -0,0 +1,14 @@ +package io.sakurasou.exception.service.permission + +import io.sakurasou.exception.ServiceThrowable + +/** + * @author ShiinaKin + * 2024/9/18 17:40 + */ +class PermissionNotFoundException: ServiceThrowable() { + override val code: Int + get() = 4004 + override val message: String + get() = "Permission Not Found" +} \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/exception/RoleNotExistException.kt b/app/src/main/kotlin/io/sakurasou/exception/service/role/RoleNotFoundException.kt similarity index 53% rename from app/src/main/kotlin/io/sakurasou/exception/RoleNotExistException.kt rename to app/src/main/kotlin/io/sakurasou/exception/service/role/RoleNotFoundException.kt index 8d20a8f4..0fd80015 100644 --- a/app/src/main/kotlin/io/sakurasou/exception/RoleNotExistException.kt +++ b/app/src/main/kotlin/io/sakurasou/exception/service/role/RoleNotFoundException.kt @@ -1,10 +1,12 @@ -package io.sakurasou.exception +package io.sakurasou.exception.service.role + +import io.sakurasou.exception.ServiceThrowable /** * @author ShiinaKin * 2024/9/18 17:40 */ -class RoleNotExistException: ServiceThrowable() { +class RoleNotFoundException: ServiceThrowable() { override val code: Int get() = 4004 override val message: String diff --git a/app/src/main/kotlin/io/sakurasou/exception/ConfigTypeNotMatchException.kt b/app/src/main/kotlin/io/sakurasou/exception/service/setting/ConfigTypeNotMatchException.kt similarity index 70% rename from app/src/main/kotlin/io/sakurasou/exception/ConfigTypeNotMatchException.kt rename to app/src/main/kotlin/io/sakurasou/exception/service/setting/ConfigTypeNotMatchException.kt index 5000960a..29dfc9a4 100644 --- a/app/src/main/kotlin/io/sakurasou/exception/ConfigTypeNotMatchException.kt +++ b/app/src/main/kotlin/io/sakurasou/exception/service/setting/ConfigTypeNotMatchException.kt @@ -1,4 +1,6 @@ -package io.sakurasou.exception +package io.sakurasou.exception.service.setting + +import io.sakurasou.exception.ServiceThrowable /** * @author Shiina Kin diff --git a/app/src/main/kotlin/io/sakurasou/exception/service/strategy/StrategyNotFoundException.kt b/app/src/main/kotlin/io/sakurasou/exception/service/strategy/StrategyNotFoundException.kt new file mode 100644 index 00000000..b11bf82a --- /dev/null +++ b/app/src/main/kotlin/io/sakurasou/exception/service/strategy/StrategyNotFoundException.kt @@ -0,0 +1,14 @@ +package io.sakurasou.exception.service.strategy + +import io.sakurasou.exception.ServiceThrowable + +/** + * @author Shiina Kin + * 2024/9/23 08:22 + */ +class StrategyNotFoundException : ServiceThrowable() { + override val code: Int + get() = 4004 + override val message: String + get() = "Strategy Not Found" +} \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/exception/UserNotFoundException.kt b/app/src/main/kotlin/io/sakurasou/exception/service/user/UserNotFoundException.kt similarity index 59% rename from app/src/main/kotlin/io/sakurasou/exception/UserNotFoundException.kt rename to app/src/main/kotlin/io/sakurasou/exception/service/user/UserNotFoundException.kt index 208ff561..5184d01d 100644 --- a/app/src/main/kotlin/io/sakurasou/exception/UserNotFoundException.kt +++ b/app/src/main/kotlin/io/sakurasou/exception/service/user/UserNotFoundException.kt @@ -1,4 +1,6 @@ -package io.sakurasou.exception +package io.sakurasou.exception.service.user + +import io.sakurasou.exception.ServiceThrowable /** * @author Shiina Kin @@ -8,5 +10,5 @@ class UserNotFoundException : ServiceThrowable() { override val code: Int get() = 404 override val message: String - get() = "User not found" + get() = "User Not Found" } \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/extension/AuthExtension.kt b/app/src/main/kotlin/io/sakurasou/extension/AuthExtension.kt index f3d85b51..d81e3889 100644 --- a/app/src/main/kotlin/io/sakurasou/extension/AuthExtension.kt +++ b/app/src/main/kotlin/io/sakurasou/extension/AuthExtension.kt @@ -2,9 +2,7 @@ package io.sakurasou.extension import io.ktor.server.application.* import io.ktor.util.* -import io.sakurasou.config.InstanceCenter -import io.sakurasou.exception.PrincipalNotExistException -import io.sakurasou.model.DatabaseSingleton.dbQuery +import io.sakurasou.exception.controller.access.PrincipalNotFoundException import kotlinx.serialization.Serializable /** @@ -15,5 +13,5 @@ import kotlinx.serialization.Serializable data class Principal(val id: Long, val groupId: Long, val username: String, val roles: List) fun ApplicationCall.getPrincipal(): Principal { - return attributes.getOrNull(AttributeKey("principal")) ?: throw PrincipalNotExistException() + return attributes.getOrNull(AttributeKey("principal")) ?: throw PrincipalNotFoundException() } \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/extension/RouteExtension.kt b/app/src/main/kotlin/io/sakurasou/extension/RouteExtension.kt index 05b08294..eca03469 100644 --- a/app/src/main/kotlin/io/sakurasou/extension/RouteExtension.kt +++ b/app/src/main/kotlin/io/sakurasou/extension/RouteExtension.kt @@ -7,7 +7,7 @@ import io.sakurasou.config.InstanceCenter import io.sakurasou.controller.request.PageRequest import io.sakurasou.controller.vo.CommonResponse import io.sakurasou.exception.ServiceThrowable -import io.sakurasou.exception.WrongParameterException +import io.sakurasou.exception.controller.param.WrongParameterException /** * @author Shiina Kin diff --git a/app/src/main/kotlin/io/sakurasou/model/dao/common/PaginationDao.kt b/app/src/main/kotlin/io/sakurasou/model/dao/common/PaginationDao.kt index 3b2daa03..912c7954 100644 --- a/app/src/main/kotlin/io/sakurasou/model/dao/common/PaginationDao.kt +++ b/app/src/main/kotlin/io/sakurasou/model/dao/common/PaginationDao.kt @@ -2,7 +2,7 @@ package io.sakurasou.model.dao.common import io.sakurasou.controller.request.PageRequest import io.sakurasou.controller.vo.PageResult -import io.sakurasou.exception.PagingParameterWrongException +import io.sakurasou.exception.controller.param.PagingParameterWrongException import io.sakurasou.model.dao.group.Groups import io.sakurasou.model.dao.strategy.Strategies import org.jetbrains.exposed.sql.* diff --git a/app/src/main/kotlin/io/sakurasou/plugins/Authorization.kt b/app/src/main/kotlin/io/sakurasou/plugins/Authorization.kt index d363bcf1..22fb0459 100644 --- a/app/src/main/kotlin/io/sakurasou/plugins/Authorization.kt +++ b/app/src/main/kotlin/io/sakurasou/plugins/Authorization.kt @@ -5,8 +5,8 @@ import io.ktor.server.auth.* import io.ktor.server.auth.jwt.* import io.ktor.util.* import io.sakurasou.config.InstanceCenter -import io.sakurasou.exception.PrincipalNotExistException -import io.sakurasou.exception.UnauthorizedAccessException +import io.sakurasou.exception.controller.access.PrincipalNotFoundException +import io.sakurasou.exception.controller.status.UnauthorizedAccessException import io.sakurasou.extension.Principal /** @@ -19,7 +19,7 @@ val AuthorizationPlugin = createRouteScopedPlugin( ) { pluginConfig.apply { on(AuthenticationChecked) { call -> - val principal = call.principal() ?: throw PrincipalNotExistException() + val principal = call.principal() ?: throw PrincipalNotFoundException() val id = principal.payload.getClaim("id").asLong() val groupId = principal.payload.getClaim("groupId").asLong() val username = principal.payload.getClaim("username").asString() diff --git a/app/src/main/kotlin/io/sakurasou/plugins/Routing.kt b/app/src/main/kotlin/io/sakurasou/plugins/Routing.kt index 3fbea7e7..e65c1347 100644 --- a/app/src/main/kotlin/io/sakurasou/plugins/Routing.kt +++ b/app/src/main/kotlin/io/sakurasou/plugins/Routing.kt @@ -21,7 +21,7 @@ import io.sakurasou.config.InstanceCenter.strategyService import io.sakurasou.config.InstanceCenter.userService import io.sakurasou.controller.* import io.sakurasou.exception.ServiceThrowable -import io.sakurasou.exception.SiteNotInitializationException +import io.sakurasou.exception.controller.status.SiteNotInitializationException import io.sakurasou.extension.failure import io.sakurasou.extension.isSiteNotInitialized import org.jetbrains.exposed.sql.exposedLogger diff --git a/app/src/main/kotlin/io/sakurasou/service/auth/AuthServiceImpl.kt b/app/src/main/kotlin/io/sakurasou/service/auth/AuthServiceImpl.kt index 037cb6cf..a5fb28f8 100644 --- a/app/src/main/kotlin/io/sakurasou/service/auth/AuthServiceImpl.kt +++ b/app/src/main/kotlin/io/sakurasou/service/auth/AuthServiceImpl.kt @@ -2,8 +2,8 @@ package io.sakurasou.service.auth import at.favre.lib.crypto.bcrypt.BCrypt import io.sakurasou.controller.request.UserLoginRequest -import io.sakurasou.exception.UnauthorizedAccessException -import io.sakurasou.exception.UserNotFoundException +import io.sakurasou.exception.controller.status.UnauthorizedAccessException +import io.sakurasou.exception.service.user.UserNotFoundException import io.sakurasou.model.DatabaseSingleton.dbQuery import io.sakurasou.model.dao.relation.RelationDao import io.sakurasou.model.dao.user.UserDao diff --git a/app/src/main/kotlin/io/sakurasou/service/common/CommonServiceImpl.kt b/app/src/main/kotlin/io/sakurasou/service/common/CommonServiceImpl.kt index 77529fcf..f397c4b0 100644 --- a/app/src/main/kotlin/io/sakurasou/service/common/CommonServiceImpl.kt +++ b/app/src/main/kotlin/io/sakurasou/service/common/CommonServiceImpl.kt @@ -3,7 +3,7 @@ package io.sakurasou.service.common import at.favre.lib.crypto.bcrypt.BCrypt import io.sakurasou.config.InstanceCenter import io.sakurasou.controller.request.SiteInitRequest -import io.sakurasou.exception.SiteRepeatedInitializationException +import io.sakurasou.exception.controller.status.SiteRepeatedInitializationException import io.sakurasou.model.DatabaseSingleton.dbQuery import io.sakurasou.model.dao.album.AlbumDao import io.sakurasou.model.dao.user.UserDao diff --git a/app/src/main/kotlin/io/sakurasou/service/group/GroupServiceImpl.kt b/app/src/main/kotlin/io/sakurasou/service/group/GroupServiceImpl.kt index 632108f6..d5f544fa 100644 --- a/app/src/main/kotlin/io/sakurasou/service/group/GroupServiceImpl.kt +++ b/app/src/main/kotlin/io/sakurasou/service/group/GroupServiceImpl.kt @@ -6,8 +6,8 @@ import io.sakurasou.controller.request.PageRequest import io.sakurasou.controller.vo.GroupPageVO import io.sakurasou.controller.vo.GroupVO import io.sakurasou.controller.vo.PageResult -import io.sakurasou.exception.GroupNotExistException -import io.sakurasou.exception.RoleNotExistException +import io.sakurasou.exception.service.group.GroupNotFoundException +import io.sakurasou.exception.service.role.RoleNotFoundException import io.sakurasou.model.DatabaseSingleton.dbQuery import io.sakurasou.model.dao.group.GroupDao import io.sakurasou.model.dao.relation.RelationDao @@ -36,7 +36,7 @@ class GroupServiceImpl( runCatching { relationDao.batchInsertGroupToRoles(groupId, groupRoles) }.onFailure { - throw RoleNotExistException() + throw RoleNotFoundException() } } } @@ -60,7 +60,7 @@ class GroupServiceImpl( } override suspend fun fetchGroup(id: Long): GroupVO { - val group = dbQuery { groupDao.findGroupById(id) } ?: throw GroupNotExistException() + val group = dbQuery { groupDao.findGroupById(id) } ?: throw GroupNotFoundException() val roles = dbQuery { relationDao.listRoleByGroupId(group.id) } return GroupVO( id = group.id, diff --git a/app/src/main/kotlin/io/sakurasou/service/role/RoleServiceImpl.kt b/app/src/main/kotlin/io/sakurasou/service/role/RoleServiceImpl.kt index 8a8611f9..24711da2 100644 --- a/app/src/main/kotlin/io/sakurasou/service/role/RoleServiceImpl.kt +++ b/app/src/main/kotlin/io/sakurasou/service/role/RoleServiceImpl.kt @@ -2,8 +2,8 @@ package io.sakurasou.service.role import io.sakurasou.controller.vo.PermissionVO import io.sakurasou.controller.vo.RoleVO -import io.sakurasou.exception.PermissionNotExistException -import io.sakurasou.exception.RoleNotExistException +import io.sakurasou.exception.service.permission.PermissionNotFoundException +import io.sakurasou.exception.service.role.RoleNotFoundException import io.sakurasou.model.DatabaseSingleton.dbQuery import io.sakurasou.model.dao.permission.PermissionDao import io.sakurasou.model.dao.relation.RelationDao @@ -25,7 +25,7 @@ class RoleServiceImpl( val permissionNames = relationDao.listPermissionByRole(role.name) val permissionVOList = permissionNames.map { permissionName -> val permission = permissionDao.findPermissionByName(permissionName) - ?: throw PermissionNotExistException() + ?: throw PermissionNotFoundException() PermissionVO( permission.name, permission.description @@ -43,11 +43,11 @@ class RoleServiceImpl( override suspend fun listRolesWithPermissionsOfUser(roleNames: List): Map { return dbQuery { roleNames.associate { roleName -> - val role = roleDao.findRoleByName(roleName) ?: throw RoleNotExistException() + val role = roleDao.findRoleByName(roleName) ?: throw RoleNotFoundException() val permissionNames = relationDao.listPermissionByRole(roleName) val permissionVOList = permissionNames.map { permissionName -> val permission = permissionDao.findPermissionByName(permissionName) - ?: throw PermissionNotExistException() + ?: throw PermissionNotFoundException() PermissionVO( permission.name, permission.description diff --git a/app/src/main/kotlin/io/sakurasou/service/setting/SettingServiceImpl.kt b/app/src/main/kotlin/io/sakurasou/service/setting/SettingServiceImpl.kt index b76aa233..1fa4e5cc 100644 --- a/app/src/main/kotlin/io/sakurasou/service/setting/SettingServiceImpl.kt +++ b/app/src/main/kotlin/io/sakurasou/service/setting/SettingServiceImpl.kt @@ -7,8 +7,8 @@ import io.sakurasou.constant.SETTING_SYSTEM import io.sakurasou.controller.request.SiteSettingPatchRequest import io.sakurasou.controller.request.StrategySettingPatchRequest import io.sakurasou.controller.request.SystemSettingPatchRequest -import io.sakurasou.exception.ConfigTypeNotMatchException -import io.sakurasou.exception.MissingNecessaryColumnException +import io.sakurasou.exception.service.setting.ConfigTypeNotMatchException +import io.sakurasou.exception.dao.MissingNecessaryColumnException import io.sakurasou.model.DatabaseSingleton.dbQuery import io.sakurasou.model.dao.setting.SettingDao import io.sakurasou.model.dto.SettingUpdateDTO @@ -110,7 +110,7 @@ class SettingServiceImpl( }?.let { if (it.config !is SystemSetting) throw ConfigTypeNotMatchException() it.config - } ?: run { throw MissingNecessaryColumnException() } + } ?: throw MissingNecessaryColumnException() } override suspend fun getSiteSetting(): SiteSetting { @@ -119,7 +119,7 @@ class SettingServiceImpl( }?.let { if (it.config !is SiteSetting) throw ConfigTypeNotMatchException() it.config - } ?: run { throw MissingNecessaryColumnException() } + } ?: throw MissingNecessaryColumnException() } override suspend fun getStrategySetting(): StrategySetting { @@ -128,7 +128,7 @@ class SettingServiceImpl( }?.let { if (it.config !is StrategySetting) throw ConfigTypeNotMatchException() it.config - } ?: run { throw MissingNecessaryColumnException() } + } ?: throw MissingNecessaryColumnException() } override suspend fun getSystemStatus(): SystemStatus { @@ -137,6 +137,6 @@ class SettingServiceImpl( }?.let { if (it.config !is SystemStatus) throw ConfigTypeNotMatchException() it.config - } ?: run { throw MissingNecessaryColumnException() } + } ?: throw MissingNecessaryColumnException() } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/service/strategy/StrategyServiceImpl.kt b/app/src/main/kotlin/io/sakurasou/service/strategy/StrategyServiceImpl.kt index 94381a3c..877e48ed 100644 --- a/app/src/main/kotlin/io/sakurasou/service/strategy/StrategyServiceImpl.kt +++ b/app/src/main/kotlin/io/sakurasou/service/strategy/StrategyServiceImpl.kt @@ -6,7 +6,7 @@ import io.sakurasou.controller.request.StrategyPatchRequest import io.sakurasou.controller.vo.PageResult import io.sakurasou.controller.vo.StrategyPageVO import io.sakurasou.controller.vo.StrategyVO -import io.sakurasou.exception.StrategyNotExistException +import io.sakurasou.exception.service.strategy.StrategyNotFoundException import io.sakurasou.model.DatabaseSingleton.dbQuery import io.sakurasou.model.dao.strategy.StrategyDao import io.sakurasou.model.dto.StrategyInsertDTO @@ -53,7 +53,7 @@ class StrategyServiceImpl( } override suspend fun fetchStrategy(id: Long): StrategyVO { - val strategy = dbQuery { strategyDao.findStrategyById(id) } ?: throw StrategyNotExistException() + val strategy = dbQuery { strategyDao.findStrategyById(id) } ?: throw StrategyNotFoundException() val strategyVO = StrategyVO( id = strategy.id, name = strategy.name, diff --git a/app/src/main/kotlin/io/sakurasou/service/user/UserServiceImpl.kt b/app/src/main/kotlin/io/sakurasou/service/user/UserServiceImpl.kt index b7fccca6..60448451 100644 --- a/app/src/main/kotlin/io/sakurasou/service/user/UserServiceImpl.kt +++ b/app/src/main/kotlin/io/sakurasou/service/user/UserServiceImpl.kt @@ -2,7 +2,7 @@ package io.sakurasou.service.user import at.favre.lib.crypto.bcrypt.BCrypt import io.sakurasou.controller.request.UserInsertRequest -import io.sakurasou.exception.SignupNotAllowedException +import io.sakurasou.exception.controller.access.SignupNotAllowedException import io.sakurasou.model.DatabaseSingleton.dbQuery import io.sakurasou.model.dao.album.AlbumDao import io.sakurasou.model.dao.user.UserDao @@ -28,7 +28,6 @@ class UserServiceImpl( val rawPassword = userInsertRequest.password val encodePassword = BCrypt.withDefaults().hashToString(12, rawPassword.toCharArray()) - val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()) val userInsertDTO = UserInsertDTO( groupId = systemSetting.defaultGroupId, diff --git a/app/src/test/kotlin/io/sakurasou/service/auth/AuthServiceTest.kt b/app/src/test/kotlin/io/sakurasou/service/auth/AuthServiceTest.kt index 02eb33d7..e5e82803 100644 --- a/app/src/test/kotlin/io/sakurasou/service/auth/AuthServiceTest.kt +++ b/app/src/test/kotlin/io/sakurasou/service/auth/AuthServiceTest.kt @@ -3,8 +3,8 @@ package io.sakurasou.service.auth import at.favre.lib.crypto.bcrypt.BCrypt import io.mockk.* import io.sakurasou.controller.request.UserLoginRequest -import io.sakurasou.exception.UnauthorizedAccessException -import io.sakurasou.exception.UserNotFoundException +import io.sakurasou.exception.controller.status.UnauthorizedAccessException +import io.sakurasou.exception.service.user.UserNotFoundException import io.sakurasou.model.DatabaseSingleton import io.sakurasou.model.dao.relation.RelationDao import io.sakurasou.model.dao.user.UserDao diff --git a/app/src/test/kotlin/io/sakurasou/service/common/CommonServiceTest.kt b/app/src/test/kotlin/io/sakurasou/service/common/CommonServiceTest.kt index db59050d..387f5813 100644 --- a/app/src/test/kotlin/io/sakurasou/service/common/CommonServiceTest.kt +++ b/app/src/test/kotlin/io/sakurasou/service/common/CommonServiceTest.kt @@ -3,7 +3,7 @@ package io.sakurasou.service.common import at.favre.lib.crypto.bcrypt.BCrypt import io.mockk.* import io.sakurasou.controller.request.SiteInitRequest -import io.sakurasou.exception.SiteRepeatedInitializationException +import io.sakurasou.exception.controller.status.SiteRepeatedInitializationException import io.sakurasou.model.DatabaseSingleton import io.sakurasou.model.dao.album.AlbumDao import io.sakurasou.model.dao.user.UserDao diff --git a/app/src/test/kotlin/io/sakurasou/service/group/GroupServiceTest.kt b/app/src/test/kotlin/io/sakurasou/service/group/GroupServiceTest.kt index b175fe2e..25609148 100644 --- a/app/src/test/kotlin/io/sakurasou/service/group/GroupServiceTest.kt +++ b/app/src/test/kotlin/io/sakurasou/service/group/GroupServiceTest.kt @@ -4,7 +4,7 @@ import io.mockk.* import io.sakurasou.controller.request.GroupInsertRequest import io.sakurasou.controller.request.GroupPatchRequest import io.sakurasou.controller.vo.GroupVO -import io.sakurasou.exception.GroupNotExistException +import io.sakurasou.exception.service.group.GroupNotFoundException import io.sakurasou.model.DatabaseSingleton import io.sakurasou.model.dao.group.GroupDao import io.sakurasou.model.dao.relation.RelationDao @@ -160,7 +160,7 @@ class GroupServiceTest { } every { groupDao.findGroupById(1) } returns null - assertFailsWith { + assertFailsWith { groupService.fetchGroup(1) } } diff --git a/app/src/test/kotlin/io/sakurasou/service/strategy/StrategyServiceTest.kt b/app/src/test/kotlin/io/sakurasou/service/strategy/StrategyServiceTest.kt index 01ae291d..6ba78c92 100644 --- a/app/src/test/kotlin/io/sakurasou/service/strategy/StrategyServiceTest.kt +++ b/app/src/test/kotlin/io/sakurasou/service/strategy/StrategyServiceTest.kt @@ -4,7 +4,7 @@ import io.mockk.* import io.sakurasou.controller.request.StrategyInsertRequest import io.sakurasou.controller.request.StrategyPatchRequest import io.sakurasou.controller.vo.StrategyVO -import io.sakurasou.exception.StrategyNotExistException +import io.sakurasou.exception.service.strategy.StrategyNotFoundException import io.sakurasou.model.DatabaseSingleton import io.sakurasou.model.dao.strategy.StrategyDao import io.sakurasou.model.dto.StrategyInsertDTO @@ -147,7 +147,7 @@ class StrategyServiceTest { } every { strategyDao.findStrategyById(2L) } returns null - assertFailsWith(StrategyNotExistException::class) { + assertFailsWith(StrategyNotFoundException::class) { strategyService.fetchStrategy(2L) } } diff --git a/app/src/test/kotlin/io/sakurasou/service/user/UserServiceTest.kt b/app/src/test/kotlin/io/sakurasou/service/user/UserServiceTest.kt index 8e47263e..c0ff6621 100644 --- a/app/src/test/kotlin/io/sakurasou/service/user/UserServiceTest.kt +++ b/app/src/test/kotlin/io/sakurasou/service/user/UserServiceTest.kt @@ -3,7 +3,7 @@ package io.sakurasou.service.user import at.favre.lib.crypto.bcrypt.BCrypt import io.mockk.* import io.sakurasou.controller.request.UserInsertRequest -import io.sakurasou.exception.SignupNotAllowedException +import io.sakurasou.exception.controller.access.SignupNotAllowedException import io.sakurasou.model.DatabaseSingleton import io.sakurasou.model.dao.album.AlbumDao import io.sakurasou.model.dao.user.UserDao