-
Notifications
You must be signed in to change notification settings - Fork 1
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: 어드민 멤버 정보 수정 api 구현 #39
Changes from 20 commits
3a0b42f
c15036b
3c64a2b
e2551c6
2eb830f
e663303
9f6e251
10cb890
4cc0683
5131e5e
4d0ca15
f9c6e98
87db165
dab588e
1a4ad96
768cc7b
6377e53
1375307
c6df1bd
42d72ce
e15cf62
3e7501f
f5400ef
eeadd68
f94c844
b8d8fa0
746b3f2
5120ace
b570260
d40429a
4f0c248
47c4120
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,10 @@ | |
import com.gdschongik.gdsc.domain.member.dao.MemberRepository; | ||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryRequest; | ||
import com.gdschongik.gdsc.domain.member.dto.request.MemberUpdateRequest; | ||
import com.gdschongik.gdsc.domain.member.dto.response.MemberFindAllResponse; | ||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import com.gdschongik.gdsc.global.exception.ErrorCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
@@ -30,4 +32,13 @@ public void withdrawMember(Long memberId) { | |
Member member = memberRepository.findById(memberId).orElseThrow(() -> new CustomException(MEMBER_NOT_FOUND)); | ||
member.withdraw(); | ||
} | ||
|
||
@Transactional | ||
public void updateMember(Long memberId, MemberUpdateRequest request) { | ||
Member member = | ||
memberRepository.findById(memberId).orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND)); | ||
|
||
member.validateStatus(); | ||
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. 어떤 Status임을 검증하는지 궁금한데, "삭제된 유저가 아님을 검증"으로 바꾸는건 어떨까요? 저만의 생각이라 혹시 의도가 있는 거라면 알려주세요! 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.
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. 우선은 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. 저는 Member가 업데이트를 해줄 수 있는 상태인지 확인하는거라 |
||
member.updateMemberInfo(request); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.gdschongik.gdsc.domain.member.domain; | ||
|
||
import static com.gdschongik.gdsc.global.common.constant.RegexConstant.*; | ||
import static com.gdschongik.gdsc.global.exception.ErrorCode.*; | ||
|
||
import com.gdschongik.gdsc.domain.common.model.BaseTimeEntity; | ||
import com.gdschongik.gdsc.domain.member.dto.request.MemberUpdateRequest; | ||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
|
@@ -100,4 +102,70 @@ public void withdraw() { | |
public boolean isDeleted() { | ||
return this.status.isDeleted(); | ||
} | ||
|
||
public void updateMemberInfo(MemberUpdateRequest request) { | ||
updateStudentId(request.studentId()); | ||
updateName(request.name()); | ||
updatePhone(request.phone()); | ||
updateDepartment(request.department()); | ||
updateEmail(request.email()); | ||
updateDiscordUsername(request.discordUsername()); | ||
updateNickname(request.nickname()); | ||
} | ||
|
||
private void updateStudentId(String studentId) { | ||
validateStringNotNull(studentId); | ||
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. 업데이트 시 not null 정책은 dto 단에서 검증하는 것으로 하면 어떨까요? |
||
validateRegex(studentId, STUDENT_ID); | ||
this.studentId = studentId; | ||
} | ||
|
||
private void updateName(String name) { | ||
validateStringNotNull(name); | ||
this.name = name; | ||
} | ||
|
||
private void updatePhone(String phone) { | ||
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. 전화번호는 굳이 하이픈 붙여서 저장할 필요는 없을 것 같아요. 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. db에 넣을 때 제거해서 넣으면 좋은 점이 있나요? 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.
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. 검색하려면 필요하겠네요👍 |
||
validateStringNotNull(phone); | ||
validateRegex(phone, PHONE); | ||
this.phone = phone; | ||
} | ||
|
||
private void updateDepartment(String department) { | ||
validateStringNotNull(department); | ||
this.department = department; | ||
} | ||
|
||
private void updateEmail(String email) { | ||
validateStringNotNull(email); | ||
this.email = email; | ||
} | ||
|
||
private void updateDiscordUsername(String discordUsername) { | ||
validateStringNotNull(discordUsername); | ||
this.discordUsername = discordUsername; | ||
} | ||
|
||
private void updateNickname(String nickname) { | ||
validateStringNotNull(nickname); | ||
validateRegex(nickname, NICKNAME); | ||
this.nickname = nickname; | ||
} | ||
|
||
private void validateStringNotNull(String value) { | ||
if (value == null) { | ||
throw new CustomException(METHOD_ARGUMENT_NULL); | ||
} | ||
} | ||
|
||
private void validateRegex(String value, String regex) { | ||
if (!value.matches(regex)) { | ||
throw new CustomException(REGEX_VIOLATION); | ||
} | ||
} | ||
|
||
public void validateStatus() { | ||
if (isDeleted()) { | ||
throw new CustomException(MEMBER_DELETED); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.gdschongik.gdsc.domain.member.dto.request; | ||
|
||
import static com.gdschongik.gdsc.global.common.constant.RegexConstant.*; | ||
|
||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Pattern; | ||
|
||
public record MemberUpdateRequest( | ||
@NotBlank @Pattern(regexp = STUDENT_ID, message = "학번은 " + STUDENT_ID + " 형식이어야 합니다.") String studentId, | ||
@NotBlank String name, | ||
@NotBlank @Pattern(regexp = PHONE, message = "전화번호는 " + PHONE + " 형식이어야 합니다.") String phone, | ||
@NotBlank String department, | ||
@NotBlank @Email String email, | ||
@NotBlank String discordUsername, | ||
@NotBlank @Pattern(regexp = NICKNAME, message = "닉네임은 " + NICKNAME + " 형식이어야 합니다.") String nickname) {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.gdschongik.gdsc.global.common.constant; | ||
|
||
public class RegexConstant { | ||
public static final String STUDENT_ID = "^[A-C]{1}[0-9]{6}$"; | ||
public static final String PHONE = "^010-[0-9]{4}-[0-9]{4}$"; | ||
public static final String NICKNAME = "[ㄱ-ㅣ가-힣]{1,6}$"; | ||
|
||
private RegexConstant() {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,8 @@ public record ErrorResponse(String errorCodeName, String errorMessage) { | |
public static ErrorResponse of(ErrorCode errorCode) { | ||
return new ErrorResponse(errorCode.name(), errorCode.getMessage()); | ||
} | ||
|
||
public static ErrorResponse of(String errorCodeName, String errorMessage) { | ||
return new ErrorResponse(errorCodeName, errorMessage); | ||
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. GlobalExceptionHandler에서 사용하는 방식을 보긴 했는데, 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. 다른 handler 메서드에서는 더 좋은 방법이 있을까요? 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. 아 취향 차이일 수 있는데, public static ErrorResponse of(ErrorCode errorCode, String errorMessage) {
return new ErrorResponse(errorCode.name(), errorMessage); errorCodeName도 자유롭게 사용하려면 지금 짜주신 방법이 더 좋은 것 같구요 ㅎㅎ 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. 아 제가 잘못 이해했었네요 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.gdschongik.gdsc.domain.member.application; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import com.gdschongik.gdsc.domain.member.dao.MemberRepository; | ||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.member.dto.request.MemberUpdateRequest; | ||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import com.gdschongik.gdsc.global.exception.ErrorCode; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class MemberServiceTest { | ||
@Autowired | ||
private MemberRepository memberRepository; | ||
|
||
@Autowired | ||
private MemberService memberService; | ||
|
||
@Test | ||
void status가_DELETED라면_예외_발생() { | ||
// given | ||
Member member = Member.createGuestMember("oAuthId"); | ||
member.withdraw(); | ||
memberRepository.save(member); | ||
|
||
// when & then | ||
MemberUpdateRequest requestBody = new MemberUpdateRequest( | ||
"A111111", "name", "010-1234-5678", "department", "[email protected]", "discordUsername", "한글"); | ||
assertThatThrownBy(() -> memberService.updateMember(member.getId(), requestBody)) | ||
.isInstanceOf(CustomException.class) | ||
.hasMessage(ErrorCode.MEMBER_DELETED.getMessage()); | ||
} | ||
} |
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.
메서드 이름이 잘못되었습니다.