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

Refactor/#148 #149

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SecurityConfig {

private static final String STUDENT = "STUDENT";
private static final String TEACHER = "TEACHER";
private static final String PARENT = "PARENT";
private static final String ADMIN = "ADMIN";

private final TokenFilter tokenFilter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package b1nd.dodam.restapi.member.application;

import b1nd.dodam.domain.rds.member.entity.Member;
import b1nd.dodam.domain.rds.member.entity.Parent;
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.BroadcastClubMemberDuplicateException;
import b1nd.dodam.domain.rds.member.exception.MemberDuplicateException;
import b1nd.dodam.domain.rds.member.repository.BroadcastClubMemberRepository;
import b1nd.dodam.domain.rds.member.repository.MemberRepository;
import b1nd.dodam.domain.rds.member.repository.StudentRepository;
import b1nd.dodam.domain.rds.member.repository.TeacherRepository;
import b1nd.dodam.domain.rds.member.repository.*;
import b1nd.dodam.restapi.auth.infrastructure.security.support.MemberAuthenticationHolder;
import b1nd.dodam.restapi.member.application.data.req.*;
import b1nd.dodam.restapi.support.data.Response;
Expand All @@ -32,6 +30,7 @@ public class MemberCommandUseCase {
private final MemberRepository memberRepository;
private final StudentRepository studentRepository;
private final TeacherRepository teacherRepository;
private final ParentRepository parentRepository;
private final BroadcastClubMemberRepository broadcastClubMemberRepository;
private final MemberAuthenticationHolder memberAuthenticationHolder;
private final ApplicationEventPublisher eventPublisher;
Expand All @@ -55,6 +54,13 @@ public Response join(JoinTeacherReq req) {
return Response.created("선생님 회원가입 성공");
}

public Response join(JoinParentReq req) {
checkIfIdIsDuplicate(req.id());
Member member = memberRepository.save(req.mapToMember(encodePw(req.pw())));
parentRepository.save(req.mapToParent(member));
return Response.created("학부모 회원가입 성공");
}

private void checkIfIdIsDuplicate(String id) {
if(memberRepository.existsById(id)) {
throw new MemberDuplicateException();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package b1nd.dodam.restapi.member.application.data.req;

import b1nd.dodam.domain.rds.member.entity.Member;
import b1nd.dodam.domain.rds.member.entity.Parent;
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 jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotEmpty;

public record JoinParentReq(@NotEmpty String id, @NotEmpty String pw, @NotEmpty String name, @NotEmpty @Email String email,
@NotEmpty String relation, @NotEmpty String phone) {
public Parent mapToParent(Member member) {
return Parent.builder()
.member(member)
.relation(relation)
.build();
}

public Member mapToMember(String encodedPw) {
return Member.builder()
.id(id)
.pw(encodedPw)
.email(email)
.name(name)
.role(MemberRole.PARENT)
.phone(phone)
.status(ActiveStatus.PENDING)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public Response join(@RequestBody @Valid JoinTeacherReq req) {
return commandUseCase.join(req);
}

@PostMapping("/join-parent")
public Response join(@RequestBody @Valid JoinParentReq req) {
return commandUseCase.join(req);
}

@PostMapping("/broadcast-club-member")
public Response apply(@RequestBody @Valid ApplyBroadcastClubMemberReq req) {
return commandUseCase.apply(req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

import b1nd.dodam.domain.rds.member.entity.Student;
import b1nd.dodam.domain.rds.nightstudy.entity.NightStudy;
import b1nd.dodam.domain.rds.support.enumeration.SchoolPlace;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

import java.time.LocalDate;

public record ApplyNightStudyReq(@NotNull @Size(min = 10, max = 250) String content,
@NotNull String place,
@NotNull Boolean doNeedPhone, String reasonForPhone,
@NotNull LocalDate startAt, @NotNull LocalDate endAt) {
public NightStudy toEntity(Student student) {
return NightStudy.builder()
.content(content)
.place(SchoolPlace.of(place))
.doNeedPhone(doNeedPhone)
.reasonForPhone(reasonForPhone)
.student(student)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public record NightStudyRes(Long id,
ApprovalStatus status,
Boolean doNeedPhone, String reasonForPhone,
StudentRes student,
String place,
String rejectReason,
LocalDate startAt, LocalDate endAt,
LocalDateTime createdAt, LocalDateTime modifiedAt) {
Expand All @@ -30,7 +29,6 @@ public static NightStudyRes of(NightStudy nightStudy) {
nightStudy.getStatus(),
nightStudy.getDoNeedPhone(), nightStudy.getReasonForPhone(),
StudentRes.of(nightStudy.getStudent()),
nightStudy.getPlace().getPlace(),
nightStudy.getRejectReason(),
nightStudy.getStartAt(), nightStudy.getEndAt(),
nightStudy.getCreatedAt(), nightStudy.getModifiedAt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import b1nd.dodam.discord.webhook.client.DiscordWebhookClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Arrays;

@Slf4j
@Component
@RequiredArgsConstructor
public class ErrorNoticeSender {
Expand All @@ -33,6 +35,7 @@ public void send(Exception e, RequestInfo request) {
+ "```\n"
+ getStackTrace(e)
+ "\n```";

discordWebHookClient.notice("", title, description);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package b1nd.dodam.domain.rds.member.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

@Getter
@Entity(name = "parent")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Parent {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@NotNull
private String relation;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fk_member_id", nullable = false)
private Member member;

@Builder
public Parent(int id, String relation, Member member) {
this.id = id;
this.relation = relation;
this.member = member;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package b1nd.dodam.domain.rds.member.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity(name = "student_code")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class StudentCode {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String studentCode;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fk_student_id", nullable = false)
private Student student;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fk_parent_id", nullable = false)
private Parent parent;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package b1nd.dodam.domain.rds.member.repository;

import b1nd.dodam.domain.rds.member.entity.Parent;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ParentRepository extends JpaRepository<Parent, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import b1nd.dodam.domain.rds.nightstudy.exception.ReasonForPhoneMissingException;
import b1nd.dodam.domain.rds.support.entity.BaseEntity;
import b1nd.dodam.domain.rds.support.enumeration.ApprovalStatus;
import b1nd.dodam.domain.rds.support.enumeration.SchoolPlace;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
Expand Down Expand Up @@ -38,10 +37,6 @@ public class NightStudy extends BaseEntity {

private String reasonForPhone;

@NotNull
@Enumerated(value = EnumType.STRING)
private SchoolPlace place;

@NotNull
@Enumerated(value = EnumType.STRING)
private ApprovalStatus status;
Expand All @@ -63,7 +58,7 @@ public class NightStudy extends BaseEntity {
private LocalDate endAt;

@Builder
public NightStudy(String content, boolean doNeedPhone, String reasonForPhone, SchoolPlace place, Student student,
public NightStudy(String content, boolean doNeedPhone, String reasonForPhone, Student student,
LocalDate startAt, LocalDate endAt) {
isApplicationDuration();
isInvalidStudyPeriod(startAt, endAt);
Expand All @@ -72,7 +67,6 @@ public NightStudy(String content, boolean doNeedPhone, String reasonForPhone, Sc
this.content = content;
this.doNeedPhone = doNeedPhone;
this.reasonForPhone = reasonForPhone;
this.place = place;
this.status = ApprovalStatus.PENDING;
this.student = student;
this.startAt = startAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
@RequiredArgsConstructor
public enum SchoolPlace {

PROGRAMMING_1("프로그래밍1실"),
PROGRAMMING_2("프로그래밍2실"),
PROGRAMMING_3("프로그래밍3실"),
KOREAN("국어실"),
MATH("수학실"),
SOCIETY("사회실"),
HALL("강당"),
AUDIOVISUAL_ROOM("시청각실"),
NONE("장소 없음"),
Expand Down