Skip to content

Commit 9958fd1

Browse files
committed
[DVK-6] fix: 회원정보 수정 API에 이메일 추가
1 parent 74010b3 commit 9958fd1

File tree

10 files changed

+58
-48
lines changed

10 files changed

+58
-48
lines changed

src/main/kotlin/com/devooks/backend/member/v1/controller/MemberController.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,11 @@ class MemberController(
154154
val requesterId: UUID = tokenService.getMemberId(Authorization(authorization))
155155
val command: ModifyProfileCommand = request.toCommand()
156156
val memberInfo: MemberInfo = memberInfoService.updateProfile(command, requesterId)
157-
val categories: List<Category> = categoryService.getAll(command.favoriteCategoryIdList)
158-
favoriteCategoryService.deleteByMemberId(requesterId)
159-
favoriteCategoryService.save(categories, requesterId)
157+
val categories = command.favoriteCategoryIdList?.let {
158+
val categories: List<Category> = categoryService.getAll(it)
159+
favoriteCategoryService.deleteByMemberId(requesterId)
160+
favoriteCategoryService.save(categories, requesterId)
161+
}.let { favoriteCategoryService.findByMemberId(requesterId) }
160162
return ModifyProfileResponse(memberInfo, categories)
161163
}
162164

src/main/kotlin/com/devooks/backend/member/v1/domain/MemberInfo.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class MemberInfo(
1414
val accountNumber: String,
1515
val introduction: String,
1616
val phoneNumber: String,
17+
val email: String,
1718
) {
1819
companion object {
1920
fun MemberInfoEntity.toDomain(): MemberInfo =
@@ -28,6 +29,7 @@ class MemberInfo(
2829
accountNumber = this.accountNumber,
2930
introduction = this.introduction,
3031
phoneNumber = this.phoneNumber,
32+
email = this.email,
3133
)
3234
}
33-
}
35+
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.devooks.backend.member.v1.dto
22

3-
import java.util.UUID
3+
import java.util.*
44

55
class ModifyProfileCommand(
6-
val phoneNumber: String,
7-
val blogLink: String,
8-
val instagramLink: String,
9-
val youtubeLink: String,
10-
val introduction: String,
11-
val favoriteCategoryIdList: List<UUID>,
6+
val phoneNumber: String?,
7+
val blogLink: String?,
8+
val instagramLink: String?,
9+
val youtubeLink: String?,
10+
val introduction: String?,
11+
val favoriteCategoryIdList: List<UUID>?,
12+
val email: String?,
1213
)
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.devooks.backend.member.v1.dto
22

33
import com.devooks.backend.member.v1.error.validateBlogLink
4+
import com.devooks.backend.member.v1.error.validateEmail
45
import com.devooks.backend.member.v1.error.validateFavoriteCategoryIdList
56
import com.devooks.backend.member.v1.error.validateInstagramLink
67
import com.devooks.backend.member.v1.error.validateIntroduction
@@ -14,14 +15,16 @@ data class ModifyProfileRequest(
1415
val youtubeLink: String?,
1516
val introduction: String?,
1617
val favoriteCategoryIdList: List<String>?,
18+
val email: String?,
1719
) {
1820
fun toCommand(): ModifyProfileCommand =
1921
ModifyProfileCommand(
20-
phoneNumber = phoneNumber.validatePhoneNumber(),
21-
blogLink = blogLink.validateBlogLink(),
22-
instagramLink = instagramLink.validateInstagramLink(),
23-
youtubeLink = youtubeLink.validateYoutubeLink(),
24-
introduction = introduction.validateIntroduction(),
25-
favoriteCategoryIdList = favoriteCategoryIdList.validateFavoriteCategoryIdList()
22+
phoneNumber = phoneNumber?.validatePhoneNumber(),
23+
blogLink = blogLink?.validateBlogLink(),
24+
instagramLink = instagramLink?.validateInstagramLink(),
25+
youtubeLink = youtubeLink?.validateYoutubeLink(),
26+
introduction = introduction?.validateIntroduction(),
27+
favoriteCategoryIdList = favoriteCategoryIdList?.validateFavoriteCategoryIdList(),
28+
email = email?.validateEmail(),
2629
)
2730
}

src/main/kotlin/com/devooks/backend/member/v1/entity/MemberInfoEntity.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.devooks.backend.member.v1.entity
22

3+
import com.devooks.backend.member.v1.dto.ModifyProfileCommand
34
import java.util.*
45
import org.springframework.data.annotation.Id
56
import org.springframework.data.domain.Persistable
@@ -21,8 +22,19 @@ data class MemberInfoEntity(
2122
val accountNumber: String = "",
2223
val introduction: String = "",
2324
val phoneNumber: String = "",
25+
val email: String = "",
2426
) : Persistable<UUID> {
2527
override fun getId(): UUID? = id
2628

2729
override fun isNew(): Boolean = id == null
28-
}
30+
31+
fun update(command: ModifyProfileCommand) =
32+
copy(
33+
phoneNumber = command.phoneNumber ?: this.phoneNumber,
34+
blogLink = command.blogLink ?: this.blogLink,
35+
instagramLink = command.instagramLink ?: this.instagramLink,
36+
youtubeLink = command.youtubeLink ?: this.youtubeLink,
37+
introduction = command.introduction ?: this.introduction,
38+
email = command.email ?: this.email,
39+
)
40+
}

src/main/kotlin/com/devooks/backend/member/v1/error/MemberError.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ enum class MemberError(val exception: GeneralException) {
2323
INVALID_FAVORITE_CATEGORIES(GeneralException("MEMBER-400-13", BAD_REQUEST, "잘못된 형식의 카테고리 식별자 입니다.")),
2424
REQUIRED_WITHDRAWAL_REASON(GeneralException("MEMBER-400-14", BAD_REQUEST, "탈퇴 이유가 반드시 필요합니다.")),
2525
INVALID_MEMBER_ID(GeneralException("MEMBER-400-15", BAD_REQUEST, "잘못된 형식의 회원 식별자 입니다.")),
26+
REQUIRED_EMAIL(GeneralException("MEMBER-400-16", BAD_REQUEST, "이메일은 반드시 필요합니다.")),
27+
INVALID_EMAIL(GeneralException("MEMBER-400-17", BAD_REQUEST, "잘못도니 형식의 이메일 입니다.")),
2628

2729
// 403
2830
SUSPENDED_MEMBER(GeneralException("MEMBER-403-1", FORBIDDEN, "정지된 회원으로 서비스 이용이 불가합니다.")),

src/main/kotlin/com/devooks/backend/member/v1/error/MemberValidation.kt

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.devooks.backend.common.error.validateUUID
66
import java.util.*
77

88
private val phoneRegex = Regex("^[0-9]{2,3}-[0-9]{3,4}-[0-9]{3,4}$")
9+
val emailRegex = Regex("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$")
910

1011
fun String?.validateNickname(): String =
1112
validateNotBlank(MemberError.REQUIRED_NICKNAME.exception)
@@ -28,36 +29,27 @@ fun String?.validateAccountNumber(): String =
2829
validateNotBlank(MemberError.REQUIRED_ACCOUNT_NUMBER.exception)
2930

3031
fun String?.validatePhoneNumber(): String =
31-
validateNotNull(MemberError.REQUIRED_PHONE_NUMBER.exception)
32-
.takeIf { it.isNotBlank() }
33-
?.also {
34-
it.takeIf { phoneRegex.matches(it) }
35-
?: throw MemberError.INVALID_PHONE_NUMBER.exception
36-
}
37-
?: ""
32+
validateNotBlank(MemberError.REQUIRED_PHONE_NUMBER.exception)
33+
.also { it.takeIf { phoneRegex.matches(it) } ?: throw MemberError.INVALID_PHONE_NUMBER.exception }
3834

3935
fun String?.validateBlogLink(): String =
40-
validateNotNull(MemberError.REQUIRED_BLOG_LINK.exception)
41-
.takeIf { it.isNotBlank() }
42-
?: ""
36+
validateNotBlank(MemberError.REQUIRED_BLOG_LINK.exception)
4337

4438
fun String?.validateInstagramLink(): String =
45-
validateNotNull(MemberError.REQUIRED_INSTAGRAM_LINK.exception)
46-
.takeIf { it.isNotBlank() }
47-
?: ""
39+
validateNotBlank(MemberError.REQUIRED_INSTAGRAM_LINK.exception)
4840

4941
fun String?.validateYoutubeLink(): String =
50-
validateNotNull(MemberError.REQUIRED_YOUTUBE_LINK.exception)
51-
.takeIf { it.isNotBlank() }
52-
?: ""
42+
validateNotBlank(MemberError.REQUIRED_YOUTUBE_LINK.exception)
5343

5444
fun String?.validateIntroduction(): String =
55-
validateNotNull(MemberError.REQUIRED_INTRODUCTION_LINK.exception)
56-
.takeIf { it.isNotBlank() }
57-
?: ""
45+
validateNotBlank(MemberError.REQUIRED_INTRODUCTION_LINK.exception)
5846

5947
fun String?.validateWithdrawalReason(): String =
6048
validateNotBlank(MemberError.REQUIRED_WITHDRAWAL_REASON.exception)
6149

6250
fun String?.validateMemberId(): UUID =
6351
validateUUID(MemberError.INVALID_MEMBER_ID.exception)
52+
53+
fun String?.validateEmail(): String =
54+
validateNotBlank(MemberError.REQUIRED_EMAIL.exception)
55+
.also { it.takeIf { emailRegex.matches(it) } ?: throw MemberError.INVALID_EMAIL.exception }

src/main/kotlin/com/devooks/backend/member/v1/service/MemberInfoService.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.springframework.stereotype.Service
1313

1414
@Service
1515
class MemberInfoService(
16-
private val memberInfoRepository: MemberInfoRepository
16+
private val memberInfoRepository: MemberInfoRepository,
1717
) {
1818

1919
suspend fun create(member: Member): MemberInfo {
@@ -44,14 +44,7 @@ class MemberInfoService(
4444
requesterId: UUID,
4545
): MemberInfo {
4646
val memberInfo = findMemberInfoById(requesterId)
47-
val updateMemberInfo = memberInfo
48-
.copy(
49-
phoneNumber = command.phoneNumber,
50-
blogLink = command.blogLink,
51-
instagramLink = command.instagramLink,
52-
youtubeLink = command.youtubeLink,
53-
introduction = command.introduction
54-
)
47+
val updateMemberInfo = memberInfo.update(command)
5548
return memberInfoRepository.save(updateMemberInfo).toDomain()
5649
}
5750

@@ -60,4 +53,4 @@ class MemberInfoService(
6053
.findByMemberId(requesterId)
6154
?: throw MemberError.NOT_FOUND_MEMBER_INFO_BY_ID.exception
6255

63-
}
56+
}

src/main/resources/schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS member_info
2424
introduction TEXT NOT NULL,
2525
phone_number VARCHAR NOT NULL,
2626
member_id uuid NOT NULL UNIQUE,
27+
email VARCHAR NOT NULL,
2728
CONSTRAINT fk_member_id FOREIGN KEY (member_id) REFERENCES member_info (member_id) ON DELETE CASCADE ON UPDATE CASCADE
2829
);
2930

src/test/kotlin/com/devooks/backend/member/v1/controller/MemberControllerTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,8 @@ internal class MemberControllerTest @Autowired constructor(
445445
instagramLink = "www.instagram.com",
446446
youtubeLink = "www.youtube.com",
447447
introduction = "hello",
448-
favoriteCategoryIdList = listOf(categoryId)
448+
favoriteCategoryIdList = listOf(categoryId),
449+
email = "asd@naver.com"
449450
)
450451

451452
postModifyProfile(tokenGroup, modifyProfileRequest)
@@ -756,6 +757,7 @@ internal class MemberControllerTest @Autowired constructor(
756757
assertThat(memberInfo.instagramLink).isEqualTo(modifyProfileRequest.instagramLink)
757758
assertThat(memberInfo.youtubeLink).isEqualTo(modifyProfileRequest.youtubeLink)
758759
assertThat(memberInfo.introduction).isEqualTo(modifyProfileRequest.introduction)
760+
assertThat(memberInfo.email).isEqualTo(modifyProfileRequest.email)
759761
assertIterableEquals(favoriteCategories, modifyProfileRequest.favoriteCategoryIdList)
760762
}
761763
}

0 commit comments

Comments
 (0)