Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
[WEAV-000] 예외 타입 리팩터링 (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfogSW authored Apr 21, 2024
1 parent ca13952 commit 40be553
Show file tree
Hide file tree
Showing 75 changed files with 505 additions and 492 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.studentcenter.weave.application.common.exception

import com.studentcenter.weave.support.common.exception.CustomException

sealed class AuthException(
codeNumber: Int,
message: String,
) : CustomException(CODE_PREFIX, codeNumber, message) {

class RefreshTokenNotFound(message: String = "") :
AuthException(codeNumber = 1, message = message)

class UserNotAuthenticated(message: String = "인증되지 않은 사용자 입니다") :
AuthException(codeNumber = 2, message = message)

companion object {
const val CODE_PREFIX = "AUTH"
}


}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.studentcenter.weave.application.common.exception

import com.studentcenter.weave.support.common.exception.CustomException


sealed class UniversityVerificationException(
codeNumber: Int,
message: String,
) : CustomException(CODE_PREFIX, codeNumber, message) {

class VerificationInformationNotFound(message: String = "유저의 인증 요청을 찾을 수 없습니다.") :
UniversityVerificationException(codeNumber = 1, message = message)

class InvalidVerificationInformation(message: String = "인증 정보가 일치하지 않습니다.") :
UniversityVerificationException(codeNumber = 2, message = message)

class AlreadyVerifiedEmail(message: String = "이미 인증된 이메일입니다.") :
UniversityVerificationException(codeNumber = 3, message = message)

class AlreadyVerifiedUser(message: String = "이미 인증된 유저입니다.") :
UniversityVerificationException(codeNumber = 4, message = message)

companion object {
const val CODE_PREFIX = "UNIV_VERIFICATION"
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.studentcenter.weave.application.common.security.context

import com.studentcenter.weave.application.common.exception.AuthExceptionType
import com.studentcenter.weave.application.common.exception.AuthException
import com.studentcenter.weave.application.user.vo.UserAuthentication
import com.studentcenter.weave.support.common.exception.CustomException
import com.studentcenter.weave.support.security.context.SecurityContextHolder

fun getCurrentUserAuthentication(): UserAuthentication {
Expand All @@ -11,10 +10,6 @@ fun getCurrentUserAuthentication(): UserAuthentication {
?.getAuthentication()

return userAuthentication ?: run {
val message = "인증되지 않은 사용자입니다."
throw CustomException(
type = AuthExceptionType.USER_NOT_AUTHENTICATED,
message = message
)
throw AuthException.UserNotAuthenticated()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.studentcenter.weave.application.meeting.service.application

import com.studentcenter.weave.application.common.exception.MeetingExceptionType
import com.studentcenter.weave.application.common.security.context.getCurrentUserAuthentication
import com.studentcenter.weave.application.meeting.port.inbound.CreateMeetingAttendance
import com.studentcenter.weave.application.meeting.port.outbound.MeetingEventPublisher
Expand All @@ -10,7 +9,7 @@ import com.studentcenter.weave.application.meetingTeam.port.inbound.GetMeetingTe
import com.studentcenter.weave.domain.meeting.entity.Meeting
import com.studentcenter.weave.domain.meeting.entity.MeetingAttendance
import com.studentcenter.weave.domain.meeting.event.MeetingCompletedEvent.Companion.createCompletedEvent
import com.studentcenter.weave.support.common.exception.CustomException
import com.studentcenter.weave.domain.meeting.exception.MeetingException
import com.studentcenter.weave.support.lock.distributedLock
import org.springframework.stereotype.Service
import java.time.LocalDateTime
Expand All @@ -37,10 +36,7 @@ class CreateMeetingAttendanceService(

val teamMemberMe = teamMembers
.firstOrNull { it.userId == getCurrentUserAuthentication().userId }
?: throw CustomException(
MeetingExceptionType.MEETING_NOT_JOINED_USER,
"미팅에 참여하지 않는 유저입니다",
)
?: throw MeetingException.NotJoinedUser()

validateAlreadyCreatedAttendance(
meetingId = meeting.id,
Expand Down Expand Up @@ -96,10 +92,7 @@ class CreateMeetingAttendanceService(
private fun getByIdAndValidate(meetingId: UUID): Meeting {
val meeting = meetingDomainService.getById(meetingId)
if (meeting.isFinished() || meeting.isEndPending(LocalDateTime.now())) {
throw CustomException(
MeetingExceptionType.FINISHED_MEETING,
"이미 완료(혹은 종료)된 미팅입니다.",
)
throw MeetingException.AlreadyFinished()
}
return meeting
}
Expand All @@ -113,10 +106,7 @@ class CreateMeetingAttendanceService(
meetingMemberId = meetingMemberId,
)
) {
throw CustomException(
MeetingExceptionType.ALREADY_ATTENDANCE_CREATED,
"이미 미팅 참여 의사를 결정했습니다.",
)
throw MeetingException.AlreadyAttended()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.studentcenter.weave.application.meeting.service.application

import com.studentcenter.weave.application.common.exception.MeetingExceptionType
import com.studentcenter.weave.application.common.security.context.getCurrentUserAuthentication
import com.studentcenter.weave.application.meeting.port.inbound.FindMyRequestMeetingByReceivingTeamId
import com.studentcenter.weave.application.meeting.service.domain.MeetingDomainService
import com.studentcenter.weave.application.meetingTeam.port.inbound.GetMeetingTeam
import com.studentcenter.weave.domain.meeting.entity.Meeting
import com.studentcenter.weave.support.common.exception.CustomException
import com.studentcenter.weave.domain.meetingTeam.exception.MeetingTeamException
import org.springframework.stereotype.Service
import java.util.*

Expand All @@ -18,16 +17,14 @@ class FindMyRequestMeetingByReceivingTeamIdService(

override fun invoke(receivingTeamId: UUID): Meeting? {
val userId = getCurrentUserAuthentication().userId
val myTeam = getMeetingTeam.findByMemberUserId(userId).let {
if (it == null || it.isPublished().not()) {
throw CustomException(
MeetingExceptionType.NOT_FOUND_MY_MEETING_TEAM,
"내 미팅팀이 존재하지 않아요! 미팅팀에 참여해 주세요!",
)
val myTeam = getMeetingTeam
.findByMemberUserId(userId)
.let {
if (it == null || it.isPublished().not()) {
throw MeetingTeamException.CanNotFindMyMeetingTeam()
}
it
}
it
}


return meetingDomainService.findByRequestingTeamIdAndReceivingTeamId(
requestingTeamId = myTeam.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.studentcenter.weave.application.meeting.service.application

import com.studentcenter.weave.application.common.exception.MeetingExceptionType
import com.studentcenter.weave.application.common.security.context.getCurrentUserAuthentication
import com.studentcenter.weave.application.meeting.port.inbound.GetAllOtherTeamMemberInfo
import com.studentcenter.weave.application.meeting.service.domain.MeetingDomainService
Expand All @@ -9,8 +8,8 @@ import com.studentcenter.weave.application.meetingTeam.vo.MemberInfo
import com.studentcenter.weave.application.university.port.inbound.GetUniversity
import com.studentcenter.weave.application.user.port.inbound.GetUser
import com.studentcenter.weave.domain.meeting.entity.Meeting
import com.studentcenter.weave.domain.meeting.exception.MeetingException
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingTeam
import com.studentcenter.weave.support.common.exception.CustomException
import org.springframework.stereotype.Service
import java.util.*

Expand Down Expand Up @@ -52,10 +51,7 @@ class GetAllOtherTeamMemberInfoService(
private fun validateMeeting(meeting: Meeting) {
// FIXME(prepared): 추후에 상태가 추가되면 Completed -> Prepared
if (meeting.isCompleted().not()) {
throw CustomException(
MeetingExceptionType.IS_NOT_COMPLETED_MEETING,
"완료된 미팅이 아닙니다.",
)
throw MeetingException.IsNotCompletedMeeting()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.studentcenter.weave.application.meeting.service.application

import com.studentcenter.weave.application.common.exception.MeetingExceptionType
import com.studentcenter.weave.application.common.exception.MeetingTeamExceptionType
import com.studentcenter.weave.application.common.security.context.getCurrentUserAuthentication
import com.studentcenter.weave.application.meeting.port.inbound.RequestMeeting
import com.studentcenter.weave.application.meeting.service.domain.MeetingAttendanceDomainService
Expand All @@ -10,10 +8,11 @@ import com.studentcenter.weave.application.meetingTeam.port.inbound.GetMeetingTe
import com.studentcenter.weave.application.user.port.inbound.GetUser
import com.studentcenter.weave.domain.meeting.entity.Meeting
import com.studentcenter.weave.domain.meeting.entity.MeetingAttendance
import com.studentcenter.weave.domain.meeting.exception.MeetingException
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingMember
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingTeam
import com.studentcenter.weave.domain.meetingTeam.enums.MeetingTeamStatus
import com.studentcenter.weave.support.common.exception.CustomException
import com.studentcenter.weave.domain.meetingTeam.exception.MeetingTeamException
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*
Expand Down Expand Up @@ -57,10 +56,7 @@ class RequestMeetingService(
val teamMember = members.firstOrNull { it.userId == getCurrentUserAuthentication().userId }

if (teamMember == null) {
throw CustomException(
type = MeetingTeamExceptionType.IS_NOT_TEAM_MEMBER,
message = "미팅팀에 속해있지 않아요! 미팅팀에 참여해 주세요!",
)
throw MeetingTeamException.IsNotTeamMember()
}

return MeetingAttendance.create(
Expand All @@ -75,10 +71,7 @@ class RequestMeetingService(
receivingTeamId: UUID,
) {
if (meetingDomainService.existsMeetingRequest(myTeam.id, receivingTeamId)) {
throw CustomException(
MeetingExceptionType.ALREADY_REQUEST_MEETING,
"이미 상대팀에게 미팅을 신청했어요!",
)
throw MeetingException.AlreadyRequestMeeting()
}
}

Expand All @@ -87,28 +80,19 @@ class RequestMeetingService(
.let { getUser.getById(it.userId) }

if (user.isUnivVerified.not()) {
throw CustomException(
MeetingExceptionType.CAN_NOT_MEETING_REQUEST_NOT_UNIV_VERIFIED_USER,
"대학교 이메일 인증이 되지 않았어요! 대학교 이메일을 인증해 주세요!",
)
throw MeetingException.UniversityMailUnverifiedUser()
}
}

private fun getMyMeetingTeam(): MeetingTeam {
return getCurrentUserAuthentication()
.let { getMeetingTeam.findByMemberUserId(it.userId) }
?: throw CustomException(
MeetingExceptionType.NOT_FOUND_MY_MEETING_TEAM,
"내 미팅팀이 존재하지 않아요! 미팅팀에 참여해 주세요!",
)
?: throw MeetingTeamException.CanNotFindMyMeetingTeam()
}

private fun validateMyMeetingTeamStatus(myMeetingTeam: MeetingTeam) {
if (myMeetingTeam.status != MeetingTeamStatus.PUBLISHED) {
throw CustomException(
MeetingExceptionType.CAN_NOT_PUBLISHED_TEAM,
"나의 미팅팀이 공개되지 않았어요! 미팅팀을 공개해 주세요!",
)
throw MeetingTeamException.IsNotPublishedTeam()
}
}

Expand All @@ -117,17 +101,11 @@ class RequestMeetingService(
receivingMeetingTeam: MeetingTeam,
) {
if (myMeetingTeam.gender == receivingMeetingTeam.gender) {
throw CustomException(
MeetingExceptionType.CAN_NOT_MEETING_REQUEST_SAME_GENDER,
"다른 성별의 미팅팀에만 미팅을 요청할 수 있어요!",
)
throw MeetingException.CanNotRequestToSameGender()
}

if (myMeetingTeam.memberCount != receivingMeetingTeam.memberCount) {
throw CustomException(
MeetingExceptionType.CAN_NOT_MEETING_REQUEST_NOT_SAME_MEMBERS,
"동일한 인원수의 미팅팀에만 미팅을 요청할 수 있어요!"
)
throw MeetingException.CanNotRequestToDifferentMemberCount()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.studentcenter.weave.application.meeting.service.application

import com.studentcenter.weave.application.common.exception.MeetingExceptionType
import com.studentcenter.weave.application.common.security.context.getCurrentUserAuthentication
import com.studentcenter.weave.application.meeting.port.inbound.ScrollPendingMeeting
import com.studentcenter.weave.application.meeting.service.domain.MeetingDomainService
Expand All @@ -9,7 +8,7 @@ import com.studentcenter.weave.application.meetingTeam.port.inbound.GetAllMeetin
import com.studentcenter.weave.application.meetingTeam.port.inbound.GetMeetingTeam
import com.studentcenter.weave.domain.meeting.entity.Meeting
import com.studentcenter.weave.domain.meeting.enums.TeamType
import com.studentcenter.weave.support.common.exception.CustomException
import com.studentcenter.weave.domain.meetingTeam.exception.MeetingTeamException
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*
Expand All @@ -24,10 +23,7 @@ class ScrollPendingMeetingService(
@Transactional(readOnly = true)
override fun invoke(query: ScrollPendingMeeting.Query): ScrollPendingMeeting.Result {
val myTeam = getMeetingTeam.findByMemberUserId(getCurrentUserAuthentication().userId)
?: throw CustomException(
MeetingExceptionType.NOT_FOUND_MY_MEETING_TEAM,
"내 미팅팀이 존재하지 않아요! 미팅팀에 참여해 주세요!",
)
?: throw MeetingTeamException.CanNotFindMyMeetingTeam()

val (items, next) = scrollByPendingMeetingByTeamId(
teamId = myTeam.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.studentcenter.weave.application.meeting.service.application

import com.studentcenter.weave.application.common.exception.MeetingExceptionType
import com.studentcenter.weave.application.common.security.context.getCurrentUserAuthentication
import com.studentcenter.weave.application.meeting.port.inbound.ScrollPreparedMeeting
import com.studentcenter.weave.application.meeting.service.domain.MeetingDomainService
import com.studentcenter.weave.application.meeting.vo.PreparedMeetingInfo
import com.studentcenter.weave.application.meetingTeam.port.inbound.GetAllMeetingTeamInfo
import com.studentcenter.weave.application.meetingTeam.port.inbound.GetMeetingTeam
import com.studentcenter.weave.domain.meeting.entity.Meeting
import com.studentcenter.weave.support.common.exception.CustomException
import com.studentcenter.weave.domain.meetingTeam.exception.MeetingTeamException
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*
Expand All @@ -23,10 +22,7 @@ class ScrollPreparedMeetingService(
@Transactional(readOnly = true)
override fun invoke(query: ScrollPreparedMeeting.Query): ScrollPreparedMeeting.Result {
val myTeam = getMeetingTeam.findByMemberUserId(getCurrentUserAuthentication().userId)
?: throw CustomException(
MeetingExceptionType.NOT_FOUND_MY_MEETING_TEAM,
"내 미팅팀이 존재하지 않아요! 미팅팀에 참여해 주세요!",
)
?: throw MeetingTeamException.CanNotFindMyMeetingTeam()

val (items, next) = scrollByPreparedMeetingByTeamId(
teamId = myTeam.id,
Expand Down
Loading

0 comments on commit 40be553

Please sign in to comment.