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

Feature/#99 #103

Merged
merged 9 commits into from
Sep 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import b1nd.dodam.domain.rds.member.entity.Member;
import b1nd.dodam.domain.rds.member.entity.Student;
import b1nd.dodam.domain.rds.member.entity.Teacher;
import b1nd.dodam.domain.rds.member.enumeration.ActiveStatus;
import b1nd.dodam.domain.rds.member.enumeration.MemberRole;
import b1nd.dodam.domain.rds.member.event.StudentRegisteredEvent;
import b1nd.dodam.domain.rds.member.exception.*;
import b1nd.dodam.domain.rds.member.service.MemberService;
Expand Down Expand Up @@ -126,6 +128,33 @@ public Response updateStudentInfo(UpdateStudentInfoReq req) {
return Response.noContent("내 학생 정보 수정 성공");
}

public Response updateInfoForAdmin(String id, MemberRole memberRole, UpdateStudentForAdminReq req){
switch (memberRole) {
case STUDENT:
updateMemberInfo(id, req);
Student student = getStudentByMember(service.getMemberBy(id));
student.updateInfo(req.grade(), req.room(), req.number());
break;

case TEACHER:
updateMemberInfo(id, req);
Teacher teacher = service.getTeacherBy(service.getMemberBy(id));
Copy link
Member

Choose a reason for hiding this comment

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

공통 부분을 switch case 문에 넣을 필요가 없어 보입니다

Copy link
Member Author

Choose a reason for hiding this comment

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

teacher.updateInfoForAdmin(req.tel(), req.position());
break;

default:
throw new UnmodifiableRole();
}
return Response.noContent("유저 정보 수정 성공");
}

private void updateMemberInfo(String id, UpdateStudentForAdminReq req) {
Member member = service.getMemberById(id)
.orElseThrow(MemberNotFoundException::new);
member.updateInfoForAdmin(req.name(), req.pw(), req.phone(), req.parentPhone());
service.save(member);
}

private Student getStudentByMember(Member member) {
return service.getStudentByMember(member)
.orElseThrow(StudentNotFoundException::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import jakarta.validation.constraints.NotNull;

public record JoinStudentReq(@NotEmpty String id, @NotEmpty String pw, @NotEmpty String name, @NotEmpty @Email String email,
@NotEmpty String phone, @NotNull int grade, @NotNull int room, @NotNull int number) {
@NotEmpty String phone, @NotNull String parentPhone, @NotNull int grade, @NotNull int room, @NotNull int number) {
public Student mapToStudent(Member member) {
return Student.builder()
.member(member)
Expand All @@ -27,6 +27,7 @@ public Member mapToMember(String encodedPw) {
.name(name)
.role(MemberRole.STUDENT)
.phone(phone)
.parentPhone(parentPhone)
.status(ActiveStatus.DEACTIVATE)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package b1nd.dodam.restapi.member.application.data.req;

public record UpdateStudentForAdminReq(String pw, String name, String phone, String parentPhone, Integer grade,
Integer room, Integer number, String tel, String position) {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package b1nd.dodam.restapi.member.presentation;

import b1nd.dodam.domain.rds.member.enumeration.MemberRole;
import b1nd.dodam.restapi.member.application.MemberCommandUseCase;
import b1nd.dodam.restapi.member.application.MemberQueryUseCase;
import b1nd.dodam.restapi.member.application.data.req.*;
Expand Down Expand Up @@ -70,6 +71,14 @@ public Response updateStudentInfo(@RequestBody UpdateStudentInfoReq req) {
return commandUseCase.updateStudentInfo(req);
}

@PatchMapping("/info/{id}/{role}")
public Response updateInfoForAdmin(@PathVariable String id,
suw0n marked this conversation as resolved.
Show resolved Hide resolved
@PathVariable MemberRole role,
@RequestBody UpdateStudentForAdminReq req
){
return commandUseCase.updateInfoForAdmin(id, role, req);
}

@GetMapping("/{id}")
public ResponseData<MemberInfoRes> getById(@PathVariable String id) {
return queryUseCase.getById(id);
Expand Down Expand Up @@ -105,4 +114,5 @@ public ResponseData<Boolean> checkBroadcastClubMember(@PathVariable String id) {
return queryUseCase.checkBroadcastClubMember(id);
}


suw0n marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 2 additions & 0 deletions dodam-system-domain/dodam-domain-rds/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.14.2'

implementation 'jakarta.validation:jakarta.validation-api:3.0.2'

implementation 'org.apache.commons:commons-lang3:3.13.0'
suw0n marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
import b1nd.dodam.domain.rds.member.enumeration.MemberRole;
import b1nd.dodam.domain.rds.support.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;
import org.apache.commons.lang3.StringUtils;

@Getter
@Entity(name = "member")
Expand Down Expand Up @@ -44,8 +46,10 @@ public class Member extends BaseEntity {
@NotNull
private String phone;

private String parentPhone;
suw0n marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

부모님 번호는 공통 정보가 아니라 학생의 정보이므로 굳이 member 에 추가하기 보다는 student에 추가하는게 맞는 것 같습니다

Copy link
Member

Choose a reason for hiding this comment

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

@NotNull 도 추가해주세요

Copy link
Member Author

Choose a reason for hiding this comment

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


@Builder
public Member(String id, String pw, String name, String email, MemberRole role, ActiveStatus status, String profileImage, String phone) {
public Member(String id, String pw, String name, String email, MemberRole role, ActiveStatus status, String profileImage, String phone, String parentPhone) {
this.id = id;
this.pw = pw;
this.email = email;
Expand All @@ -54,27 +58,43 @@ public Member(String id, String pw, String name, String email, MemberRole role,
this.status = status;
this.profileImage = profileImage;
this.phone = phone;
this.parentPhone = parentPhone;
}

public void updatePw(String pw) {
this.pw = pw;
}

public void updateInfo(String name, String email, String phone, String profileImage) {
if(Objects.nonNull(name)) {
if(StringUtils.isNotBlank(name)){
this.name = name;
}
if(Objects.nonNull(email)) {
if(StringUtils.isNotBlank(email)){
this.email = email;
}
if(Objects.nonNull(phone)) {
if(StringUtils.isNotBlank(phone)){
this.phone = phone;
}
if(Objects.nonNull(profileImage)) {
if(StringUtils.isNotBlank(profileImage)){
this.profileImage = profileImage;
}
}

public void updateInfoForAdmin(String pw, String name, String phone, String parentPhone){
if(StringUtils.isNotBlank(pw)){
this.phone = pw;
}
if(StringUtils.isNotBlank(name)){
this.name = name;
}
if(StringUtils.isNotBlank(phone)){
this.phone = phone;
}
if(StringUtils.isNotBlank(parentPhone)){
this.parentPhone = parentPhone;
}
}

public void updateStatus(ActiveStatus status) {
this.status = status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;

@Getter
@Entity(name = "student")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

@Getter
@Entity(name = "teacher")
Expand Down Expand Up @@ -33,4 +34,13 @@ public Teacher(Member member, String tel, String position) {
this.position = position;
}

public void updateInfoForAdmin(String tel, String position){
suw0n marked this conversation as resolved.
Show resolved Hide resolved
if(StringUtils.isNotBlank(tel)){
this.tel = tel;
}
if (StringUtils.isNotBlank(position)){
this.position = position;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum MemberExceptionCode implements ExceptionCode {
PARENT_NOT_FOUND(404, "없는 부모님 정보"),
TEACHER_NOT_FOUND(404, "없는 선생님"),
MEMBER_DUPLICATION(409, "이미 존재하는 멤버"),
BROADCAST_CLUB_MEMBER_DUPLICATION(409, "이미 존재하는 방송부원");
BROADCAST_CLUB_MEMBER_DUPLICATION(409, "이미 존재하는 방송부원"),
UNMODIFIABLE_ROLE(403, "해당 유저는 수정이 불가합니다");

private final int status;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package b1nd.dodam.domain.rds.member.exception;

import b1nd.dodam.core.exception.CustomException;

public class UnmodifiableRole extends CustomException {

public UnmodifiableRole() {
super(MemberExceptionCode.UNMODIFIABLE_ROLE);
}

}