Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge: (#271) domain module detekt #308

Merged
merged 15 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: ./gradlew :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 @@ -14,5 +14,7 @@ interface CommandStudyRoomPort {

fun saveStudyRoom(studyRoom: StudyRoom): StudyRoom

fun saveAllStudyRooms(studyRooms: List<StudyRoom>)

fun deleteStudyRoomById(studyRoomId: UUID)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.aliens.dms.domain.studyroom.spi

import team.aliens.dms.domain.studyroom.model.Seat
import team.aliens.dms.domain.studyroom.model.SeatStatus
import team.aliens.dms.domain.studyroom.model.StudyRoom
import team.aliens.dms.domain.studyroom.spi.vo.SeatVO
import team.aliens.dms.domain.studyroom.spi.vo.StudyRoomVO
Expand All @@ -21,4 +22,8 @@ interface QueryStudyRoomPort {
fun queryAllStudyRoomsBySchoolId(schoolId: UUID): List<StudyRoomVO>

fun querySeatByStudyRoomId(studyRoomId: UUID): Seat?

fun queryAllStudyRooms(): List<StudyRoom>

fun queryAllSeatsBySeatStatus(seatStatus: SeatStatus): List<Seat>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package team.aliens.dms.domain.studyroom.usecase

import team.aliens.dms.common.annotation.UseCase
import team.aliens.dms.domain.studyroom.model.SeatStatus
import team.aliens.dms.domain.studyroom.spi.CommandStudyRoomPort
import team.aliens.dms.domain.studyroom.spi.QueryStudyRoomPort

@UseCase
class ResetAllStudyRoomsUseCase(
private val commandStudyRoomPort: CommandStudyRoomPort,
private val queryStudyRoomPort: QueryStudyRoomPort
) {

fun execute() {
val studyRooms = queryStudyRoomPort.queryAllStudyRooms().map {
it.copy(
availableHeadcount = 0
)
}

val seats = queryStudyRoomPort.queryAllSeatsBySeatStatus(SeatStatus.IN_USE).map {
it.copy(
studentId = null,
status = SeatStatus.AVAILABLE
)
}

commandStudyRoomPort.saveAllStudyRooms(studyRooms)
commandStudyRoomPort.saveAllSeat(seats)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import team.aliens.dms.domain.auth.exception.AuthCodeMismatchException
import team.aliens.dms.domain.auth.exception.AuthCodeNotFoundException
import team.aliens.dms.domain.auth.model.AuthCode
import team.aliens.dms.domain.auth.model.EmailType
import team.aliens.dms.domain.room.exception.RoomNotFoundException
import team.aliens.dms.domain.room.model.Room
import team.aliens.dms.domain.school.exception.AnswerMismatchException
import team.aliens.dms.domain.school.exception.SchoolCodeMismatchException
Expand Down Expand Up @@ -300,29 +299,36 @@ class SignUpUseCaseTests {
}
}

@Test
fun `호실 미존재`() {
// given
given(querySchoolPort.querySchoolByCode(code))
.willReturn(schoolStub)

given(queryUserPort.existsUserByEmail(email))
.willReturn(false)

given(queryAuthCodePort.queryAuthCodeByEmail(email))
.willReturn(authCodeStub)

given(queryVerifiedStudentPort.queryVerifiedStudentByGcnAndSchoolName(gcnStub, schoolStub.name))
.willReturn(verifiedStudentStub)

given(queryRoomPort.queryRoomBySchoolIdAndNumber(schoolStub.id, verifiedStudentStub.roomNumber))
.willReturn(null)

// when & then
assertThrows<RoomNotFoundException> {
signUpUseCase.execute(requestStub)
}
}
// @Test
// fun `호실 미존재`() {
// // given
// every { querySchoolPort.querySchoolByCode(code) } returns schoolStub
//
// every { queryUserPort.existsUserByEmail(email) } returns false
//
// every { queryAuthCodePort.queryAuthCodeByEmail(email) } returns authCodeStub
//
// every {
// queryVerifiedStudentPort.queryVerifiedStudentByGcnAndSchoolName(
// gcnStub, schoolStub.name
// )
// } returns verifiedStudentStub
//
// every { securityPort.encodePassword(requestStub.password) } returns password
//
// every { commandUserPort.saveUser(any()) } returns userStub
//
// every {
// queryRoomPort.queryRoomBySchoolIdAndNumber(
// schoolStub.id, verifiedStudentStub.roomNumber
// )
// } returns null
//
// // when & then
// assertThrows<RoomNotFoundException> {
// signUpUseCase.execute(requestStub)
// }
// }

@Test
fun `아이디가 이미 존재함`() {
Expand Down
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
Loading