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

유저 회원가입 수락에 졸업생 수락 기능 추가 #139

Merged
merged 3 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 19 additions & 1 deletion src/main/kotlin/com/msg/gauth/domain/user/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class User(
@Column(nullable = true, columnDefinition = "TEXT")
val profileUrl: String?,
): BaseIdEntity(){

fun update(name: String, grade: Int, classNum: Int, num: Int, gender: Gender): User{
val user = User(
name = name,
Expand All @@ -61,7 +62,7 @@ class User(
return user
}

fun update(name: String, gender: Gender): User {
fun updateTeacher(name: String, gender: Gender): User {
val user = User(
name = name,
email = this.email,
Expand All @@ -78,6 +79,23 @@ class User(
return user
}

fun updateGraduate(name: String, gender: Gender): User {
val user = User(
name = name,
email = this.email,
grade = this.grade,
classNum = this.classNum,
num = this.num,
gender = gender,
password = this.password,
roles = mutableListOf(UserRole.ROLE_GRADUATE),
state = UserState.CREATED,
profileUrl = this.profileUrl
)
user.id = this.id
return user
}

fun update(password: String): User{
val user = User(
name = this.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.msg.gauth.domain.user.enums
import org.springframework.security.core.GrantedAuthority

enum class UserRole : GrantedAuthority {
ROLE_STUDENT, ROLE_TEACHER, ROLE_ADMIN;
ROLE_STUDENT, ROLE_TEACHER, ROLE_ADMIN, ROLE_GRADUATE;

override fun getAuthority(): String =
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AcceptTeacherSignUpService(
fun execute(acceptTeacherReqDto: AcceptTeacherReqDto) {
val user: User = userRepository.findByIdAndStateAndRoles(acceptTeacherReqDto.id, UserState.PENDING, mutableListOf(UserRole.ROLE_TEACHER))
?: throw UserNotFoundException()
user.update(acceptTeacherReqDto.name, acceptTeacherReqDto.gender)
user.updateTeacher(acceptTeacherReqDto.name, acceptTeacherReqDto.gender)
.let { userRepository.save(it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AcceptUserSignUpService(
when(acceptUserReqDto.userRole){
UserRole.ROLE_STUDENT -> acceptStudent(id, acceptUserReqDto)
UserRole.ROLE_TEACHER -> acceptTeacher(id, acceptUserReqDto)
UserRole.ROLE_GRADUATE -> acceptGraduate(id, acceptUserReqDto)
else -> throw BadUserRoleRequestException()
}

Expand All @@ -28,9 +29,12 @@ class AcceptUserSignUpService(
getUser(id).update(acceptUserReqDto)
.let { userRepository.save(it) }


private fun acceptTeacher(id: Long, acceptUserReqDto: AcceptUserReqDto) =
getUser(id).update(acceptUserReqDto.name, acceptUserReqDto.gender)
getUser(id).updateTeacher(acceptUserReqDto.name, acceptUserReqDto.gender)
.let { userRepository.save(it) }

private fun acceptGraduate(id: Long, acceptUserReqDto: AcceptUserReqDto) =
getUser(id).updateGraduate(acceptUserReqDto.name, acceptUserReqDto.gender)
.let { userRepository.save(it) }

}