Skip to content

Commit

Permalink
[BE] 2차 스프린트 이후 수정할 것 리팩토링 (#174)
Browse files Browse the repository at this point in the history
* refactor: VO Equals&HashCode 추가 리팩토링

* merge: 팀 캘린더 하루 일정 조회 PR rebase conflict 해결

* refactor: @DirtiesContext 대신 truncate sql 사용

* refactor: MemberException 메시지 Exception 안에서 생성 리팩토링

* refactor: TeamPlaceException 메시지 Exception 안에서 생성 리팩토링

* merge: 팀 캘린더 하루 일정 조회 PR rebase conflict 해결 2

* merge: TeamCalendarScheduleService 팀 캘린더 하루 일정 조회 PR rebase conflict 해결 2

* merge: TeamCalendarScheduleApiDocsTest 팀 캘린더 하루 일정 조회 PR rebase conflict 해결

* refactor: 1:N에서 1 쪽 객체 생성 시 List 필드 new ArrayList로 초기화

* refactor: 엔티티에서 @AllArgsConstructor 제거

* fix: merge conflict 오류 해결

* refactor: domain에 vo 패키지 추가
  • Loading branch information
sh111-coder authored Jul 26, 2023
1 parent 146913c commit b121fa1
Show file tree
Hide file tree
Showing 33 changed files with 165 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public boolean preHandle(final HttpServletRequest request, final HttpServletResp
final String token = extractToken(request);
final String email = extractEmailFromToken(token);
if (notExistsByEmail(email)) {
throw new MemberException.MemberNotFoundException("멤버 조회 실패");
throw new MemberException.MemberNotFoundException();
}
return true;
}
Expand All @@ -42,7 +42,7 @@ private String extractToken(HttpServletRequest request) {
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith(PREFIX_BEARER)) {
return bearerToken.substring(PREFIX_BEARER.length());
}
throw new MemberException.UnSupportAuthenticationException("지원하지 않는 인증 방식입니다.");
throw new MemberException.UnSupportAuthenticationException();
}

public String extractEmailFromToken(String token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import team.teamby.teambyteam.member.domain.vo.Email;
import team.teamby.teambyteam.member.domain.vo.Name;
import team.teamby.teambyteam.member.domain.vo.ProfileImageUrl;
import team.teamby.teambyteam.teamplace.domain.TeamPlace;

import java.util.ArrayList;
import java.util.List;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Member {

@Id
Expand All @@ -38,13 +37,12 @@ public class Member {
public Member(
final Name name,
final Email email,
final ProfileImageUrl profileImageUrl,
final List<MemberTeamPlace> memberTeamPlaces
final ProfileImageUrl profileImageUrl
) {
this.name = name;
this.email = email;
this.profileImageUrl = profileImageUrl;
this.memberTeamPlaces = memberTeamPlaces;
this.memberTeamPlaces = new ArrayList<>();
}

public List<TeamPlace> getTeamPlaces() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void validate(final String value) {
}

if (isNotMatchEmailForm(value)) {
throw new MemberException.EmailRegexException("정해진 이메일의 양식이 아닙니다.");
throw new MemberException.EmailRegexException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import team.teamby.teambyteam.member.exception.MemberException;
Expand All @@ -11,6 +12,7 @@

@Embeddable
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EqualsAndHashCode
@Getter
public class Name {

Expand All @@ -29,10 +31,10 @@ private void validate(final String value) {
throw new NullPointerException("멤버 이름은 null일 수 없습니다.");
}
if (value.length() > MAX_LENGTH) {
throw new MemberException.NameLengthException("입력한 길이가 최대 이름 길이인 " + MAX_LENGTH + "를 초과했습니다.");
throw new MemberException.NameLengthException();
}
if (value.isBlank()) {
throw new MemberException.NameLengthException("멤버 이름은 공백을 제외한 1자 이상이어야 합니다.");
throw new MemberException.NameBlankException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

@Embeddable
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@EqualsAndHashCode
@Getter
public class ProfileImageUrl {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,34 @@ public MemberException(final String message) {
}

public static class NameLengthException extends MemberException {
public NameLengthException(final String message) {
super(message);

public NameLengthException() {
super("멤버 이름의 길이가 최대 이름 길이를 초과했습니다.");
}
}

public static class NameBlankException extends MemberException {

public NameBlankException() {
super("멤버 이름은 공백을 제외한 1자 이상이어야합니다.");
}
}

public static class EmailRegexException extends MemberException {
public EmailRegexException(final String message) {
super(message);
public EmailRegexException() {
super("정해진 이메일의 양식이 아닙니다.");
}
}

public static class MemberNotFoundException extends MemberException {
public MemberNotFoundException(final String message) {
super(message);
public MemberNotFoundException() {
super("조회한 멤버가 존재하지 않습니다.");
}
}

public static class UnSupportAuthenticationException extends MemberException {
public UnSupportAuthenticationException(final String message) {
super(message);
public UnSupportAuthenticationException() {
super("지원하지 않는 인증 방식입니다.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public SchedulesWithTeamPlaceIdResponse findScheduleInPeriod(
final int targetMonth
) {
final Member member = memberRepository.findByEmail(new Email(memberEmailDto.email()))
.orElseThrow(() -> new MemberException.MemberNotFoundException("사용자를 찾을 수 없습니다."));
.orElseThrow(MemberException.MemberNotFoundException::new);

final List<Long> participatedTeamPlaceIds = member.getTeamPlaces()
.stream()
.map(TeamPlace::getId)
.toList();

final CalendarPeriod period = CalendarPeriod.createPeriod(targetYear, targetMonth);
final CalendarPeriod period = CalendarPeriod.of(targetYear, targetMonth);
final List<Schedule> schedules = scheduleRepository
.findAllByTeamPlaceIdAndPeriod(participatedTeamPlaceIds, period.startDateTime(), period.endDatetime());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import team.teamby.teambyteam.schedule.application.dto.ScheduleResponse;
import team.teamby.teambyteam.schedule.application.dto.ScheduleUpdateRequest;
import team.teamby.teambyteam.schedule.application.dto.SchedulesResponse;
import team.teamby.teambyteam.schedule.domain.*;
import team.teamby.teambyteam.schedule.domain.CalendarPeriod;
import team.teamby.teambyteam.schedule.domain.Schedule;
import team.teamby.teambyteam.schedule.domain.ScheduleRepository;
import team.teamby.teambyteam.schedule.domain.vo.Span;
import team.teamby.teambyteam.schedule.domain.vo.Title;
import team.teamby.teambyteam.schedule.exception.ScheduleException;
import team.teamby.teambyteam.teamplace.domain.TeamPlaceRepository;
import team.teamby.teambyteam.teamplace.exception.TeamPlaceException;
Expand Down Expand Up @@ -37,7 +41,7 @@ public Long register(final ScheduleRegisterRequest scheduleRegisterRequest, fina

private void checkTeamPlaceExist(final Long teamPlaceId) {
if (notExistTeamPlace(teamPlaceId)) {
throw new TeamPlaceException.NotFoundException("ID에 해당하는 팀 플레이스를 찾을 수 없습니다.");
throw new TeamPlaceException.NotFoundException();
}
}

Expand All @@ -50,15 +54,15 @@ public ScheduleResponse findSchedule(final Long scheduleId, final Long teamPlace
checkTeamPlaceExist(teamPlaceId);

final Schedule schedule = scheduleRepository.findById(scheduleId)
.orElseThrow(() -> new ScheduleException.ScheduleNotFoundException("조회한 일정이 존재하지 않습니다."));
.orElseThrow(ScheduleException.ScheduleNotFoundException::new);
validateScheduleOwnerTeam(teamPlaceId, schedule);

return ScheduleResponse.from(schedule);
}

private void validateScheduleOwnerTeam(final Long teamPlaceId, final Schedule schedule) {
if (isNotScheduleOfTeam(teamPlaceId, schedule)) {
throw new ScheduleException.TeamAccessForbidden("해당 팀플레이스에 일정을 조회할 권한이 없습니다.");
throw new ScheduleException.TeamAccessForbidden();
}
}

Expand All @@ -70,7 +74,7 @@ private boolean isNotScheduleOfTeam(final Long teamPlaceId, final Schedule sched
public SchedulesResponse findScheduleInPeriod(final Long teamPlaceId, final int targetYear, final int targetMonth) {
checkTeamPlaceExist(teamPlaceId);

final CalendarPeriod period = CalendarPeriod.createPeriod(targetYear, targetMonth);
final CalendarPeriod period = CalendarPeriod.of(targetYear, targetMonth);
final List<Schedule> schedules = scheduleRepository
.findAllByTeamPlaceIdAndPeriod(teamPlaceId, period.startDateTime(), period.endDatetime());

Expand All @@ -86,7 +90,7 @@ public SchedulesResponse findDailySchedule(
) {
checkTeamPlaceExist(teamPlaceId);

final CalendarPeriod dailyPeriod = CalendarPeriod.createDailyPeriod(targetYear, targetMonth, targetDay);
final CalendarPeriod dailyPeriod = CalendarPeriod.of(targetYear, targetMonth, targetDay);
final List<Schedule> dailySchedules = scheduleRepository
.findAllByTeamPlaceIdAndDailyPeriod(teamPlaceId, dailyPeriod.startDateTime(), dailyPeriod.endDatetime());

Expand All @@ -97,7 +101,7 @@ public void update(final ScheduleUpdateRequest scheduleUpdateRequest, final Long
checkTeamPlaceExist(teamPlaceId);

final Schedule schedule = scheduleRepository.findById(scheduleId)
.orElseThrow(() -> new ScheduleException.ScheduleNotFoundException("ID에 해당하는 일정을 찾을 수 없습니다."));
.orElseThrow(ScheduleException.ScheduleNotFoundException::new);

schedule.change(scheduleUpdateRequest.title(),
scheduleUpdateRequest.startDateTime(), scheduleUpdateRequest.endDateTime());
Expand All @@ -111,7 +115,7 @@ public void delete(final Long teamPlaceId, final Long scheduleId) {

private void checkScheduleExist(final Long scheduleId) {
if (notExistSchedule(scheduleId)) {
throw new ScheduleException.ScheduleNotFoundException("ID에 해당하는 일정을 찾을 수 없습니다.");
throw new ScheduleException.ScheduleNotFoundException();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package team.teamby.teambyteam.schedule.application.dto;

import team.teamby.teambyteam.schedule.domain.Schedule;
import team.teamby.teambyteam.schedule.domain.Span;
import team.teamby.teambyteam.schedule.domain.vo.Span;

import java.time.format.DateTimeFormatter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package team.teamby.teambyteam.schedule.application.dto;

import team.teamby.teambyteam.schedule.domain.Schedule;
import team.teamby.teambyteam.schedule.domain.Span;
import team.teamby.teambyteam.schedule.domain.vo.Span;

import java.time.format.DateTimeFormatter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public record CalendarPeriod(
private static final LocalTime END_TIME_OF_DAY = LocalTime.of(23, 59, 59);
public static final int NEXT_MONTH_OFFSET = 1;

public static CalendarPeriod createPeriod(final int year, final int month) {
public static CalendarPeriod of(final int year, final int month) {
final LocalDate startDate = LocalDate.of(year, month, FIRST_DAY_OF_MONTH);
final LocalDate endDate = startDate.plusMonths(NEXT_MONTH_OFFSET).withDayOfMonth(FIRST_DAY_OF_MONTH);

return new CalendarPeriod(LocalDateTime.of(startDate, START_TIME_OF_DAY), LocalDateTime.of(endDate, START_TIME_OF_DAY));
}

public static CalendarPeriod createDailyPeriod(final int year, final int month, final int day) {
public static CalendarPeriod of(final int year, final int month, final int day) {
LocalDate dailyDate = LocalDate.of(year, month, day);

return new CalendarPeriod(LocalDateTime.of(dailyDate, START_TIME_OF_DAY), LocalDateTime.of(dailyDate, END_TIME_OF_DAY));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package team.teamby.teambyteam.schedule.domain;

import jakarta.persistence.*;
import java.util.Objects;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import team.teamby.teambyteam.schedule.domain.vo.Span;
import team.teamby.teambyteam.schedule.domain.vo.Title;

import java.time.LocalDateTime;
import java.util.Objects;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Getter
public class Schedule {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package team.teamby.teambyteam.schedule.domain;
package team.teamby.teambyteam.schedule.domain.vo;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import team.teamby.teambyteam.schedule.exception.ScheduleException;
Expand All @@ -11,6 +12,7 @@

@Embeddable
@Getter
@EqualsAndHashCode
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Span {

Expand All @@ -28,7 +30,7 @@ public Span(final LocalDateTime startDateTime, final LocalDateTime endDateTime)

private void validateDateTimeOrder(final LocalDateTime startDateTime, final LocalDateTime endDateTime) {
if (startDateTime.isAfter(endDateTime)) {
throw new ScheduleException.SpanWrongOrderException("시작 일자가 종료 일자보다 이후일 수 없습니다.");
throw new ScheduleException.SpanWrongOrderException();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team.teamby.teambyteam.schedule.domain;
package team.teamby.teambyteam.schedule.domain.vo;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
Expand Down Expand Up @@ -30,7 +30,7 @@ private void validate(final String value) {
}

if (value.isBlank()) {
throw new ScheduleException.TitleBlankException("일정의 제목은 빈 칸일 수 없습니다.");
throw new ScheduleException.TitleBlankException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ public ScheduleException(final String message) {
}

public static class ScheduleNotFoundException extends ScheduleException {
public ScheduleNotFoundException(final String message) {
super(message);
public ScheduleNotFoundException() {
super("조회한 일정이 존재하지 않습니다.");
}
}

public static class TeamAccessForbidden extends ScheduleException {
public TeamAccessForbidden(final String message) {
super(message);
public TeamAccessForbidden() {
super("해당 팀플레이스에 일정을 조회할 권한이 없습니다.");
}
}

public static class SpanWrongOrderException extends ScheduleException {
public SpanWrongOrderException(final String message) {
super(message);
public SpanWrongOrderException() {
super("시작 일자가 종료 일자보다 이후일 수 없습니다.");
}
}

public static class TitleBlankException extends ScheduleException {

public TitleBlankException(final String message) {
super(message);
public TitleBlankException() {
super("일정의 제목은 빈 칸일 수 없습니다.");
}
}
}
Loading

0 comments on commit b121fa1

Please sign in to comment.