diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/admin/exception/AdminNotFoundException.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/admin/exception/AdminNotFoundException.kt new file mode 100644 index 000000000..de29059e0 --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/admin/exception/AdminNotFoundException.kt @@ -0,0 +1,8 @@ +package team.msg.domain.admin.exception + +import team.msg.domain.admin.exception.constant.AdminErrorCode +import team.msg.global.error.exception.BitgouelException + +class AdminNotFoundException( + message: String +) : BitgouelException(message, AdminErrorCode.ADMIN_NOT_FOUND.status) \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/admin/exception/constant/AdminErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/admin/exception/constant/AdminErrorCode.kt new file mode 100644 index 000000000..ff28b7fe4 --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/admin/exception/constant/AdminErrorCode.kt @@ -0,0 +1,7 @@ +package team.msg.domain.admin.exception.constant + +enum class AdminErrorCode( + val status: Int +) { + ADMIN_NOT_FOUND(404) +} \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/auth/exception/constant/AuthErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/auth/exception/constant/AuthErrorCode.kt index 2a2ddd506..e52eea962 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/auth/exception/constant/AuthErrorCode.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/auth/exception/constant/AuthErrorCode.kt @@ -1,13 +1,12 @@ package team.msg.domain.auth.exception.constant enum class AuthErrorCode( - val message: String, val status: Int ) { - ALREADY_EXIST_EMAIL("이미 가입된 이메일입니다.", 409), - ALREADY_EXIST_PHONE_NUMBER("이미 가입된 전화번호입니다.", 409), - MISMATCH_PASSWORD("일치하지 않는 비밀번호입니다.", 401), - UNAPPROVED_USER("아직 회원가입 대기 상태입니다.", 403), - INVALID_TOKEN("유효하지 않은 토큰입니다.", 401), - REFRESH_TOKEN_NOT_FOUND("존재하지 않는 리프레시 토큰입니다.", 404) + ALREADY_EXIST_EMAIL(409), + ALREADY_EXIST_PHONE_NUMBER(409), + MISMATCH_PASSWORD(401), + UNAPPROVED_USER(403), + INVALID_TOKEN(401), + REFRESH_TOKEN_NOT_FOUND(404) } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/auth/presentation/AuthController.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/auth/presentation/AuthController.kt index 8846eaa19..82e867d91 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/auth/presentation/AuthController.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/auth/presentation/AuthController.kt @@ -74,4 +74,10 @@ class AuthController( authService.logout(refreshToken) return ResponseEntity.status(HttpStatus.NO_CONTENT).build() } + + @DeleteMapping("/withdraw") + fun withdraw(): ResponseEntity { + authService.withdraw() + return ResponseEntity.status(HttpStatus.NO_CONTENT).build() + } } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/auth/service/AuthService.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/auth/service/AuthService.kt index 89dd14df4..a3e14aca3 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/auth/service/AuthService.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/auth/service/AuthService.kt @@ -12,4 +12,5 @@ interface AuthService { fun login(request: LoginRequest): TokenResponse fun reissueToken(refreshToken: String): TokenResponse fun logout(refreshToken: String) + fun withdraw() } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/auth/service/AuthServiceImpl.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/auth/service/AuthServiceImpl.kt index a79d169cd..c7e108e58 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/auth/service/AuthServiceImpl.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/auth/service/AuthServiceImpl.kt @@ -1,17 +1,13 @@ package team.msg.domain.auth.service +import org.springframework.context.ApplicationEventPublisher import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import team.msg.common.enum.ApproveStatus import team.msg.common.util.SecurityUtil import team.msg.common.util.UserUtil -import team.msg.domain.auth.exception.AlreadyExistEmailException -import team.msg.domain.auth.exception.AlreadyExistPhoneNumberException -import team.msg.domain.auth.exception.InvalidRefreshTokenException -import team.msg.domain.auth.exception.MisMatchPasswordException -import team.msg.domain.auth.exception.RefreshTokenNotFoundException -import team.msg.domain.auth.exception.UnApprovedUserException +import team.msg.domain.auth.exception.* import team.msg.domain.auth.presentation.data.request.* import team.msg.domain.auth.presentation.data.response.TokenResponse import team.msg.domain.auth.repository.RefreshTokenRepository @@ -33,6 +29,7 @@ import team.msg.domain.student.repository.StudentRepository import team.msg.domain.teacher.model.Teacher import team.msg.domain.teacher.repository.TeacherRepository import team.msg.domain.user.enums.Authority +import team.msg.domain.user.event.WithdrawUserEvent import team.msg.domain.user.exception.UserNotFoundException import team.msg.domain.user.model.User import team.msg.domain.user.repository.UserRepository @@ -54,7 +51,8 @@ class AuthServiceImpl( private val jwtTokenGenerator: JwtTokenGenerator, private val jwtTokenParser: JwtTokenParser, private val refreshTokenRepository: RefreshTokenRepository, - private val userUtil: UserUtil + private val userUtil: UserUtil, + private val applicationEventPublisher: ApplicationEventPublisher ) : AuthService { /** @@ -213,6 +211,7 @@ class AuthServiceImpl( val user = userRepository.findByIdOrNull(token.userId) ?: throw UserNotFoundException("존재하지 않는 유저입니다. info : [ userId = ${token.userId} ]") + refreshTokenRepository.deleteById(refreshToken) return jwtTokenGenerator.generateToken(user.id, user.authority) } @@ -236,6 +235,18 @@ class AuthServiceImpl( refreshTokenRepository.delete(token) } + /** + * 회원탈퇴를 처리하는 메서드입니다. + */ + @Transactional(rollbackFor = [Exception::class]) + override fun withdraw() { + val user = userUtil.queryCurrentUser() + + applicationEventPublisher.publishEvent(WithdrawUserEvent(user)) + + userRepository.delete(user) + } + /** * 유저 생성과 검증을 처리하는 private 메서드입니다. * @param 유저 생성 및 검증하기 위한 email, name, phoneNumber, password, authority 입니다. diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/bbozzak/exception/BbozzakNotFoundException.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/bbozzak/exception/BbozzakNotFoundException.kt new file mode 100644 index 000000000..bf52a94ce --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/bbozzak/exception/BbozzakNotFoundException.kt @@ -0,0 +1,8 @@ +package team.msg.domain.bbozzak.exception + +import team.msg.domain.bbozzak.exception.constant.BbozzakErrorCode +import team.msg.global.error.exception.BitgouelException + +class BbozzakNotFoundException( + message: String +) : BitgouelException(message, BbozzakErrorCode.BBOZZAK_NOT_FOUND.status) \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/bbozzak/exception/constant/BbozzakErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/bbozzak/exception/constant/BbozzakErrorCode.kt new file mode 100644 index 000000000..6880f083d --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/bbozzak/exception/constant/BbozzakErrorCode.kt @@ -0,0 +1,7 @@ +package team.msg.domain.bbozzak.exception.constant + +enum class BbozzakErrorCode( + val status: Int +) { + BBOZZAK_NOT_FOUND(404) +} \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/club/exception/constant/ClubErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/club/exception/constant/ClubErrorCode.kt index 4c59aa75f..ea7fa1d12 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/club/exception/constant/ClubErrorCode.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/club/exception/constant/ClubErrorCode.kt @@ -1,8 +1,7 @@ package team.msg.domain.club.exception.constant enum class ClubErrorCode( - val message: String, val status: Int ) { - CLUB_NOT_FOUND("존재하지 않는 동아리입니다.", 404) + CLUB_NOT_FOUND(404) } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/company/exception/CompanyNotFoundException.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/company/exception/CompanyNotFoundException.kt new file mode 100644 index 000000000..fb724fc7e --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/company/exception/CompanyNotFoundException.kt @@ -0,0 +1,8 @@ +package team.msg.domain.company.exception + +import team.msg.domain.company.exception.constant.CompanyErrorCode +import team.msg.global.error.exception.BitgouelException + +class CompanyNotFoundException( + message: String +) : BitgouelException(message, CompanyErrorCode.COMPANY_NOT_FOUND.status) \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/company/exception/constant/CompanyErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/company/exception/constant/CompanyErrorCode.kt new file mode 100644 index 000000000..07625bf91 --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/company/exception/constant/CompanyErrorCode.kt @@ -0,0 +1,7 @@ +package team.msg.domain.company.exception.constant + +enum class CompanyErrorCode( + val status: Int +) { + COMPANY_NOT_FOUND(404) +} \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/government/GovernmentNotFoundException.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/government/GovernmentNotFoundException.kt new file mode 100644 index 000000000..76b2dae23 --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/government/GovernmentNotFoundException.kt @@ -0,0 +1,8 @@ +package team.msg.domain.government + +import team.msg.domain.government.exception.constant.GovernmentErrorCode +import team.msg.global.error.exception.BitgouelException + +class GovernmentNotFoundException( + message: String +) : BitgouelException(message, GovernmentErrorCode.GOVERNMENT_NOT_FOUND.status) \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/government/exception/constant/GovernmentErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/government/exception/constant/GovernmentErrorCode.kt new file mode 100644 index 000000000..bf1a03483 --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/government/exception/constant/GovernmentErrorCode.kt @@ -0,0 +1,7 @@ +package team.msg.domain.government.exception.constant + +enum class GovernmentErrorCode( + val status: Int +) { + GOVERNMENT_NOT_FOUND(404) +} \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/lecture/exception/constant/LectureErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/lecture/exception/constant/LectureErrorCode.kt index c5f4b1803..e1cb90651 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/lecture/exception/constant/LectureErrorCode.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/lecture/exception/constant/LectureErrorCode.kt @@ -1,12 +1,9 @@ package team.msg.domain.lecture.exception.constant enum class LectureErrorCode( - val message: String, val status: Int ){ - INVALID_LECTURE_TYPE("유효하지 않은 강의 구분입니다.", 400), - - LECTURE_NOT_FOUND("존재하지 않는 강의입니다.", 404), - - ALREADY_APPROVED_LECTURE("이미 개설 신청이 승인된 강의입니다.",409) + INVALID_LECTURE_TYPE(400), + LECTURE_NOT_FOUND(404), + ALREADY_APPROVED_LECTURE(409) } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/professor/exception/ProfessorNotFoundException.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/professor/exception/ProfessorNotFoundException.kt new file mode 100644 index 000000000..660db634b --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/professor/exception/ProfessorNotFoundException.kt @@ -0,0 +1,8 @@ +package team.msg.domain.professor.exception + +import team.msg.domain.professor.exception.constant.ProfessorErrorCode +import team.msg.global.error.exception.BitgouelException + +class ProfessorNotFoundException( + message: String +) : BitgouelException(message, ProfessorErrorCode.PROFESSOR_NOT_FOUND.status) \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/professor/exception/constant/ProfessorErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/professor/exception/constant/ProfessorErrorCode.kt new file mode 100644 index 000000000..dcdb3bc3a --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/professor/exception/constant/ProfessorErrorCode.kt @@ -0,0 +1,7 @@ +package team.msg.domain.professor.exception.constant + +enum class ProfessorErrorCode( + val status: Int +) { + PROFESSOR_NOT_FOUND(404) +} \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/school/exception/constant/SchoolErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/school/exception/constant/SchoolErrorCode.kt index be68b9c97..467c69a52 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/school/exception/constant/SchoolErrorCode.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/school/exception/constant/SchoolErrorCode.kt @@ -1,8 +1,7 @@ package team.msg.domain.school.exception.constant enum class SchoolErrorCode( - val message: String, val status: Int ) { - SCHOOL_NOT_FOUND("이미 가입된 정보입니다.", 403) + SCHOOL_NOT_FOUND(403) } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/student/exception/constant/StudentActivityErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/student/exception/constant/StudentActivityErrorCode.kt index 9b5e70d11..ec67bcba0 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/student/exception/constant/StudentActivityErrorCode.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/student/exception/constant/StudentActivityErrorCode.kt @@ -1,8 +1,7 @@ package team.msg.domain.student.exception.constant enum class StudentActivityErrorCode( - val message: String, val status: Int ) { - STUDENT_ACTIVITY_NOT_FOUND("학생 활동을 찾을 수 없습니다", 404) + STUDENT_ACTIVITY_NOT_FOUND(404) } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/student/exception/constant/StudentErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/student/exception/constant/StudentErrorCode.kt index 73f1548b2..793d60a85 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/student/exception/constant/StudentErrorCode.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/student/exception/constant/StudentErrorCode.kt @@ -1,8 +1,7 @@ package team.msg.domain.student.exception.constant enum class StudentErrorCode( - val message: String, val status: Int ) { - STUDENT_NOT_FOUND("학생을 찾을 수 없습니다.", 404) + STUDENT_NOT_FOUND(404) } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/teacher/exception/TeacherNotFoundException.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/teacher/exception/TeacherNotFoundException.kt index 428f6079f..666963d74 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/teacher/exception/TeacherNotFoundException.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/teacher/exception/TeacherNotFoundException.kt @@ -5,5 +5,4 @@ import team.msg.global.error.exception.BitgouelException class TeacherNotFoundException( message: String -) : BitgouelException(message, TeacherErrorCode.TEACHER_NOT_FOUND.status) { -} \ No newline at end of file +) : BitgouelException(message, TeacherErrorCode.TEACHER_NOT_FOUND.status) \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/teacher/exception/constant/TeacherErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/teacher/exception/constant/TeacherErrorCode.kt index d711d6bfa..4da893cfd 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/teacher/exception/constant/TeacherErrorCode.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/teacher/exception/constant/TeacherErrorCode.kt @@ -1,8 +1,7 @@ package team.msg.domain.teacher.exception.constant enum class TeacherErrorCode( - val message: String, val status: Int ) { - TEACHER_NOT_FOUND("취업 동아리 선생님을 찾을 수 없습니다.", 404) + TEACHER_NOT_FOUND(404) } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/user/exception/constant/UserErrorCode.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/user/exception/constant/UserErrorCode.kt index edf99bc19..54b3bc67b 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/user/exception/constant/UserErrorCode.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/user/exception/constant/UserErrorCode.kt @@ -1,8 +1,7 @@ package team.msg.domain.user.exception.constant enum class UserErrorCode( - val message: String, val status: Int ) { - USER_NOT_FOUND("존재하지 않는 유저입니다.", 404) + USER_NOT_FOUND(404) } \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/user/handler/UserEventHandler.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/user/handler/UserEventHandler.kt new file mode 100644 index 000000000..e61038dda --- /dev/null +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/user/handler/UserEventHandler.kt @@ -0,0 +1,100 @@ +package team.msg.domain.user.handler + +import org.springframework.stereotype.Component +import org.springframework.transaction.event.TransactionPhase +import org.springframework.transaction.event.TransactionalEventListener +import team.msg.domain.admin.exception.AdminNotFoundException +import team.msg.domain.admin.repository.AdminRepository +import team.msg.domain.auth.exception.UnApprovedUserException +import team.msg.domain.bbozzak.exception.BbozzakNotFoundException +import team.msg.domain.bbozzak.repository.BbozzakRepository +import team.msg.domain.company.exception.CompanyNotFoundException +import team.msg.domain.company.repository.CompanyInstructorRepository +import team.msg.domain.government.GovernmentNotFoundException +import team.msg.domain.government.repository.GovernmentRepository +import team.msg.domain.lecture.repository.RegisteredLectureRepository +import team.msg.domain.professor.exception.ProfessorNotFoundException +import team.msg.domain.professor.repository.ProfessorRepository +import team.msg.domain.student.exception.StudentNotFoundException +import team.msg.domain.student.repository.StudentActivityRepository +import team.msg.domain.student.repository.StudentRepository +import team.msg.domain.teacher.exception.TeacherNotFoundException +import team.msg.domain.teacher.repository.TeacherRepository +import team.msg.domain.user.enums.Authority.* +import team.msg.domain.user.event.WithdrawUserEvent +import team.msg.domain.user.repository.UserRepository + +@Component +class UserEventHandler( + private val userRepository: UserRepository, + private val studentRepository: StudentRepository, + private val studentActivityRepository: StudentActivityRepository, + private val bbozzakRepository: BbozzakRepository, + private val teacherRepository: TeacherRepository, + private val professorRepository: ProfessorRepository, + private val companyInstructorRepository: CompanyInstructorRepository, + private val governmentRepository: GovernmentRepository, + private val registeredLectureRepository: RegisteredLectureRepository, + private val adminRepository: AdminRepository +) { + + /** + * User 의 delete 이벤트가 발행되면 User 를 삭제하는 핸들입니다. + * @param user delete 이벤트 + */ + @TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT) + fun withdrawUserHandler(event: WithdrawUserEvent) { + val user = event.user + + when (user.authority) { + ROLE_STUDENT -> { + val student = studentRepository.findByUser(user) + ?: throw StudentNotFoundException("존재하지 않는 학생 입니다. info : [ userId = ${user.id} ]") + val studentActivity = studentActivityRepository.findAllByStudent(student) + val registeredLecture = registeredLectureRepository.findAllByStudent(student) + + studentActivityRepository.deleteAll(studentActivity) + registeredLectureRepository.deleteAll(registeredLecture) + studentRepository.delete(student) + } + ROLE_ADMIN -> { + val admin = adminRepository.findByUser(user) + ?: throw AdminNotFoundException("존재하지 않는 어드민 입니다. info : [ userId = ${user.id} ]") + + adminRepository.delete(admin) + } + ROLE_BBOZZAK -> { + val bbozzak = bbozzakRepository.findByUser(user) + ?: throw BbozzakNotFoundException("존재하지 않는 뽀짝샘 입니다. info : [ userId = ${user.id} ]") + + bbozzakRepository.delete(bbozzak) + } + ROLE_TEACHER -> { + val teacher = teacherRepository.findByUser(user) + ?: throw TeacherNotFoundException("존재하지 않는 취동샘 입니다. info : [ userId = ${user.id} ]") + + teacherRepository.delete(teacher) + } + ROLE_PROFESSOR -> { + val professor = professorRepository.findByUser(user) + ?: throw ProfessorNotFoundException("존재하지 않는 대학 교수 입니다. info : [ userId = ${user.id} ]") + + professorRepository.delete(professor) + } + ROLE_COMPANY_INSTRUCTOR -> { + val companyInstructor = companyInstructorRepository.findByUser(user) + ?: throw CompanyNotFoundException("존재하지 않는 기업 강사 입니다. info : [ userId = ${user.id} ]") + + companyInstructorRepository.delete(companyInstructor) + } + ROLE_GOVERNMENT -> { + val government = governmentRepository.findByUser(user) + ?: throw GovernmentNotFoundException("존재하지 않는 유관 기관 입니다. info : [ userId = ${user.id} ]") + + governmentRepository.delete(government) + } + + else -> throw UnApprovedUserException("회원가입 승인 대기 중인 유저입니다. info : [ userId = ${user.id} ]") + } + } +} \ No newline at end of file diff --git a/bitgouel-api/src/main/kotlin/team/msg/global/security/SecurityConfig.kt b/bitgouel-api/src/main/kotlin/team/msg/global/security/SecurityConfig.kt index 6ea5a95ec..4866d9c52 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/global/security/SecurityConfig.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/global/security/SecurityConfig.kt @@ -53,6 +53,7 @@ class SecurityConfig( .mvcMatchers(HttpMethod.POST, "/auth/login").permitAll() .mvcMatchers(HttpMethod.PATCH, "/auth").permitAll() .mvcMatchers(HttpMethod.DELETE, "/auth").authenticated() + .mvcMatchers(HttpMethod.DELETE, "/auth/withdraw").authenticated() // activity .mvcMatchers(HttpMethod.POST, "/activity").hasRole(STUDENT) diff --git a/bitgouel-domain/src/main/kotlin/team/msg/common/entity/BaseUUIDEntity.kt b/bitgouel-domain/src/main/kotlin/team/msg/common/entity/BaseUUIDEntity.kt index 891ea205f..2fde4814c 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/common/entity/BaseUUIDEntity.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/common/entity/BaseUUIDEntity.kt @@ -1,17 +1,13 @@ package team.msg.common.entity - -import javax.persistence.Column -import javax.persistence.GeneratedValue -import javax.persistence.Id -import javax.persistence.MappedSuperclass -import javax.persistence.PostLoad -import javax.persistence.PostPersist import org.hibernate.annotations.GenericGenerator import org.hibernate.proxy.HibernateProxy import org.springframework.data.domain.Persistable import team.msg.common.ulid.ULIDGenerator -import java.io.Serializable import java.util.* +import javax.persistence.Column +import javax.persistence.GeneratedValue +import javax.persistence.Id +import javax.persistence.MappedSuperclass @MappedSuperclass abstract class BaseUUIDEntity( @@ -24,7 +20,6 @@ abstract class BaseUUIDEntity( open var id: UUID = UUID(0, 0) ) : BaseTimeEntity(), Persistable { - @Column(name = "ulid", updatable = false, unique = true) var ulid: String? = ULIDGenerator.generateULID() diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/admin/repository/AdminRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/admin/repository/AdminRepository.kt index d2a4f9d7b..6cfe2bebe 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/admin/repository/AdminRepository.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/admin/repository/AdminRepository.kt @@ -2,6 +2,9 @@ package team.msg.domain.admin.repository import org.springframework.data.repository.CrudRepository import team.msg.domain.admin.model.Admin +import team.msg.domain.user.model.User import java.util.UUID -interface AdminRepository : CrudRepository \ No newline at end of file +interface AdminRepository : CrudRepository { + fun findByUser(user: User): Admin? +} \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/bbozzak/repository/BbozzakRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/bbozzak/repository/BbozzakRepository.kt index 4aa7aea64..90702314a 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/bbozzak/repository/BbozzakRepository.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/bbozzak/repository/BbozzakRepository.kt @@ -2,6 +2,9 @@ package team.msg.domain.bbozzak.repository import org.springframework.data.repository.CrudRepository import team.msg.domain.bbozzak.model.Bbozzak +import team.msg.domain.user.model.User import java.util.UUID -interface BbozzakRepository : CrudRepository \ No newline at end of file +interface BbozzakRepository : CrudRepository { + fun findByUser(user: User): Bbozzak? +} \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/company/model/CompanyInstructor.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/company/model/CompanyInstructor.kt index 20ebefe47..5942e8d4c 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/company/model/CompanyInstructor.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/company/model/CompanyInstructor.kt @@ -23,6 +23,4 @@ class CompanyInstructor( @Column(columnDefinition = "VARCHAR(20)", nullable = false) val company: String -) : BaseUUIDEntity(id) { - -} \ No newline at end of file +) : BaseUUIDEntity(id) \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/company/repository/CompanyInstructorRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/company/repository/CompanyInstructorRepository.kt index ad4e47f14..d29a97425 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/company/repository/CompanyInstructorRepository.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/company/repository/CompanyInstructorRepository.kt @@ -2,7 +2,9 @@ package team.msg.domain.company.repository import org.springframework.data.repository.CrudRepository import team.msg.domain.company.model.CompanyInstructor +import team.msg.domain.user.model.User import java.util.UUID interface CompanyInstructorRepository : CrudRepository { + fun findByUser(user: User): CompanyInstructor? } \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/government/repository/GovernmentRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/government/repository/GovernmentRepository.kt index 0e582fadb..dc15dcf75 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/government/repository/GovernmentRepository.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/government/repository/GovernmentRepository.kt @@ -2,8 +2,9 @@ package team.msg.domain.government.repository import org.springframework.data.repository.CrudRepository import team.msg.domain.government.model.Government +import team.msg.domain.user.model.User import java.util.UUID interface GovernmentRepository : CrudRepository { - + fun findByUser(user: User): Government? } \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/lecture/repository/RegisteredLectureRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/lecture/repository/RegisteredLectureRepository.kt index 4f2fc7802..1a5501857 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/lecture/repository/RegisteredLectureRepository.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/lecture/repository/RegisteredLectureRepository.kt @@ -2,6 +2,9 @@ package team.msg.domain.lecture.repository import org.springframework.data.repository.CrudRepository import team.msg.domain.lecture.model.RegisteredLecture +import team.msg.domain.student.model.Student import java.util.UUID -interface RegisteredLectureRepository : CrudRepository \ No newline at end of file +interface RegisteredLectureRepository : CrudRepository { + fun findAllByStudent(student: Student): List +} \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/professor/repository/ProfessorRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/professor/repository/ProfessorRepository.kt index 7a4266f9d..feb3f40a2 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/professor/repository/ProfessorRepository.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/professor/repository/ProfessorRepository.kt @@ -2,7 +2,9 @@ package team.msg.domain.professor.repository import org.springframework.data.repository.CrudRepository import team.msg.domain.professor.model.Professor +import team.msg.domain.user.model.User import java.util.UUID interface ProfessorRepository : CrudRepository { + fun findByUser(user: User): Professor? } \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/student/model/Student.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/student/model/Student.kt index 355dd4d50..b56aa72aa 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/student/model/Student.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/student/model/Student.kt @@ -18,7 +18,7 @@ import java.util.UUID @Entity class Student( - @get:JvmName("getIdentifier") + @get:JvmName(name = "getIdentifier") override var id: UUID, @OneToOne(fetch = FetchType.LAZY, cascade = [CascadeType.MERGE]) @@ -49,4 +49,4 @@ class Student( val studentRole: StudentRole ) : BaseUUIDEntity(id) { -} \ No newline at end of file +} diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/student/model/StudentActivity.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/student/model/StudentActivity.kt index 0388d8282..49d029293 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/student/model/StudentActivity.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/student/model/StudentActivity.kt @@ -1,17 +1,11 @@ package team.msg.domain.student.model -import javax.persistence.Column -import javax.persistence.Entity -import javax.persistence.EnumType -import javax.persistence.Enumerated -import javax.persistence.FetchType -import javax.persistence.JoinColumn -import javax.persistence.ManyToOne import team.msg.common.entity.BaseUUIDEntity import team.msg.common.enum.ApproveStatus import team.msg.domain.teacher.model.Teacher import java.time.LocalDateTime import java.util.* +import javax.persistence.* @Entity class StudentActivity( diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/student/model/StudentActivityHistory.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/student/model/StudentActivityHistory.kt index 011effe6b..d2b52a63a 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/student/model/StudentActivityHistory.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/student/model/StudentActivityHistory.kt @@ -1,18 +1,11 @@ package team.msg.domain.student.model -import javax.persistence.Column -import javax.persistence.Entity -import javax.persistence.EnumType -import javax.persistence.Enumerated -import javax.persistence.FetchType -import javax.persistence.JoinColumn -import javax.persistence.ManyToOne import team.msg.common.entity.BaseUUIDEntity import team.msg.common.enum.ApproveStatus import team.msg.domain.teacher.model.Teacher import java.time.LocalDateTime import java.util.* - +import javax.persistence.* /** * StudentActivity의 History를 저장하는 엔티티입니다. @@ -49,6 +42,5 @@ class StudentActivityHistory( @Column(name = "student_activity_id", columnDefinition = "BINARY(16)", nullable = false) val studentActivityId: UUID -) : BaseUUIDEntity(id) { -} \ No newline at end of file +) : BaseUUIDEntity(id) \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/student/repository/StudentActivityRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/student/repository/StudentActivityRepository.kt index 6afeeccb9..aae8f3bdb 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/student/repository/StudentActivityRepository.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/student/repository/StudentActivityRepository.kt @@ -7,4 +7,5 @@ import java.util.* interface StudentActivityRepository : JpaRepository { fun findByIdAndStudent(id: UUID, student: Student): StudentActivity? + fun findAllByStudent(student: Student): List } \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/teacher/repository/TeacherRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/teacher/repository/TeacherRepository.kt index ad3db16ec..bde8ba235 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/teacher/repository/TeacherRepository.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/teacher/repository/TeacherRepository.kt @@ -3,8 +3,10 @@ package team.msg.domain.teacher.repository import org.springframework.data.repository.CrudRepository import team.msg.domain.club.model.Club import team.msg.domain.teacher.model.Teacher +import team.msg.domain.user.model.User import java.util.UUID interface TeacherRepository : CrudRepository { fun findByClub(club: Club): Teacher? + fun findByUser(user: User): Teacher? } \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/user/event/WithdrawUserEvent.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/user/event/WithdrawUserEvent.kt new file mode 100644 index 000000000..2b45be19b --- /dev/null +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/user/event/WithdrawUserEvent.kt @@ -0,0 +1,11 @@ +package team.msg.domain.user.event + +import team.msg.domain.user.model.User + +/** + * User 가 withdraw 하는 이벤트를 나타냅니다. + * User withdraw 를 구독자에게 알리기 위해서 사용됩니다. + */ +data class WithdrawUserEvent( + val user: User +) \ No newline at end of file