Skip to content

Commit

Permalink
refactor: 열거형 이름 Type -> MeetingType
Browse files Browse the repository at this point in the history
  • Loading branch information
seunghye218 committed Sep 26, 2024
1 parent 4264af6 commit 3bf3f18
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 49 deletions.
6 changes: 3 additions & 3 deletions backend/src/main/java/kr/momo/domain/meeting/Meeting.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public class Meeting extends BaseEntity {

@Enumerated(EnumType.STRING)
@Column(nullable = false, length = 10)
private Type type;
private MeetingType type;

@Embedded
private TimeslotInterval timeslotInterval;

public Meeting(String name, String uuid, LocalTime firstTime, LocalTime lastTime, Type type) {
public Meeting(String name, String uuid, LocalTime firstTime, LocalTime lastTime, MeetingType type) {
this.name = name;
this.uuid = uuid;
this.isLocked = false;
Expand All @@ -52,7 +52,7 @@ public Meeting(String name, String uuid, LocalTime firstTime, LocalTime lastTime
}

public Meeting(String name, String uuid, LocalTime firstTime, LocalTime lastTime) {
this(name, uuid, firstTime, lastTime, Type.DATETIME);
this(name, uuid, firstTime, lastTime, MeetingType.DATETIME);
}

public void lock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import kr.momo.exception.MomoException;
import kr.momo.exception.code.MeetingErrorCode;

public enum Type {
public enum MeetingType {

DAYSONLY,
DATETIME;

Expand All @@ -13,9 +14,9 @@ public boolean isDaysOnly() {
}

@JsonCreator
public static Type from(String type) {
public static MeetingType from(String type) {
try {
return Type.valueOf(type.toUpperCase());
return MeetingType.valueOf(type.toUpperCase());
} catch (IllegalArgumentException | NullPointerException e) {
throw new MomoException(MeetingErrorCode.INVALID_TYPE);
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/main/java/kr/momo/domain/schedule/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import kr.momo.domain.BaseEntity;
import kr.momo.domain.attendee.Attendee;
import kr.momo.domain.availabledate.AvailableDate;
import kr.momo.domain.meeting.Type;
import kr.momo.domain.meeting.MeetingType;
import kr.momo.domain.timeslot.Timeslot;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -53,7 +53,7 @@ public Schedule(Attendee attendee, AvailableDate availableDate, Timeslot timeslo
this.timeslot = timeslot;
}

public RecommendInterval recommendInterval(Type type) {
public RecommendInterval recommendInterval(MeetingType type) {
return type.isDaysOnly() ? dateInterval() : dateTimeInterval();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import kr.momo.domain.availabledate.AvailableDates;
import kr.momo.domain.meeting.Meeting;
import kr.momo.domain.meeting.MeetingRepository;
import kr.momo.domain.meeting.Type;
import kr.momo.domain.meeting.MeetingType;
import kr.momo.domain.meeting.UuidGenerator;
import kr.momo.exception.MomoException;
import kr.momo.exception.code.AttendeeErrorCode;
Expand Down Expand Up @@ -59,7 +59,7 @@ public MeetingCreateResponse create(MeetingCreateRequest request) {
return MeetingCreateResponse.from(meeting, attendee, meetingDates, token);
}

private Meeting saveMeeting(String meetingName, LocalTime startTime, LocalTime endTime, Type type) {
private Meeting saveMeeting(String meetingName, LocalTime startTime, LocalTime endTime, MeetingType type) {
String uuid = generateUniqueUuid();
Meeting meeting = new Meeting(meetingName, uuid, startTime, endTime, type);
return meetingRepository.save(meeting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.List;
import kr.momo.controller.validator.DateFormatConstraint;
import kr.momo.controller.validator.TimeFormatConstraint;
import kr.momo.domain.meeting.Type;
import kr.momo.domain.meeting.MeetingType;
import kr.momo.domain.timeslot.Timeslot;
import org.hibernate.validator.constraints.Length;

Expand Down Expand Up @@ -48,7 +48,7 @@ public record MeetingCreateRequest(

@NotNull
@Schema(description = "약속 타입", example = "DATETIME")
Type type
MeetingType type
) {

public List<LocalDate> toAvailableMeetingDates() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package kr.momo.service.schedule.dto;

import java.util.List;
import kr.momo.domain.meeting.Type;
import kr.momo.domain.meeting.MeetingType;

public record RecommendedSchedulesResponse(
String type,
List<RecommendedScheduleResponse> recommendedSchedules
) {

public static RecommendedSchedulesResponse of(Type type, List<RecommendedScheduleResponse> recommendedSchedules) {
public static RecommendedSchedulesResponse of(MeetingType type,
List<RecommendedScheduleResponse> recommendedSchedules) {
return new RecommendedSchedulesResponse(type.name(), recommendedSchedules);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;
import kr.momo.domain.attendee.AttendeeGroup;
import kr.momo.domain.meeting.Type;
import kr.momo.domain.meeting.MeetingType;
import kr.momo.domain.schedule.DateAndTimeslot;
import kr.momo.domain.schedule.ScheduleRepository;
import kr.momo.domain.schedule.recommend.CandidateSchedule;
Expand All @@ -18,7 +18,8 @@ public FilteredScheduleRecommender(ScheduleRepository scheduleRepository) {
}

@Override
protected List<CandidateSchedule> extractProperSortedDiscreteScheduleOf(AttendeeGroup filteredGroup, Type type) {
protected List<CandidateSchedule> extractProperSortedDiscreteScheduleOf(AttendeeGroup filteredGroup,
MeetingType type) {
return findAllScheduleAvailableByEveryAttendee(filteredGroup);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;
import kr.momo.domain.attendee.AttendeeGroup;
import kr.momo.domain.meeting.Type;
import kr.momo.domain.meeting.MeetingType;
import kr.momo.domain.schedule.ScheduleRepository;
import kr.momo.domain.schedule.recommend.CandidateSchedule;
import kr.momo.domain.schedule.recommend.CandidateScheduleSorter;
Expand All @@ -16,20 +16,20 @@ public abstract class ScheduleRecommender {

protected final ScheduleRepository scheduleRepository;

public List<CandidateSchedule> recommend(AttendeeGroup group, String recommendType, Type meetingType) {
public List<CandidateSchedule> recommend(AttendeeGroup group, String recommendType, MeetingType meetingType) {
List<CandidateSchedule> mergedCandidateSchedules = calcCandidateSchedules(group, meetingType);
sortSchedules(mergedCandidateSchedules, recommendType);
return mergedCandidateSchedules.stream()
.limit(getMaxRecommendCount())
.toList();
}

private List<CandidateSchedule> calcCandidateSchedules(AttendeeGroup group, Type type) {
private List<CandidateSchedule> calcCandidateSchedules(AttendeeGroup group, MeetingType type) {
List<CandidateSchedule> intersectedDateTimes = extractProperSortedDiscreteScheduleOf(group, type);
return CandidateSchedule.mergeContinuous(intersectedDateTimes, this::isContinuous);
}

abstract List<CandidateSchedule> extractProperSortedDiscreteScheduleOf(AttendeeGroup group, Type type);
abstract List<CandidateSchedule> extractProperSortedDiscreteScheduleOf(AttendeeGroup group, MeetingType type);

abstract boolean isContinuous(CandidateSchedule current, CandidateSchedule next);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Map;
import java.util.stream.Collectors;
import kr.momo.domain.attendee.AttendeeGroup;
import kr.momo.domain.meeting.Type;
import kr.momo.domain.meeting.MeetingType;
import kr.momo.domain.schedule.RecommendInterval;
import kr.momo.domain.schedule.Schedule;
import kr.momo.domain.schedule.ScheduleRepository;
Expand All @@ -22,11 +22,11 @@ protected TotalScheduleRecommender(ScheduleRepository scheduleRepository) {
}

@Override
protected List<CandidateSchedule> extractProperSortedDiscreteScheduleOf(AttendeeGroup group, Type type) {
protected List<CandidateSchedule> extractProperSortedDiscreteScheduleOf(AttendeeGroup group, MeetingType type) {
return findAllScheduleAvailableByEachAttendee(group, type);
}

private List<CandidateSchedule> findAllScheduleAvailableByEachAttendee(AttendeeGroup group, Type type) {
private List<CandidateSchedule> findAllScheduleAvailableByEachAttendee(AttendeeGroup group, MeetingType type) {
List<Schedule> schedules = scheduleRepository.findAllByAttendeeIn(group.getAttendees());
Map<RecommendInterval, AttendeeGroup> groupedAttendeesByDateTimeInterval = schedules.stream()
.collect(Collectors.groupingBy(schedule -> schedule.recommendInterval(type), Collectors.mapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import kr.momo.domain.meeting.ConfirmedMeetingRepository;
import kr.momo.domain.meeting.Meeting;
import kr.momo.domain.meeting.MeetingRepository;
import kr.momo.domain.meeting.Type;
import kr.momo.domain.meeting.MeetingType;
import kr.momo.domain.timeslot.Timeslot;
import kr.momo.fixture.AttendeeFixture;
import kr.momo.fixture.ConfirmedMeetingFixture;
Expand Down Expand Up @@ -129,7 +129,7 @@ void create() {
List.of(tomorrow.toString(), dayAfterTomorrow.toString()),
"08:00",
"22:00",
Type.DATETIME
MeetingType.DATETIME
);

RestAssured.given().log().all()
Expand All @@ -156,7 +156,7 @@ void throwExceptionTimeFormatIsInvalid(String startTime, String endTime) {
List.of(tomorrow.toString(), dayAfterTomorrow.toString()),
startTime,
endTime,
Type.DATETIME
MeetingType.DATETIME
);

RestAssured.given().log().all()
Expand All @@ -181,7 +181,7 @@ void createByInvalidNickname() {
List.of(tomorrow.toString(), dayAfterTomorrow.toString()),
"08:00",
"22:00",
Type.DATETIME
MeetingType.DATETIME
);

RestAssured.given().log().all()
Expand All @@ -206,7 +206,7 @@ void createByInvalidHost() {
List.of(tomorrow.toString(), dayAfterTomorrow.toString()),
"08:00",
"22:00",
Type.DATETIME
MeetingType.DATETIME
);

RestAssured.given().log().all()
Expand All @@ -230,7 +230,7 @@ void createByDuplicatedName() {
List.of(tomorrow.toString(), tomorrow.toString()),
"08:00",
"22:00",
Type.DATETIME
MeetingType.DATETIME
);

RestAssured.given().log().all()
Expand Down Expand Up @@ -442,7 +442,7 @@ private Meeting createLockedMovieMeeting() {
@DisplayName("주최자가 유형이 DaysOnly이며 잠겨있는 약속 일정을 확정하면 201 상태 코드를 응답한다.")
@Test
void confirmConsecutiveAndDaysOnlyMeeting() {
Meeting meeting = MeetingFixture.DRINK.create(Type.DAYSONLY);
Meeting meeting = MeetingFixture.DRINK.create(MeetingType.DAYSONLY);
meeting.lock();
meeting = meetingRepository.save(meeting);
AttendeeFixture jazz = AttendeeFixture.HOST_JAZZ;
Expand Down Expand Up @@ -500,7 +500,7 @@ void confirmNotConsecutiveMeeting() {
@DisplayName("주최자가 유형이 DaysOnly이며 연속적이지 않은 약속 일정을 확정하면 400 상태 코드를 응답한다.")
@Test
void confirmNotConsecutiveAndDaysOnlyMeeting() {
Meeting meeting = MeetingFixture.DRINK.create(Type.DAYSONLY);
Meeting meeting = MeetingFixture.DRINK.create(MeetingType.DAYSONLY);
meeting.lock();
meeting = meetingRepository.save(meeting);
AttendeeFixture jazz = AttendeeFixture.HOST_JAZZ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void availableAttendeesOf() {
@DisplayName("확정된 days only 유형 약속의 범위에 포함되는 스케줄들 중 참석 가능한 참석자들을 반환한다.")
@Test
void availableAttendeesOfDaysOnly() {
Meeting meeting = MeetingFixture.DRINK.create(Type.DAYSONLY);
Meeting meeting = MeetingFixture.DRINK.create(MeetingType.DAYSONLY);
Attendee attendee1 = AttendeeFixture.GUEST_MARK.create(meeting);
Attendee attendee2 = AttendeeFixture.HOST_JAZZ.create(meeting);
LocalDate today = LocalDate.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

class TypeTest {
class MeetingTypeTest {

@DisplayName("daysonly일 때 true를 반환한다.")
@Test
void isDaysOnly() {
assertAll(
() -> assertTrue(Type.DAYSONLY.isDaysOnly()),
() -> assertFalse(Type.DATETIME.isDaysOnly())
() -> assertTrue(MeetingType.DAYSONLY.isDaysOnly()),
() -> assertFalse(MeetingType.DATETIME.isDaysOnly())
);
}

@DisplayName("문자열을 Type으로 반환한다.")
@Test
void from() {
assertAll(
() -> assertEquals(Type.DAYSONLY, Type.from("daysonly")),
() -> assertEquals(Type.DATETIME, Type.from("datetime"))
() -> assertEquals(MeetingType.DAYSONLY, MeetingType.from("daysonly")),
() -> assertEquals(MeetingType.DATETIME, MeetingType.from("datetime"))
);
}

@DisplayName("문자열을 Type으로 변환할 때 널이거나 올바르지 않은 값이라면 예외를 던진다.")
@Test
void fromInvalid() {
assertAll(
() -> assertThrows(MomoException.class, () -> Type.from(null)),
() -> assertThrows(MomoException.class, () -> Type.from("invalid"))
() -> assertThrows(MomoException.class, () -> MeetingType.from(null)),
() -> assertThrows(MomoException.class, () -> MeetingType.from("invalid"))
);
}
}
4 changes: 2 additions & 2 deletions backend/src/test/java/kr/momo/fixture/MeetingFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.time.LocalTime;
import kr.momo.domain.meeting.Meeting;
import kr.momo.domain.meeting.Type;
import kr.momo.domain.meeting.MeetingType;

public enum MeetingFixture {

Expand All @@ -29,7 +29,7 @@ public Meeting create() {
return new Meeting(name, uuid, firstTime, lastTime);
}

public Meeting create(Type type) {
public Meeting create(MeetingType type) {
return new Meeting(name, uuid, firstTime, lastTime, type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import kr.momo.domain.availabledate.AvailableDateRepository;
import kr.momo.domain.meeting.Meeting;
import kr.momo.domain.meeting.MeetingRepository;
import kr.momo.domain.meeting.Type;
import kr.momo.domain.meeting.MeetingType;
import kr.momo.domain.meeting.UuidGenerator;
import kr.momo.domain.meeting.fake.FakeUuidGenerator;
import kr.momo.exception.MomoException;
Expand Down Expand Up @@ -129,7 +129,7 @@ void throwExceptionWhenUuidAlreadyExistsAfterMaxAttempts() {
List.of(LocalDate.now().toString()),
"08:00",
"22:00",
Type.DATETIME
MeetingType.DATETIME
);

assertThatThrownBy(() -> meetingService.create(request))
Expand All @@ -150,7 +150,7 @@ void throwExceptionWhenDatesHavePast() {
List.of(yesterday.toString(), today.toString()),
"08:00",
"22:00",
Type.DATETIME
MeetingType.DATETIME
);

//when //then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import kr.momo.domain.availabledate.AvailableDateRepository;
import kr.momo.domain.meeting.Meeting;
import kr.momo.domain.meeting.MeetingRepository;
import kr.momo.domain.meeting.Type;
import kr.momo.domain.meeting.MeetingType;
import kr.momo.domain.schedule.Schedule;
import kr.momo.domain.schedule.ScheduleRepository;
import kr.momo.domain.timeslot.Timeslot;
Expand Down Expand Up @@ -102,7 +102,7 @@ void createSchedulesReplacesOldSchedules() {
@DisplayName("days only 약속의 스케줄 생성 시 하루에 하나의 스케줄을 저장한다.")
@Test
void createDaysOnlySchedulesReplacesOldSchedules() {
meeting = meetingRepository.save(MeetingFixture.DRINK.create(Type.DAYSONLY));
meeting = meetingRepository.save(MeetingFixture.DRINK.create(MeetingType.DAYSONLY));
attendee = attendeeRepository.save(AttendeeFixture.HOST_JAZZ.create(meeting));
today = availableDateRepository.save(new AvailableDate(LocalDate.now(), meeting));
tomorrow = availableDateRepository.save(new AvailableDate(LocalDate.now().plusDays(1), meeting));
Expand Down
Loading

0 comments on commit 3bf3f18

Please sign in to comment.