Skip to content

Commit

Permalink
refactor: (#271) domain module detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
softpeanut committed Mar 2, 2023
1 parent b4074b3 commit 50efed3
Show file tree
Hide file tree
Showing 25 changed files with 134 additions and 80 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ jobs:
--build-cache
--no-daemon
- name: Run Detekt
run: ./gradlew :dms-application:detekt
- name: Run Detekt Application
run: ./gradlew :dms-application:detekt

- name: Run Detekt Domain
run: ./gradle :dms-domain:detekt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import team.aliens.dms.domain.student.dto.SignUpRequest
import team.aliens.dms.domain.student.dto.SignUpResponse
import team.aliens.dms.domain.student.exception.VerifiedStudentNotFoundException
import team.aliens.dms.domain.student.model.Student
import team.aliens.dms.domain.student.model.VerifiedStudent
import team.aliens.dms.domain.student.spi.CommandStudentPort
import team.aliens.dms.domain.student.spi.StudentCommandUserPort
import team.aliens.dms.domain.student.spi.StudentJwtPort
Expand Down Expand Up @@ -73,14 +74,6 @@ class SignUpUseCase(
schoolName = school.name
) ?: throw VerifiedStudentNotFoundException

/**
* 호실 조회
**/
val room = queryRoomPort.queryRoomBySchoolIdAndNumber(
schoolId = school.id,
number = verifiedStudent.roomNumber
) ?: throw RoomNotFoundException

val user = commandUserPort.saveUser(
createUser(
schoolId = school.id,
Expand All @@ -90,20 +83,13 @@ class SignUpUseCase(
)
)

val student = Student(
id = user.id,
roomId = room.id,
roomNumber = room.number,
roomLocation = verifiedStudent.roomLocation,
schoolId = school.id,
grade = grade,
classRoom = classRoom,
number = number,
name = verifiedStudent.name,
profileImageUrl = profileImageUrl ?: Student.PROFILE_IMAGE,
sex = verifiedStudent.sex
saveStudent(
user = user,
verifiedStudent = verifiedStudent,
school = school,
grade = grade, classRoom = classRoom, number = number,
profileImageUrl = profileImageUrl
)
commandStudentPort.saveStudent(student)
commandStudentPort.deleteVerifiedStudent(verifiedStudent)

val (accessToken, accessTokenExpiredAt, refreshToken, refreshTokenExpiredAt) = jwtPort.receiveToken(
Expand Down Expand Up @@ -183,4 +169,37 @@ class SignUpUseCase(
createdAt = LocalDateTime.now(),
deletedAt = null
)

private fun saveStudent(
user: User,
verifiedStudent: VerifiedStudent,
school: School,
grade: Int,
classRoom: Int,
number: Int,
profileImageUrl: String?
) {
/**
* 호실 조회
**/
val room = queryRoomPort.queryRoomBySchoolIdAndNumber(
schoolId = school.id,
number = verifiedStudent.roomNumber
) ?: throw RoomNotFoundException

val student = Student(
id = user.id,
roomId = room.id,
roomNumber = room.number,
roomLocation = verifiedStudent.roomLocation,
schoolId = school.id,
grade = grade,
classRoom = classRoom,
number = number,
name = verifiedStudent.name,
profileImageUrl = profileImageUrl ?: Student.PROFILE_IMAGE,
sex = verifiedStudent.sex
)
commandStudentPort.saveStudent(student)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package team.aliens.dms.common.annotation

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
annotation class Aggregate()
annotation class Aggregate
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package team.aliens.dms.common.annotation

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
annotation class DomainService()
annotation class DomainService
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package team.aliens.dms.common.error

object ErrorStatus {
const val BAD_REQUEST = 400
const val UNAUTHORIZED = 401
const val FORBIDDEN = 403
const val NOT_FOUND = 404
const val CONFLICT = 409
const val TOO_MANY_REQUEST = 429
const val INTERNAL_SERVER_ERROR = 500
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package team.aliens.dms.domain.auth.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class AuthErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

AUTH_CODE_MISMATCH(401, "Auth Code Mismatch"),
EMAIL_MISMATCH(401, "Email Mismatch"),
PASSWORD_MISMATCH(401, "Password Mismatch"),
AUTH_CODE_MISMATCH(ErrorStatus.UNAUTHORIZED, "Auth Code Mismatch"),
EMAIL_MISMATCH(ErrorStatus.UNAUTHORIZED, "Email Mismatch"),
PASSWORD_MISMATCH(ErrorStatus.UNAUTHORIZED, "Password Mismatch"),

REFRESH_TOKEN_NOT_FOUND(404, "Refresh Token Not Found"),
AUTH_CODE_NOT_FOUND(404, "Auth Code Not Found"),
AUTH_CODE_LIMIT_NOT_FOUND(404, "Auth Code Limit Not Found"),
REFRESH_TOKEN_NOT_FOUND(ErrorStatus.NOT_FOUND, "Refresh Token Not Found"),
AUTH_CODE_NOT_FOUND(ErrorStatus.NOT_FOUND, "Auth Code Not Found"),
AUTH_CODE_LIMIT_NOT_FOUND(ErrorStatus.NOT_FOUND, "Auth Code Limit Not Found"),

EMAIL_ALREADY_CERTIFIED(409, "Email Already Certified"),
EMAIL_ALREADY_CERTIFIED(ErrorStatus.CONFLICT, "Email Already Certified"),

AUTH_CODE_OVER_LIMITED(429, "Auth Code Over Limited")
AUTH_CODE_OVER_LIMITED(ErrorStatus.TOO_MANY_REQUEST, "Auth Code Over Limited")
;

override fun status(): Int = status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package team.aliens.dms.domain.file.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class FileErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

INVALID_EXTENSION(400, "Allowed Extension : jpg(JPG), jpeg(JPEG), png(PNG), heic(HEIC)"),
BAD_EXCEL_FORMAT(400, "Bas Excel Format"),
IO_INTERRUPTED(500, "Interrupted File IO")
INVALID_EXTENSION(ErrorStatus.BAD_REQUEST, "Allowed Extension : jpg(JPG), jpeg(JPEG), png(PNG), heic(HEIC)"),
BAD_EXCEL_FORMAT(ErrorStatus.BAD_REQUEST, "Bad Excel Format"),
IO_INTERRUPTED(ErrorStatus.INTERNAL_SERVER_ERROR, "Interrupted File IO")
;

override fun status(): Int = status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import team.aliens.dms.common.annotation.Aggregate
import java.time.format.DateTimeFormatter

@Aggregate
class File() {
class File private constructor() {
companion object {
val FILE_DATE_FORMAT: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package team.aliens.dms.domain.manager.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class ManagerErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

MANAGER_INFO_NOT_MATCHED(401, "Manager Info Not Matched"),
MANAGER_INFO_NOT_MATCHED(ErrorStatus.UNAUTHORIZED, "Manager Info Not Matched"),

MANAGER_NOT_FOUND(404, "Manager Not Found")
MANAGER_NOT_FOUND(ErrorStatus.NOT_FOUND, "Manager Not Found")
;

override fun status(): Int = status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package team.aliens.dms.domain.notice.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class NoticeErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

IS_NOT_WRITER(401, "Only Writer Can Delete"),
IS_NOT_WRITER(ErrorStatus.UNAUTHORIZED, "Only Writer Can Delete"),

NOTICE_NOT_FOUND(404, "Notice Not Found")
NOTICE_NOT_FOUND(ErrorStatus.NOT_FOUND, "Notice Not Found")
;

override fun status(): Int = status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package team.aliens.dms.domain.point.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class PointHistoryErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

POINT_HISTORY_NOT_FOUND(404, "Point History Not Found"),
INVALID_POINT_FILTER_RANGE(400, "Invalid Point Filter Range"),
POINT_HISTORY_CAN_NOT_CANCEL(400, "Point History Can Not Cancel")
POINT_HISTORY_NOT_FOUND(ErrorStatus.NOT_FOUND, "Point History Not Found"),
INVALID_POINT_FILTER_RANGE(ErrorStatus.BAD_REQUEST, "Invalid Point Filter Range"),
POINT_HISTORY_CAN_NOT_CANCEL(ErrorStatus.BAD_REQUEST, "Point History Can Not Cancel")
;

override fun status(): Int = status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package team.aliens.dms.domain.point.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class PointOptionErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

POINT_OPTION_NAME_EXISTS(409, "Point Option Exists"),
POINT_OPTION_NOT_FOUND(404, "Point Option Not Found"),
POINT_OPTION_SCHOOL_MISMATCH(401, "Point Option School Mismatch")
POINT_OPTION_NAME_EXISTS(ErrorStatus.CONFLICT, "Point Option Exists"),
POINT_OPTION_NOT_FOUND(ErrorStatus.NOT_FOUND, "Point Option Not Found"),
POINT_OPTION_SCHOOL_MISMATCH(ErrorStatus.UNAUTHORIZED, "Point Option School Mismatch")
;

override fun status(): Int = status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package team.aliens.dms.domain.remain.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class RemainAvailableTimeErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

REMAIN_CAN_NOT_APPLIED(403, "Remain Can Not Apply"),
REMAIN_AVAILABLE_TIME_CAN_NOT_ACCESS(403, "Remain Available Time Can Not Access"),
REMAIN_CAN_NOT_APPLIED(ErrorStatus.FORBIDDEN, "Remain Can Not Apply"),
REMAIN_AVAILABLE_TIME_CAN_NOT_ACCESS(ErrorStatus.FORBIDDEN, "Remain Available Time Can Not Access"),

REMAIN_AVAILABLE_TIME_NOT_FOUND(404, "Remain Available Time Not Found"),
REMAIN_AVAILABLE_TIME_NOT_FOUND(ErrorStatus.NOT_FOUND, "Remain Available Time Not Found"),
;

override fun status() = status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package team.aliens.dms.domain.remain.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class RemainOptionErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

REMAIN_OPTION_NOT_FOUND(404, "Remain Option Not Found")
REMAIN_OPTION_NOT_FOUND(ErrorStatus.NOT_FOUND, "Remain Option Not Found")
;

override fun status(): Int = status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package team.aliens.dms.domain.remain.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class RemainStatusErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

REMAIN_STATUS_NOT_FOUND(404, "Remain Status Not Found")
REMAIN_STATUS_NOT_FOUND(ErrorStatus.NOT_FOUND, "Remain Status Not Found")
;

override fun status() = status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package team.aliens.dms.domain.room.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class RoomErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

ROOM_NOT_FOUND(404, "Room Not Found")
ROOM_NOT_FOUND(ErrorStatus.NOT_FOUND, "Room Not Found")
;

override fun status(): Int = status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package team.aliens.dms.domain.school.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class SchoolErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

ANSWER_MISMATCH(401, "Answer Mismatch"),
SCHOOL_CODE_MISMATCH(401, "School Code Mismatch"),
SCHOOL_MISMATCH(401, "School Mismatch"),
ANSWER_MISMATCH(ErrorStatus.UNAUTHORIZED, "Answer Mismatch"),
SCHOOL_CODE_MISMATCH(ErrorStatus.UNAUTHORIZED, "School Code Mismatch"),
SCHOOL_MISMATCH(ErrorStatus.UNAUTHORIZED, "School Mismatch"),

SCHOOL_NOT_FOUND(404, "School Not Found"),
FEATURE_NOT_FOUND(404, "Feature Not Found")
SCHOOL_NOT_FOUND(ErrorStatus.NOT_FOUND, "School Not Found"),
FEATURE_NOT_FOUND(ErrorStatus.NOT_FOUND, "Feature Not Found")
;

override fun status(): Int = status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package team.aliens.dms.domain.student.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class StudentErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

STUDENT_INFO_MISMATCH(401, "Student Info Mismatch"),
STUDENT_INFO_MISMATCH(ErrorStatus.UNAUTHORIZED, "Student Info Mismatch"),

STUDENT_NOT_FOUND(404, "Student Not Found"),
STUDENT_NOT_FOUND(ErrorStatus.NOT_FOUND, "Student Not Found"),

STUDENT_ALREADY_EXISTS(409, "Student Already Exists")
STUDENT_ALREADY_EXISTS(ErrorStatus.CONFLICT, "Student Already Exists")
;

override fun status(): Int = status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package team.aliens.dms.domain.student.error

import team.aliens.dms.common.error.ErrorProperty
import team.aliens.dms.common.error.ErrorStatus

enum class VerifiedStudentErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

VERIFIED_STUDENT_NOT_FOUND(404, "Unverified Student")
VERIFIED_STUDENT_NOT_FOUND(ErrorStatus.NOT_FOUND, "Unverified Student")
;

override fun status(): Int = status
Expand Down
Loading

0 comments on commit 50efed3

Please sign in to comment.