From 9627397fd624d31e633b46bc9d4e98c341a5c8c2 Mon Sep 17 00:00:00 2001 From: leekyukin Date: Wed, 21 Dec 2022 20:18:04 +0900 Subject: [PATCH] refactor: (#101) wrap primitive type of User domain --- .../common/security/auth/AuthDetails.kt | 6 ++-- .../domain/auth/service/AuthServiceImpl.kt | 6 ++-- .../policy/AlreadyExistsStudentPolicy.kt | 6 ++-- .../domain/school/policy/InfoRangePolicy.kt | 6 ++-- .../domain/student/domain/Student.kt | 18 +++++----- .../student/policy/AlreadyCreatedPolicy.kt | 6 ++-- .../domain/student/policy/StudentPolicy.kt | 2 +- .../teacher/service/TeacherServiceImpl.kt | 2 +- .../tojserverv2/domain/user/UserCommand.kt | 3 +- .../tojserverv2/domain/user/UserMapper.kt | 14 ++++++-- .../tojserverv2/domain/user/UserReader.kt | 2 ++ .../tojserverv2/domain/user/UserStore.kt | 2 ++ .../domain/user/domain/Authority.kt | 5 +++ .../domain/user/{ => domain}/Email.kt | 4 +-- .../domain/user/{ => domain}/Image.kt | 4 +-- .../domain/user/{ => domain}/Name.kt | 4 +-- .../domain/user/{type => domain}/Nickname.kt | 4 +-- .../domain/user/{ => domain}/Password.kt | 4 +-- .../domain/user/{ => domain}/User.kt | 10 ++++-- .../domain/user/service/OAuthServiceImpl.kt | 24 +++++++------ .../domain/user/service/UserServiceImpl.kt | 4 +-- .../tojserverv2/domain/user/type/Authority.kt | 5 --- .../infrastructure/user/UserReaderImpl.kt | 2 +- .../infrastructure/user/UserRepository.kt | 2 +- .../infrastructure/user/UserStoreImpl.kt | 6 ++-- .../domain/auth/service/AuthServiceTest.kt | 14 ++++---- .../domain/user/service/UserServiceTest.kt | 36 +++++++++---------- 27 files changed, 110 insertions(+), 91 deletions(-) create mode 100644 src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Authority.kt rename src/main/kotlin/com/sexysisters/tojserverv2/domain/user/{ => domain}/Email.kt (85%) rename src/main/kotlin/com/sexysisters/tojserverv2/domain/user/{ => domain}/Image.kt (81%) rename src/main/kotlin/com/sexysisters/tojserverv2/domain/user/{ => domain}/Name.kt (84%) rename src/main/kotlin/com/sexysisters/tojserverv2/domain/user/{type => domain}/Nickname.kt (84%) rename src/main/kotlin/com/sexysisters/tojserverv2/domain/user/{ => domain}/Password.kt (85%) rename src/main/kotlin/com/sexysisters/tojserverv2/domain/user/{ => domain}/User.kt (79%) delete mode 100644 src/main/kotlin/com/sexysisters/tojserverv2/domain/user/type/Authority.kt diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/common/security/auth/AuthDetails.kt b/src/main/kotlin/com/sexysisters/tojserverv2/common/security/auth/AuthDetails.kt index 54c27eb..2cc9873 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/common/security/auth/AuthDetails.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/common/security/auth/AuthDetails.kt @@ -1,6 +1,6 @@ package com.sexysisters.tojserverv2.common.security.auth -import com.sexysisters.tojserverv2.domain.user.User +import com.sexysisters.tojserverv2.domain.user.domain.User import org.springframework.security.core.authority.SimpleGrantedAuthority import org.springframework.security.core.userdetails.UserDetails @@ -10,9 +10,9 @@ class AuthDetails( override fun getAuthorities() = mutableListOf(SimpleGrantedAuthority(user.authority.name)) - override fun getPassword() = this.user.password + override fun getPassword() = this.user.passwordValue() - override fun getUsername() = this.user.email + override fun getUsername() = this.user.emailValue() override fun isAccountNonExpired() = true diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/auth/service/AuthServiceImpl.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/auth/service/AuthServiceImpl.kt index ee65efc..63cd8a5 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/auth/service/AuthServiceImpl.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/auth/service/AuthServiceImpl.kt @@ -16,7 +16,7 @@ import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.time.Duration -import java.util.Date +import java.util.* @Service class AuthServiceImpl( @@ -33,7 +33,7 @@ class AuthServiceImpl( override fun login(command: AuthCommand.LoginRequest): AuthInfo.Token { val email = command.email val user = userReader.getUser(email) - checkPassword(command.password, user.password) + checkPassword(command.password, user.passwordValue()) val accessToken = jwtTokenProvider.createAccessToken(email) val refreshToken = jwtTokenProvider.createRefreshToken(email) @@ -63,7 +63,7 @@ class AuthServiceImpl( val parsedAccessToken = jwtTokenProvider.parseToken(accessToken)!! val remainTime = jwtTokenProvider.getExpiredTime(parsedAccessToken).time - Date().time redisRepository.setBlackList(parsedAccessToken, Duration.ofMillis(remainTime)) - redisRepository.deleteData(user.email) + redisRepository.deleteData(user.emailValue()) } @Transactional(readOnly = true) diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/school/policy/AlreadyExistsStudentPolicy.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/school/policy/AlreadyExistsStudentPolicy.kt index 9c9ba1a..ecf5580 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/school/policy/AlreadyExistsStudentPolicy.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/school/policy/AlreadyExistsStudentPolicy.kt @@ -19,9 +19,9 @@ class AlreadyExistsStudentPolicy( override fun check(student: Student, school: School) { val hasStudent = studentRepository.checkAlreadyExists( school = school, - grade = student.getGradeValue(), - classroom = student.getClassroomValue(), - number = student.getNumberValue(), + grade = student.gradeValue(), + classroom = student.classroomValue(), + number = student.numberValue(), ) if (hasStudent) { throw SchoolException.StudentAlreadyExists() diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/school/policy/InfoRangePolicy.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/school/policy/InfoRangePolicy.kt index 28898de..b5c3b84 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/school/policy/InfoRangePolicy.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/school/policy/InfoRangePolicy.kt @@ -19,9 +19,9 @@ class InfoRangePolicy : SchoolPolicy { override fun check(student: Student, school: School) { val schoolDivision = school.division - val grade = student.getGradeValue() - val classroom = student.getClassroomValue() - val number = student.getNumberValue() + val grade = student.gradeValue() + val classroom = student.classroomValue() + val number = student.numberValue() val isValidGrade = when (schoolDivision) { Division.ELEMENTARY -> grade in 1..6 diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/student/domain/Student.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/student/domain/Student.kt index 9608612..7995c4b 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/student/domain/Student.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/student/domain/Student.kt @@ -3,16 +3,16 @@ package com.sexysisters.tojserverv2.domain.student.domain import com.sexysisters.tojserverv2.domain.BaseTimeEntity import com.sexysisters.tojserverv2.domain.approve.Approve import com.sexysisters.tojserverv2.domain.school.domain.School -import com.sexysisters.tojserverv2.domain.user.User +import com.sexysisters.tojserverv2.domain.user.domain.User import javax.persistence.* @Entity @Table(name = "tbl_student") class Student( - @Embedded private val grade: Grade, - @Embedded private val classroom: Classroom, - @Embedded private val number: Number, - @Embedded private val age: Age, + @Embedded val grade: Grade, + @Embedded val classroom: Classroom, + @Embedded val number: Number, + @Embedded val age: Age, ) : BaseTimeEntity() { @Enumerated(EnumType.STRING) @@ -36,10 +36,10 @@ class Student( @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long = 0L - fun getGradeValue() = grade.value - fun getClassroomValue() = classroom.value - fun getNumberValue() = number.value - fun getAgeValue() = age.value + fun gradeValue() = grade.value + fun classroomValue() = classroom.value + fun numberValue() = number.value + fun ageValue() = age.value } fun Student.makeRelation(user: User) { diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/student/policy/AlreadyCreatedPolicy.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/student/policy/AlreadyCreatedPolicy.kt index 6bcd83d..1467219 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/student/policy/AlreadyCreatedPolicy.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/student/policy/AlreadyCreatedPolicy.kt @@ -1,7 +1,8 @@ package com.sexysisters.tojserverv2.domain.student.policy import com.sexysisters.tojserverv2.domain.student.exception.StudentException -import com.sexysisters.tojserverv2.domain.user.User +import com.sexysisters.tojserverv2.domain.user.domain.User +import com.sexysisters.tojserverv2.domain.user.domain.hasStudent import org.springframework.core.annotation.Order import org.springframework.stereotype.Component @@ -13,8 +14,7 @@ import org.springframework.stereotype.Component class AlreadyCreatedPolicy : StudentPolicy { override fun check(user: User) { - val hasStudent = user.student != null - if (hasStudent) { + if (user.hasStudent()) { throw StudentException.AlreadyCreated() } } diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/student/policy/StudentPolicy.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/student/policy/StudentPolicy.kt index 5977c68..a6e0d9f 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/student/policy/StudentPolicy.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/student/policy/StudentPolicy.kt @@ -1,6 +1,6 @@ package com.sexysisters.tojserverv2.domain.student.policy -import com.sexysisters.tojserverv2.domain.user.User +import com.sexysisters.tojserverv2.domain.user.domain.User interface StudentPolicy { fun check(user: User) diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/teacher/service/TeacherServiceImpl.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/teacher/service/TeacherServiceImpl.kt index 9a5f491..7874976 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/teacher/service/TeacherServiceImpl.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/teacher/service/TeacherServiceImpl.kt @@ -7,7 +7,7 @@ import com.sexysisters.tojserverv2.domain.student.exception.StudentException import com.sexysisters.tojserverv2.domain.teacher.* import com.sexysisters.tojserverv2.domain.teacher.domain.* import com.sexysisters.tojserverv2.domain.user.UserReader -import com.sexysisters.tojserverv2.domain.user.hasStudent +import com.sexysisters.tojserverv2.domain.user.domain.hasStudent import com.sexysisters.tojserverv2.interfaces.teacher.dto.TeacherDtoMapper import com.sexysisters.tojserverv2.interfaces.teacher.dto.TeacherResponse import org.springframework.stereotype.Service diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserCommand.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserCommand.kt index 3a9199a..3ce0890 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserCommand.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserCommand.kt @@ -1,7 +1,8 @@ package com.sexysisters.tojserverv2.domain.user import com.sexysisters.tojserverv2.config.properties.S3Properties -import com.sexysisters.tojserverv2.domain.user.type.Nickname +import com.sexysisters.tojserverv2.domain.user.domain.* +import com.sexysisters.tojserverv2.domain.user.domain.Nickname import org.springframework.security.crypto.password.PasswordEncoder class UserCommand { diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserMapper.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserMapper.kt index e9e3c19..43ef0be 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserMapper.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserMapper.kt @@ -1,8 +1,7 @@ package com.sexysisters.tojserverv2.domain.user -import org.mapstruct.InjectionStrategy -import org.mapstruct.Mapper -import org.mapstruct.ReportingPolicy +import com.sexysisters.tojserverv2.domain.user.domain.User +import org.mapstruct.* @Mapper( componentModel = "spring", @@ -10,5 +9,14 @@ import org.mapstruct.ReportingPolicy unmappedTargetPolicy = ReportingPolicy.ERROR, ) interface UserMapper { + + @Mappings( + value = [ + Mapping(source = "email.value", target = "email"), + Mapping(source = "nickname.value", target = "nickname"), + Mapping(source = "image.value", target = "profileImg"), + Mapping(source = "name.value", target = "name"), + ] + ) fun of(user: User): UserInfo.Profile } \ No newline at end of file diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserReader.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserReader.kt index 2a522b4..cbb1e71 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserReader.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserReader.kt @@ -1,5 +1,7 @@ package com.sexysisters.tojserverv2.domain.user +import com.sexysisters.tojserverv2.domain.user.domain.User + interface UserReader { fun getUser(email: String): User fun getUser(id: Long): User diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserStore.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserStore.kt index f860c84..78972c3 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserStore.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/UserStore.kt @@ -1,5 +1,7 @@ package com.sexysisters.tojserverv2.domain.user +import com.sexysisters.tojserverv2.domain.user.domain.User + interface UserStore { fun store(user: User): User fun storeOAuthUser(user: User) diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Authority.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Authority.kt new file mode 100644 index 0000000..f2d05f6 --- /dev/null +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Authority.kt @@ -0,0 +1,5 @@ +package com.sexysisters.tojserverv2.domain.user.domain + +enum class Authority { + ADMIN, USER +} \ No newline at end of file diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Email.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Email.kt similarity index 85% rename from src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Email.kt rename to src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Email.kt index b422942..7fa4145 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Email.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Email.kt @@ -1,4 +1,4 @@ -package com.sexysisters.tojserverv2.domain.user +package com.sexysisters.tojserverv2.domain.user.domain import com.sexysisters.tojserverv2.domain.user.exception.UserException import javax.persistence.Column @@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull class Email( @field:NotNull @Column(name = "email") - private val value: String, + val value: String, ) { init { val EMAIL_FORMAT = "@" diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Image.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Image.kt similarity index 81% rename from src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Image.kt rename to src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Image.kt index 8ebdb5a..77ac4eb 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Image.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Image.kt @@ -1,4 +1,4 @@ -package com.sexysisters.tojserverv2.domain.user +package com.sexysisters.tojserverv2.domain.user.domain import com.sexysisters.tojserverv2.domain.user.exception.UserException import javax.persistence.Column @@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull class Image( @field:NotNull @Column(name = "image") - private val value: String, + val value: String, ) { init { if (value.isBlank()) throw UserException.UserNotValid() diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Name.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Name.kt similarity index 84% rename from src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Name.kt rename to src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Name.kt index 3795108..2b17a3d 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Name.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Name.kt @@ -1,4 +1,4 @@ -package com.sexysisters.tojserverv2.domain.user +package com.sexysisters.tojserverv2.domain.user.domain import com.sexysisters.tojserverv2.domain.user.exception.UserException import javax.persistence.Column @@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull class Name( @field:NotNull @Column(name = "name") - private val value: String, + val value: String, ) { init { val MAX_LENGTH = 20 diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/type/Nickname.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Nickname.kt similarity index 84% rename from src/main/kotlin/com/sexysisters/tojserverv2/domain/user/type/Nickname.kt rename to src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Nickname.kt index b22e1c2..78f09ea 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/type/Nickname.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Nickname.kt @@ -1,4 +1,4 @@ -package com.sexysisters.tojserverv2.domain.user.type +package com.sexysisters.tojserverv2.domain.user.domain import com.sexysisters.tojserverv2.domain.user.exception.UserException import javax.persistence.Column @@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull class Nickname( @field:NotNull @Column(name = "nickname", unique = true) - private val value: String, + val value: String, ) { init { val MAX_LENGTH = 21 diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Password.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Password.kt similarity index 85% rename from src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Password.kt rename to src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Password.kt index 7278913..ea058c9 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Password.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/Password.kt @@ -1,4 +1,4 @@ -package com.sexysisters.tojserverv2.domain.user +package com.sexysisters.tojserverv2.domain.user.domain import com.sexysisters.tojserverv2.domain.user.exception.UserException import javax.persistence.Column @@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull class Password( @field:NotNull @Column(name = "password") - private val value: String + val value: String ) { init { val MAX_LENGTH = 20 diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/User.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/User.kt similarity index 79% rename from src/main/kotlin/com/sexysisters/tojserverv2/domain/user/User.kt rename to src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/User.kt index e325dce..4387811 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/User.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/domain/User.kt @@ -1,9 +1,7 @@ -package com.sexysisters.tojserverv2.domain.user +package com.sexysisters.tojserverv2.domain.user.domain import com.sexysisters.tojserverv2.domain.BaseTimeEntity import com.sexysisters.tojserverv2.domain.student.domain.Student -import com.sexysisters.tojserverv2.domain.user.type.Authority -import com.sexysisters.tojserverv2.domain.user.type.Nickname import javax.persistence.* @Entity @@ -25,6 +23,12 @@ class User( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long = 0L + + fun emailValue() = email.value + fun passwordValue() = password.value + fun nicknameValue() = nickname.value + fun imageValue() = image.value + fun nameValue() = name.value } fun User.updateInfo( diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/service/OAuthServiceImpl.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/service/OAuthServiceImpl.kt index 06bbdda..560fceb 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/service/OAuthServiceImpl.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/service/OAuthServiceImpl.kt @@ -1,8 +1,9 @@ package com.sexysisters.tojserverv2.domain.user.service +import com.sexysisters.tojserverv2.common.util.api.oauth.dto.OAuthInfoResponse import com.sexysisters.tojserverv2.domain.auth.AuthInfo -import com.sexysisters.tojserverv2.domain.user.User import com.sexysisters.tojserverv2.domain.user.UserStore +import com.sexysisters.tojserverv2.domain.user.domain.* import com.sexysisters.tojserverv2.infrastructure.jwt.JwtTokenProvider import com.sexysisters.tojserverv2.infrastructure.oauth.OAuthExecutor import org.springframework.stereotype.Service @@ -20,18 +21,19 @@ class OAuthServiceImpl( @Transactional override fun googleLogin(code: String): AuthInfo.Token { val oAuthResponse = googleAuthExecutor.execute(code) - val initUser = User( - nickname = oAuthResponse.name, - email = oAuthResponse.email, - profileImg = oAuthResponse.picture, - password = "OAUTH", - name = "이름" - ) + val initUser = createUser(oAuthResponse) userStore.storeOAuthUser(initUser) - return AuthInfo.Token( - accessToken = jwtTokenProvider.createAccessToken(initUser.email), - refreshToken = jwtTokenProvider.createRefreshToken(initUser.email), + accessToken = jwtTokenProvider.createAccessToken(initUser.emailValue()), + refreshToken = jwtTokenProvider.createRefreshToken(initUser.emailValue()), ) } + + private fun createUser(response: OAuthInfoResponse) = User( + nickname = Nickname(response.name), + email = Email(response.email), + image = Image(response.picture), + password = Password("OAUTH"), + name = Name("이름") + ) } \ No newline at end of file diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/service/UserServiceImpl.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/service/UserServiceImpl.kt index c6a21a4..c50d03b 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/service/UserServiceImpl.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/service/UserServiceImpl.kt @@ -7,8 +7,8 @@ import com.sexysisters.tojserverv2.domain.user.UserReader import com.sexysisters.tojserverv2.domain.user.UserStore import com.sexysisters.tojserverv2.domain.user.setEncodedPassword import com.sexysisters.tojserverv2.domain.user.toEntity -import com.sexysisters.tojserverv2.domain.user.updateInfo -import com.sexysisters.tojserverv2.domain.user.updateProfileImg +import com.sexysisters.tojserverv2.domain.user.domain.updateInfo +import com.sexysisters.tojserverv2.domain.user.domain.updateProfileImg import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/type/Authority.kt b/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/type/Authority.kt deleted file mode 100644 index 40cd3a3..0000000 --- a/src/main/kotlin/com/sexysisters/tojserverv2/domain/user/type/Authority.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.sexysisters.tojserverv2.domain.user.type - -enum class Authority { - ADMIN, USER -} \ No newline at end of file diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/infrastructure/user/UserReaderImpl.kt b/src/main/kotlin/com/sexysisters/tojserverv2/infrastructure/user/UserReaderImpl.kt index 92c2d34..6444e57 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/infrastructure/user/UserReaderImpl.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/infrastructure/user/UserReaderImpl.kt @@ -1,7 +1,7 @@ package com.sexysisters.tojserverv2.infrastructure.user import com.sexysisters.tojserverv2.common.security.auth.AuthDetails -import com.sexysisters.tojserverv2.domain.user.User +import com.sexysisters.tojserverv2.domain.user.domain.User import com.sexysisters.tojserverv2.domain.user.UserReader import com.sexysisters.tojserverv2.domain.user.exception.UserException import org.springframework.data.repository.findByIdOrNull diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/infrastructure/user/UserRepository.kt b/src/main/kotlin/com/sexysisters/tojserverv2/infrastructure/user/UserRepository.kt index 1138c11..9c733d1 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/infrastructure/user/UserRepository.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/infrastructure/user/UserRepository.kt @@ -1,6 +1,6 @@ package com.sexysisters.tojserverv2.infrastructure.user -import com.sexysisters.tojserverv2.domain.user.User +import com.sexysisters.tojserverv2.domain.user.domain.User import org.springframework.data.jpa.repository.JpaRepository interface UserRepository : JpaRepository { diff --git a/src/main/kotlin/com/sexysisters/tojserverv2/infrastructure/user/UserStoreImpl.kt b/src/main/kotlin/com/sexysisters/tojserverv2/infrastructure/user/UserStoreImpl.kt index fca3d81..f92d62b 100644 --- a/src/main/kotlin/com/sexysisters/tojserverv2/infrastructure/user/UserStoreImpl.kt +++ b/src/main/kotlin/com/sexysisters/tojserverv2/infrastructure/user/UserStoreImpl.kt @@ -1,6 +1,6 @@ package com.sexysisters.tojserverv2.infrastructure.user -import com.sexysisters.tojserverv2.domain.user.User +import com.sexysisters.tojserverv2.domain.user.domain.User import com.sexysisters.tojserverv2.domain.user.UserStore import com.sexysisters.tojserverv2.domain.user.exception.UserException import org.springframework.stereotype.Component @@ -11,7 +11,7 @@ class UserStoreImpl( ) : UserStore { override fun store(user: User): User { - validation(user.email, user.nickname) + validation(user.emailValue(), user.nicknameValue()) return userRepository.save(user) } @@ -26,5 +26,5 @@ class UserStoreImpl( } } - private fun isAlreadyExists(user: User) = userRepository.existsByEmail(user.email) + private fun isAlreadyExists(user: User) = userRepository.existsByEmail(user.emailValue()) } \ No newline at end of file diff --git a/src/test/kotlin/com/sexysisters/tojserverv2/domain/auth/service/AuthServiceTest.kt b/src/test/kotlin/com/sexysisters/tojserverv2/domain/auth/service/AuthServiceTest.kt index 7891328..a5dfae0 100644 --- a/src/test/kotlin/com/sexysisters/tojserverv2/domain/auth/service/AuthServiceTest.kt +++ b/src/test/kotlin/com/sexysisters/tojserverv2/domain/auth/service/AuthServiceTest.kt @@ -4,8 +4,8 @@ import com.sexysisters.tojserverv2.config.properties.JwtProperties import com.sexysisters.tojserverv2.domain.auth.AuthCommand import com.sexysisters.tojserverv2.domain.auth.exception.AuthErrorCode import com.sexysisters.tojserverv2.domain.auth.exception.AuthException -import com.sexysisters.tojserverv2.domain.user.User import com.sexysisters.tojserverv2.domain.user.UserReader +import com.sexysisters.tojserverv2.domain.user.domain.* import com.sexysisters.tojserverv2.infrastructure.jwt.JwtTokenProvider import com.sexysisters.tojserverv2.infrastructure.jwt.JwtValidator import com.sexysisters.tojserverv2.infrastructure.mail.MailSenderImpl @@ -36,18 +36,18 @@ val target = AuthServiceImpl( ) val user = User( - name = "이규진", - nickname = "청출어람", - email = "email", - password = "password", - profileImg = "추후 수정", + name = Name("이규진"), + nickname = Nickname("청출어람"), + email = Email("email@email.com"), + password = Password("password"), + image = Image("추후 수정)") ) class AuthServiceTest : BehaviorSpec({ Given("로그인 성공 answer 정의") { - val email = "email" + val email = "email@email.com" val accessToken = "accessToken" val refreshToken = "refreshToken" diff --git a/src/test/kotlin/com/sexysisters/tojserverv2/domain/user/service/UserServiceTest.kt b/src/test/kotlin/com/sexysisters/tojserverv2/domain/user/service/UserServiceTest.kt index 551f3ce..bcdf3e9 100644 --- a/src/test/kotlin/com/sexysisters/tojserverv2/domain/user/service/UserServiceTest.kt +++ b/src/test/kotlin/com/sexysisters/tojserverv2/domain/user/service/UserServiceTest.kt @@ -2,7 +2,7 @@ package com.sexysisters.tojserverv2.domain.user.service import com.sexysisters.tojserverv2.config.properties.S3Properties import com.sexysisters.tojserverv2.domain.user.* -import com.sexysisters.tojserverv2.domain.user.type.Authority +import com.sexysisters.tojserverv2.domain.user.domain.* import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe import io.mockk.every @@ -25,11 +25,11 @@ val target = UserServiceImpl( ) val user = User( - name = "이규진", - nickname = "청출어람", - email = "leekujin14@gmail.com", - password = "enCodedPassword", - profileImg = S3Properties.defaultProfileImg, + name = Name("이규진"), + nickname = Nickname("청출어람"), + email = Email("leekujin14@gmail.com"), + password = Password("enCodedPassword"), + image = Image(S3Properties.defaultProfileImg) ) class UserServiceTest : BehaviorSpec({ @@ -52,11 +52,11 @@ class UserServiceTest : BehaviorSpec({ Then("Command가 정상적으로 Entity로 변환되어야 한다.") { val userEntity = userCapture.captured - userEntity.email shouldBe createRequest.email - userEntity.nickname shouldBe createRequest.nickname - userEntity.password shouldBe "encodedPassword" + userEntity.emailValue() shouldBe createRequest.email + userEntity.nicknameValue() shouldBe createRequest.nickname + userEntity.passwordValue() shouldBe "encodedPassword" userEntity.authority shouldBe Authority.USER - userEntity.profileImg shouldBe S3Properties.defaultProfileImg + userEntity.imageValue() shouldBe S3Properties.defaultProfileImg } Then("PasswordEncoder와 UserStore 로직이 동작해야 한다.") { @@ -78,10 +78,10 @@ class UserServiceTest : BehaviorSpec({ Then("정확한 유저 프로필이 조회되어야 한다.") { userIdCapture.captured shouldBe userId - userInfo.email shouldBe user.email - userInfo.nickname shouldBe user.nickname - userInfo.profileImg shouldBe user.profileImg - userInfo.name shouldBe user.name + userInfo.email shouldBe user.emailValue() + userInfo.nickname shouldBe user.nicknameValue() + userInfo.profileImg shouldBe user.imageValue() + userInfo.name shouldBe user.nameValue() // TODO :: add properties -> description, age, school, ... } @@ -98,10 +98,10 @@ class UserServiceTest : BehaviorSpec({ val userInfo = target.findCurrentUserProfile() Then("정확한 값이 반환되어야 한다.") { - userInfo.email shouldBe user.email - userInfo.nickname shouldBe user.nickname - userInfo.profileImg shouldBe user.profileImg - userInfo.name shouldBe user.name + userInfo.email shouldBe user.emailValue() + userInfo.nickname shouldBe user.nicknameValue() + userInfo.profileImg shouldBe user.imageValue() + userInfo.name shouldBe user.nameValue() } } }