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

πŸ”€ :: νšŒμ›κ°€μž… μˆ˜λ½μ‹œμ— UserRole μΆ”κ°€ #319

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import org.springframework.security.crypto.password.PasswordEncoder
@TransactionalService
class SignUpService(
private val userRepository: UserRepository,
private val userRoleRepository: UserRoleRepository,
private val passwordEncoder: PasswordEncoder,
private val emailAuthRepository: EmailAuthRepository,
private val applicationEventPublisher: ApplicationEventPublisher
Expand Down Expand Up @@ -48,19 +47,8 @@ class SignUpService(

val savedUser = userRepository.save(user)

saveUserRole(user)

applicationEventPublisher.publishEvent(SignupLoggingEvent(user.email))

return savedUser.id
}

private fun saveUserRole(user: User) {
val userRole = UserRole(
user = user,
userRoleType = UserRoleType.ROLE_STUDENT
)

userRoleRepository.save(userRole)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data class AcceptUserReqDto(
val classNum: Int?,
val num: Int?
) {
fun toStudentEntity(user: User): User {
fun toEntity(user: User): User {
return User(
id = user.id,
email = user.email,
Expand All @@ -29,43 +29,10 @@ data class AcceptUserReqDto(
grade = grade,
classNum = classNum,
num = num,
roles = mutableListOf(UserRoleType.ROLE_STUDENT),
state = UserState.CREATED,
profileUrl = user.profileUrl,
wrongPasswordCount = user.wrongPasswordCount,
oauthWrongPasswordCount = user.oauthWrongPasswordCount
)
}

fun toTeacherEntity(user: User): User{
return User(
id = user.id,
email = user.email,
password = user.password,
gender = gender,
name = name,
grade = grade,
classNum = classNum,
num = num,
roles = mutableListOf(UserRoleType.ROLE_TEACHER),
state = UserState.CREATED,
profileUrl = user.profileUrl
)
}

fun toGraduateEntity(user: User): User{
return User(
id = user.id,
email = user.email,
password = user.password,
gender = gender,
name = name,
grade = grade,
classNum = classNum,
num = num,
roles = mutableListOf(UserRoleType.ROLE_GRADUATE),
state = UserState.CREATED,
profileUrl = user.profileUrl
)
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.msg.gauth.domain.user.service

import com.msg.gauth.domain.client.exception.BadUserRoleRequestException
import com.msg.gauth.domain.user.User
import com.msg.gauth.domain.user.UserRole
import com.msg.gauth.domain.user.enums.UserRoleType
import com.msg.gauth.domain.user.enums.UserState
import com.msg.gauth.domain.user.exception.UserNotFoundException
import com.msg.gauth.domain.user.presentation.dto.request.AcceptUserReqDto
import com.msg.gauth.domain.user.repository.UserRepository
import com.msg.gauth.domain.user.repository.UserRoleRepository
import com.msg.gauth.global.annotation.service.TransactionalService

@TransactionalService
class AcceptUserSignUpService(
private val userRepository: UserRepository
private val userRepository: UserRepository,
private val userRoleRepository: UserRoleRepository
) {

fun execute(id: Long, acceptUserReqDto: AcceptUserReqDto) =
Expand All @@ -25,13 +28,34 @@ class AcceptUserSignUpService(
userRepository.findByIdAndState(id, UserState.PENDING)
?: throw UserNotFoundException()

private fun acceptStudent(id: Long, acceptUserReqDto: AcceptUserReqDto)=
userRepository.save(acceptUserReqDto.toStudentEntity(getUser(id)))
private fun acceptStudent(id: Long, acceptUserReqDto: AcceptUserReqDto) {
val user = acceptUserReqDto.toEntity(getUser(id))
saveUser(user, acceptUserReqDto)
}

private fun acceptTeacher(id: Long, acceptUserReqDto: AcceptUserReqDto) {
val user = acceptUserReqDto.toEntity(getUser(id))
saveUser(user, acceptUserReqDto)
}

private fun acceptGraduate(id: Long, acceptUserReqDto: AcceptUserReqDto) {
val user = acceptUserReqDto.toEntity(getUser(id))
saveUser(user, acceptUserReqDto)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when 쑰건문 μ‚¬μš©ν•  ν•„μš”λ„ 없어지고 private ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•  μ΄μœ λ„ μ—†μ–΄μ§€λŠ” 것 κ°™μ•„μš”

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8cc83a7
κ·ΈλŸ¬λ„€μš” μˆ˜μ •ν–ˆμ–΄μš”!


private fun saveUser(user: User, acceptUserReqDto: AcceptUserReqDto) {
saveUserRole(user, acceptUserReqDto.userRoleType)
userRepository.save(user)
}

private fun saveUserRole(user: User, userRoleType: UserRoleType) {
val userRole = UserRole(
user = user,
userRoleType = userRoleType
)
userRoleRepository.save(userRole)
}

private fun acceptTeacher(id: Long, acceptUserReqDto: AcceptUserReqDto) =
userRepository.save(acceptUserReqDto.toTeacherEntity(getUser(id)))

private fun acceptGraduate(id: Long, acceptUserReqDto: AcceptUserReqDto) =
userRepository.save(acceptUserReqDto.toGraduateEntity(getUser(id)))
}

}
Loading