diff --git a/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/application/MemberCommandUseCase.java b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/application/MemberCommandUseCase.java index add01768..d0526cbf 100644 --- a/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/application/MemberCommandUseCase.java +++ b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/application/MemberCommandUseCase.java @@ -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.repository.BroadcastClubMemberRepository; @@ -128,4 +130,26 @@ public Response updateStudentInfo(UpdateStudentInfoReq req) { return Response.noContent("내 학생 정보 수정 성공"); } + public Response updateStudentParentPhone(String id, UpdateStudentForAdminReq req){ + Member current = memberAuthenticationHolder.current(); + if (!(current.getRole() == MemberRole.TEACHER || current.getRole() == MemberRole.ADMIN)){ + throw new UnauthorizedException(); + } + Member member = memberRepository.getById(id); + Student student = studentRepository.getByMember(member); + student.updateParentPhone(req.parentPhone()); + return Response.noContent("학생 정보 수정 성공"); + } + + public Response updateTeacherForAdmin(String id, UpdateTeacherForAdminReq req){ + Member current = memberAuthenticationHolder.current(); + if (!(current.getRole() == MemberRole.TEACHER)){ + throw new UnauthorizedException(); + } + Member member = memberRepository.getById(id); + Teacher teacher = teacherRepository.getByMember(member); + teacher.updateInfo(req.tel(), req.position()); + return Response.noContent("선생 정보 수정 성공"); + } + } diff --git a/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/application/data/req/UpdateStudentForAdminReq.java b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/application/data/req/UpdateStudentForAdminReq.java new file mode 100644 index 00000000..228a0e21 --- /dev/null +++ b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/application/data/req/UpdateStudentForAdminReq.java @@ -0,0 +1,3 @@ +package b1nd.dodam.restapi.member.application.data.req; + +public record UpdateStudentForAdminReq(String parentPhone) {} diff --git a/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/application/data/req/UpdateTeacherForAdminReq.java b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/application/data/req/UpdateTeacherForAdminReq.java new file mode 100644 index 00000000..ea29752d --- /dev/null +++ b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/application/data/req/UpdateTeacherForAdminReq.java @@ -0,0 +1,4 @@ +package b1nd.dodam.restapi.member.application.data.req; + +public record UpdateTeacherForAdminReq(String tel, String position) { +} diff --git a/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/presentation/MemberController.java b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/presentation/MemberController.java index ca72ef3e..afdff925 100644 --- a/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/presentation/MemberController.java +++ b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/member/presentation/MemberController.java @@ -70,6 +70,16 @@ public Response updateStudentInfo(@RequestBody UpdateStudentInfoReq req) { return commandUseCase.updateStudentInfo(req); } + @PatchMapping("/student/info/{id}") + public Response updateStudentForAdmin(@PathVariable String id, @RequestBody UpdateStudentForAdminReq req){ + return commandUseCase.updateStudentParentPhone(id, req); + } + + @PatchMapping("/teacher/info/{id}") + public Response updateTeacherForAdmin(@PathVariable String id, @RequestBody UpdateTeacherForAdminReq req){ + return commandUseCase.updateTeacherForAdmin(id, req); + } + @GetMapping("/{id}") public ResponseData getById(@PathVariable String id) { return queryUseCase.getById(id); diff --git a/dodam-system-domain/dodam-domain-rds/build.gradle b/dodam-system-domain/dodam-domain-rds/build.gradle index d4590c17..ca00a046 100644 --- a/dodam-system-domain/dodam-domain-rds/build.gradle +++ b/dodam-system-domain/dodam-domain-rds/build.gradle @@ -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' } diff --git a/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/entity/Member.java b/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/entity/Member.java index d40ea5be..4cf654d8 100644 --- a/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/entity/Member.java +++ b/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/entity/Member.java @@ -7,14 +7,16 @@ import b1nd.dodam.domain.rds.member.exception.WrongPasswordException; 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") @@ -64,20 +66,32 @@ public void updatePw(String 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){ + if(StringUtils.isNotBlank(pw)){ + this.pw = pw; + } + if(StringUtils.isNotBlank(name)){ + this.name = name; + } + if(StringUtils.isNotBlank(phone)){ + this.phone = phone; + } + } + public void updateStatus(ActiveStatus status) { this.status = status; } diff --git a/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/entity/Student.java b/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/entity/Student.java index dda1b71e..c59bfa98 100644 --- a/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/entity/Student.java +++ b/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/entity/Student.java @@ -6,6 +6,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; @Getter @Entity(name = "student") @@ -29,6 +30,8 @@ public class Student { @NotNull private int number; + private String parentPhone; + @Builder public Student(Member member, int grade, int room, int number) { this.member = member; @@ -43,4 +46,9 @@ public void updateInfo(int grade, int room, int number) { this.number = number; } + public void updateParentPhone(String parentPhone) { + if(StringUtils.isNotBlank(parentPhone)){ + this.parentPhone = parentPhone; + } + } } diff --git a/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/entity/Teacher.java b/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/entity/Teacher.java index 67b312b6..bce50544 100644 --- a/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/entity/Teacher.java +++ b/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/entity/Teacher.java @@ -6,6 +6,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; @Getter @Entity(name = "teacher") @@ -33,4 +34,13 @@ public Teacher(Member member, String tel, String position) { this.position = position; } + public void updateInfo(String tel, String position){ + if(StringUtils.isNotBlank(tel)){ + this.tel = tel; + } + if (StringUtils.isNotBlank(position)){ + this.position = position; + } + } + } diff --git a/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/exception/MemberExceptionCode.java b/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/exception/MemberExceptionCode.java index 8931dc23..f0163b1f 100644 --- a/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/exception/MemberExceptionCode.java +++ b/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/exception/MemberExceptionCode.java @@ -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, "이미 존재하는 방송부원"), + UNAUTHORIZED(403, "권한 없음"); private final int status; private final String message; diff --git a/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/exception/UnauthorizedException.java b/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/exception/UnauthorizedException.java new file mode 100644 index 00000000..38eeecab --- /dev/null +++ b/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/exception/UnauthorizedException.java @@ -0,0 +1,12 @@ +package b1nd.dodam.domain.rds.member.exception; + +import b1nd.dodam.core.exception.CustomException; + +public final class UnauthorizedException extends CustomException { + + public UnauthorizedException() { + super(MemberExceptionCode.UNAUTHORIZED); + } + +} +