-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: 유저 회원가입 플로우 (TEMP_USER -> USER) #10
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cef8d33
feat: VacgomId 엔티티 추가
h-beeen 02fbf9f
feat: vacgomId validation checker API
h-beeen afb3981
feat: 백곰 아이디 영문 소문자로 시작 Regex
h-beeen 15090dc
feat: Security Logger 개선
h-beeen 78181a6
feat: Init HealthProfile Entity
h-beeen 578f1e7
refactor: 불필요 엔티티 제거
h-beeen d07a305
feat: 유저 회원가입 플로우(TEMP_USER -> USER)
h-beeen e4f13ac
feat: 백곰 아이디 -> 닉네임 명명 수정
h-beeen b3d2bdb
fix: 이름, 생일, 성별 저장 오류 수정
h-beeen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...end/application/auth/dto/LoginResponse.kt → ...kend/application/auth/dto/AuthResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package com.vacgom.backend.application.auth.dto | ||
|
||
data class LoginResponse( | ||
data class AuthResponse( | ||
val member: MemberResponse, | ||
val token: TokenResponse | ||
) |
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/com/vacgom/backend/application/auth/dto/ResourceIdResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.vacgom.backend.application.auth.dto | ||
|
||
data class ResourceIdResponse( | ||
var id: Long | ||
val id: Long | ||
) |
57 changes: 57 additions & 0 deletions
57
src/main/kotlin/com/vacgom/backend/application/member/MemberService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.vacgom.backend.application.member | ||
|
||
import com.vacgom.backend.application.auth.dto.AuthResponse | ||
import com.vacgom.backend.application.auth.dto.MemberResponse | ||
import com.vacgom.backend.application.auth.dto.TokenResponse | ||
import com.vacgom.backend.application.member.dto.request.SignUpRequest | ||
import com.vacgom.backend.domain.auth.constants.Role | ||
import com.vacgom.backend.domain.member.HealthProfile | ||
import com.vacgom.backend.domain.member.MemberDetails | ||
import com.vacgom.backend.domain.member.Nickname | ||
import com.vacgom.backend.exception.member.MemberError | ||
import com.vacgom.backend.exception.member.NicknameError | ||
import com.vacgom.backend.global.exception.error.BusinessException | ||
import com.vacgom.backend.global.security.jwt.JwtFactory | ||
import com.vacgom.backend.infrastructure.member.persistence.HealthProfileRepository | ||
import com.vacgom.backend.infrastructure.member.persistence.MemberRepository | ||
import jakarta.transaction.Transactional | ||
import org.springframework.stereotype.Service | ||
import java.util.* | ||
|
||
@Service | ||
@Transactional | ||
class MemberService( | ||
private val memberRepository: MemberRepository, | ||
private val healthProfileRepository: HealthProfileRepository, | ||
private val jwtFactory: JwtFactory | ||
) { | ||
fun validateNickname(id: String) { | ||
val nickname = Nickname(id) | ||
if (memberRepository.existsMemberByNickname(nickname)) | ||
throw BusinessException(NicknameError.DUPLICATED) | ||
} | ||
|
||
fun signUpVacgom( | ||
memberId: UUID, | ||
request: SignUpRequest | ||
): AuthResponse { | ||
val member = memberRepository.findById(memberId).orElseThrow { BusinessException(MemberError.NOT_FOUND) } | ||
val nickname = Nickname(request.nickname) | ||
val memberDetails = MemberDetails(request.name, request.birthday, request.sex) | ||
|
||
member.updateNickname(nickname) | ||
member.updateMemberDetails(memberDetails) | ||
member.updateRole(Role.ROLE_USER) | ||
|
||
val healthConditions = request.healthConditions.stream() | ||
.map { condition -> | ||
HealthProfile(member, condition) | ||
}.toList() | ||
healthProfileRepository.saveAll(healthConditions) | ||
|
||
val memberResponse = MemberResponse(member.id!!, member.role) | ||
val tokenResponse = TokenResponse(jwtFactory.createAccessToken(member)) | ||
|
||
return AuthResponse(memberResponse, tokenResponse) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com/vacgom/backend/application/member/dto/request/SignUpRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.vacgom.backend.application.member.dto.request | ||
|
||
import com.vacgom.backend.domain.member.constants.HealthCondition | ||
|
||
data class SignUpRequest( | ||
val name: String, | ||
val birthday: String, | ||
val sex: String, | ||
val healthConditions: MutableList<HealthCondition>, | ||
val nickname: String | ||
) |
24 changes: 0 additions & 24 deletions
24
src/main/kotlin/com/vacgom/backend/domain/auth/RefreshToken.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/vacgom/backend/domain/member/HealthProfile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.vacgom.backend.domain.member | ||
|
||
import com.vacgom.backend.domain.member.constants.HealthCondition | ||
import jakarta.persistence.* | ||
import org.hibernate.annotations.GenericGenerator | ||
import java.util.* | ||
|
||
@Entity | ||
@Table(name = "t_health_profile") | ||
class HealthProfile( | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
var member: Member, | ||
|
||
@Enumerated(value = EnumType.STRING) | ||
var healthCondition: HealthCondition | ||
) { | ||
@Id | ||
@GeneratedValue(generator = "uuid2") | ||
@GenericGenerator(name = "uuid2", strategy = "uuid2") | ||
@Column(columnDefinition = "BINARY(16)", name = "health_profile_id") | ||
val id: UUID? = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/vacgom/backend/domain/member/MemberDetails.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.vacgom.backend.domain.member | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat | ||
import com.vacgom.backend.domain.member.constants.Sex | ||
import jakarta.persistence.Embeddable | ||
import jakarta.persistence.EnumType | ||
import jakarta.persistence.Enumerated | ||
import java.time.LocalDate | ||
import java.time.format.DateTimeFormatter | ||
|
||
@Embeddable | ||
class MemberDetails( | ||
var name: String, | ||
|
||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") | ||
var birthday: LocalDate, | ||
|
||
@Enumerated(EnumType.STRING) | ||
var sex: Sex | ||
) { | ||
constructor(name: String, birthday: String, sex: String) : this( | ||
name, | ||
LocalDate.parse(birthday, DateTimeFormatter.ofPattern("yyyy-MM-dd")), | ||
Sex.valueOf(sex) | ||
) | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/com/vacgom/backend/domain/member/Nickname.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.vacgom.backend.domain.member | ||
|
||
import com.vacgom.backend.exception.member.NicknameError | ||
import com.vacgom.backend.global.exception.error.BusinessException | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Embeddable | ||
|
||
@Embeddable | ||
class Nickname( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 객체에 제약 거는거 좋아하는건 또 어케 하시고 .. |
||
@Column(unique = true) var nickname: String | ||
) { | ||
companion object { | ||
private const val VACGOM_ID_REGEX = "[a-z0-9_]+" | ||
private const val START_WITH_LOWER_CASE_REGEX = "^[a-z].*" | ||
private const val CONSECUTIVE_UNDERSCORES = "____" | ||
private const val MINIMUM_LENGTH = 4 | ||
private const val MAXIMUM_LENGTH = 10 | ||
} | ||
|
||
init { | ||
validatePattern(nickname) | ||
} | ||
|
||
private fun validatePattern(id: String) { | ||
require(id.matches(START_WITH_LOWER_CASE_REGEX.toRegex())) { | ||
throw BusinessException(NicknameError.NOT_START_WITH_LOWER_CASE) | ||
} | ||
require(id.matches(VACGOM_ID_REGEX.toRegex())) { | ||
throw BusinessException(NicknameError.INVALID_VACGOM_ID_PATTERN) | ||
} | ||
require(CONSECUTIVE_UNDERSCORES !in id) { | ||
throw BusinessException(NicknameError.CONSECUTIVE_UNDERSCORES) | ||
} | ||
require(id.length in MINIMUM_LENGTH..MAXIMUM_LENGTH) { | ||
throw BusinessException(NicknameError.INVALID_LENGTH) | ||
} | ||
|
||
val lowerCaseCount = id.count { it.isLowerCase() } | ||
require(lowerCaseCount >= 4) { | ||
throw BusinessException(NicknameError.MINIMUM_LOWERCASE_REQUIRED) | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/com/vacgom/backend/domain/member/constants/HealthCondition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.vacgom.backend.domain.member.constants | ||
|
||
enum class HealthCondition( | ||
val code: Long, | ||
val description: String | ||
) { | ||
DIABETES(1, "당뇨병"), | ||
CHRONIC_CARDIOVASCULAR_DISEASE(2, "만성 심혈관질환"), | ||
CHRONIC_PULMONARY_DISEASE(3, "만성 폐질환"), | ||
CHRONIC_RENAL_DISEASE(4, "만성 신질환"), | ||
CHRONIC_LIVER_DISEASE(5, "만성 간질환"), | ||
SOLID_TUMOR_UNDERGOING_ANTINEOPLASTIC_THERAPY(6, "항암치료중인 고형암"), | ||
IMMUNOSUPPRESSIVE_AGENTS_EXCLUDING_TRANSPLANT(7, "이식 이외 면역 억제제 사용"), | ||
HEMATOPOIETIC_STEM_CELL_TRANSPLANTATION(8, "조혈모"), | ||
CELL_TRANSPLANTATION(9, "세포이식"), | ||
SICKLE_CELL_DISEASE(10, "무비증"), | ||
HIV_INFECTION_CD4_ABOVE_200(11, "HIV 감염:CD4>=200/mm3"), | ||
HIV_INFECTION_CD4_BELOW_200(11, "HIV 감염:CD4<200/mm3"), | ||
PREGNANCY(12, "임신"), | ||
MEDICAL_WORKER(13, "의료기관 종사자"), | ||
ORGAN_TRANSPLANTATION(14, "장기 이식 경험") | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/vacgom/backend/domain/member/constants/Sex.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.vacgom.backend.domain.member.constants | ||
|
||
enum class Sex { | ||
MALE, | ||
FEMALE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/vacgom/backend/exception/member/NicknameError.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.vacgom.backend.exception.member | ||
|
||
import com.vacgom.backend.global.exception.error.ErrorCode | ||
import org.springframework.http.HttpStatus | ||
|
||
|
||
enum class NicknameError( | ||
override val message: String, | ||
override val status: HttpStatus, | ||
override val code: String | ||
) : ErrorCode { | ||
INVALID_VACGOM_ID_PATTERN("닉네임은 영문 소문자, 숫자, 언더바(_)로만 구성되어야 합니다.", HttpStatus.BAD_REQUEST, "VI_001"), | ||
NOT_START_WITH_LOWER_CASE("닉네임은 영문 소문자로 시작해야 합니다", HttpStatus.BAD_REQUEST, "VI_002"), | ||
CONSECUTIVE_UNDERSCORES("언더바(_)는 최대 3개 까지 연속으로 사용할 수 있습니다.", HttpStatus.BAD_REQUEST, "VI_003"), | ||
DUPLICATED("이미 사용중인 닉네임입니다.", HttpStatus.BAD_REQUEST, "VI_004"), | ||
INVALID_LENGTH("닉네임은 4 ~ 20자 이하여야 합니다.", HttpStatus.BAD_REQUEST, "VI_005"), | ||
MINIMUM_LOWERCASE_REQUIRED("최소 4개의 소문자 영어를 포함해야 합니다.", HttpStatus.BAD_REQUEST, "VI_006"), | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기서 나중엔 백신접종내역 추가되는ㄱ게 맞나요?