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,6 +2,7 @@

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.event.StudentRegisteredEvent;
import b1nd.dodam.domain.rds.member.exception.*;
Expand Down Expand Up @@ -126,6 +127,29 @@ public Response updateStudentInfo(UpdateStudentInfoReq req) {
return Response.noContent("내 학생 정보 수정 성공");
}

public Response updateStudentForAdmin(String id, UpdateStudentForAdminReq req){
updateMember(id, req.pw(), req.name(), req.phone());

Student student = getStudentByMember(service.getMemberBy(id));
student.updateInfo(req.grade(), req.room(), req.number());
student.setParentPhone(req.parentPhone());
return Response.noContent("학생 정보 수정 성공");
}

public Response updateTeacherForAdmin(String id, UpdateTeacherForAdminReq req){
updateMember(id, req.pw(), req.name(), req.phone());

Teacher teacher = service.getTeacherBy(service.getMemberBy(id));
teacher.updateInfo(req.tel(), req.position());
return Response.noContent("선생 정보 수정 성공");
}

private void updateMember(String id, String pw, String name, String phone) {
Member member = service.getMemberBy(id);
member.updateInfoForAdmin(pw, name, phone);
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,13 +9,14 @@
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)
.grade(grade)
.room(room)
.number(number)
.parentPhone(parentPhone)
.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) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package b1nd.dodam.restapi.member.application.data.req;

public record UpdateTeacherForAdminReq(String pw, String name, String phone, String tel, String position) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.updateStudentForAdmin(id, req);
}

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

@GetMapping("/{id}")
public ResponseData<MemberInfoRes> getById(@PathVariable String id) {
return queryUseCase.getById(id);
Expand Down
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 @@ -61,20 +63,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){
suw0n marked this conversation as resolved.
Show resolved Hide resolved
if(StringUtils.isNotBlank(pw)){
this.phone = pw;
}
if(StringUtils.isNotBlank(name)){
this.name = name;
}
if(StringUtils.isNotBlank(phone)){
this.phone = phone;
}
}

public void updateStatus(ActiveStatus status) {
this.status = status;
}
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 = "student")
Expand All @@ -29,12 +30,16 @@ public class Student {
@NotNull
private int number;

@NotNull
private String parentPhone;

@Builder
public Student(Member member, int grade, int room, int number) {
public Student(Member member, int grade, int room, int number, String parentPhone) {
this.member = member;
this.grade = grade;
this.room = room;
this.number = number;
this.parentPhone = parentPhone;
}

public void updateInfo(int grade, int room, int number) {
Expand All @@ -43,4 +48,9 @@ public void updateInfo(int grade, int room, int number) {
this.number = number;
}

public void setParentPhone(String parentPhone) {
suw0n marked this conversation as resolved.
Show resolved Hide resolved
if(StringUtils.isNotBlank(parentPhone)){
this.parentPhone = parentPhone;
}
}
}
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 updateInfo(String tel, String position){
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);
}

}