Skip to content

Commit 44e4416

Browse files
committed
refactor(schedule): 중복 로직을 헬퍼 메서드로 정리, 테이블에 인덱스 추가, Date 필드 삭제(불필요)
1 parent 3e0fdb1 commit 44e4416

File tree

5 files changed

+24
-30
lines changed

5 files changed

+24
-30
lines changed

src/main/java/back/kalender/domain/schedule/dto/response/MonthlyScheduleItem.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public record MonthlyScheduleItem(
2929
@Schema(description = "공연 ID (공연 일정인 경우 포함, 없을 경우 null)", example = "501")
3030
Optional<Long> performanceId,
3131

32-
@Schema(description = "일정 날짜 (YYYY-MM-DD)", example = "2025-11-02")
33-
LocalDate date,
34-
3532
@Schema(description = "일정 장소 (선택 사항)", example = "고척 스카이돔")
3633
Optional<String> location
3734
) {
@@ -43,7 +40,6 @@ public MonthlyScheduleItem(
4340
ScheduleCategory scheduleCategory,
4441
LocalDateTime scheduleTime,
4542
Long performanceId,
46-
LocalDate date,
4743
String location
4844
) {
4945
this(
@@ -54,7 +50,6 @@ public MonthlyScheduleItem(
5450
scheduleCategory,
5551
scheduleTime,
5652
Optional.ofNullable(performanceId),
57-
date,
5853
Optional.ofNullable(location)
5954
);
6055
}

src/main/java/back/kalender/domain/schedule/entity/Schedule.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
import java.time.LocalDateTime;
1010

1111
@Entity
12-
@Table(name = "schedules")
12+
@Table(
13+
name = "schedules",
14+
indexes = @Index(name = "idx_schedule_artist_time", columnList = "artistId, scheduleTime")
15+
)
1316
@Getter
1417
@Builder
1518
@NoArgsConstructor(access = AccessLevel.PROTECTED)
16-
@AllArgsConstructor
19+
@AllArgsConstructor(access = AccessLevel.PRIVATE)
1720
public class Schedule extends BaseEntityTmp {
1821

1922
@Column(nullable = false)
@@ -34,7 +37,4 @@ public class Schedule extends BaseEntityTmp {
3437
private LocalDateTime scheduleTime;
3538

3639
private String location;
37-
38-
private LocalDate date;
39-
//TODO: scheduleTime, date 차이 명확히 알아두기, 실제 일정 날짜는 3일이고 티켓팅은 1일일 때 데이터 처리 어떻게 할지 고민하기
4040
}

src/main/java/back/kalender/domain/schedule/repository/ScheduleRepository.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public interface ScheduleRepository extends JpaRepository<Schedule, Long> {
2222
s.scheduleCategory,
2323
s.scheduleTime,
2424
s.performanceId,
25-
CAST(s.scheduleTime AS LocalDate),
2625
s.location
2726
)
2827
FROM Schedule s

src/main/java/back/kalender/domain/schedule/service/ScheduleServiceImpl.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,14 @@ public MonthlySchedulesResponse getFollowingSchedules(Long userId, int year, int
4141
throw new ServiceException(ErrorCode.INVALID_INPUT_VALUE);
4242
}
4343

44-
List<ArtistFollowTmp> follows = artistFollowRepository.findAllByUserId(userId);
45-
log.debug("[Schedule] [GetFollowing] 팔로우 아티스트 조회 완료 - count={}", follows.size());
44+
List<Long> artistIds = getFollowedArtistIds(userId);
4645

47-
if (follows.isEmpty()) {
46+
if (artistIds.isEmpty()) {
4847
log.info("[Schedule] [GetFollowing] 팔로우한 아티스트 없음, 빈 리스트 반환 - userId={}", userId);
4948
return new MonthlySchedulesResponse(Collections.emptyList());
5049
}
5150

52-
List<Long> artistIds = follows.stream()
53-
.map(follow -> follow.getArtist().getId())
54-
.toList();
55-
log.debug("[Schedule] [GetFollowing] 대상 아티스트 ID 추출 - artistIds={}", artistIds);
51+
log.debug("[Schedule] [GetFollowing] 대상 아티스트 ID 추출 - count={}, ids={}", artistIds.size(), artistIds);
5652

5753
try {
5854
YearMonth yearMonth = YearMonth.of(year, month);
@@ -160,17 +156,13 @@ public DailySchedulesResponse getDailySchedules(Long userId, String date, Option
160156
log.debug("[Schedule] [GetDaily] 단일 아티스트 필터링 적용 - artistId={}", id);
161157

162158
} else {
163-
List<ArtistFollowTmp> follows = artistFollowRepository.findAllByUserId(userId);
159+
targetArtistIds = getFollowedArtistIds(userId);
164160

165-
if (follows.isEmpty()) {
161+
if (targetArtistIds.isEmpty()) {
166162
log.info("[Schedule] [GetDaily] 팔로우한 아티스트 없음 - 빈 리스트 반환");
167163
return new DailySchedulesResponse(Collections.emptyList());
168164
}
169165

170-
targetArtistIds = follows.stream()
171-
.map(follow -> follow.getArtist().getId())
172-
.toList();
173-
174166
log.debug("[Schedule] [GetDaily] 전체 팔로우 아티스트 적용 - count={}", targetArtistIds.size());
175167
}
176168

@@ -208,16 +200,13 @@ public UpcomingEventsResponse getUpcomingEvents(Long userId, Optional<Long> arti
208200
log.debug("[Schedule] [GetUpcoming] 단일 아티스트 필터링 적용 - artistId={}", id);
209201

210202
} else {
211-
List<ArtistFollowTmp> follows = artistFollowRepository.findAllByUserId(userId);
203+
targetArtistIds = getFollowedArtistIds(userId);
212204

213-
if (follows.isEmpty()) {
205+
if (targetArtistIds.isEmpty()) {
214206
log.info("[Schedule] [GetUpcoming] 팔로우한 아티스트 없음 - 빈 리스트 반환");
215207
return new UpcomingEventsResponse(Collections.emptyList());
216208
}
217209

218-
targetArtistIds = follows.stream()
219-
.map(follow -> follow.getArtist().getId())
220-
.toList();
221210
log.debug("[Schedule] [GetUpcoming] 전체 팔로우 아티스트 적용 - count={}", targetArtistIds.size());
222211
}
223212

@@ -251,4 +240,16 @@ public UpcomingEventsResponse getUpcomingEvents(Long userId, Optional<Long> arti
251240

252241
return new UpcomingEventsResponse(processedItems);
253242
}
243+
244+
private List<Long> getFollowedArtistIds(Long userId) {
245+
List<ArtistFollowTmp> follows = artistFollowRepository.findAllByUserId(userId);
246+
247+
if (follows.isEmpty()) {
248+
return Collections.emptyList();
249+
}
250+
251+
return follows.stream()
252+
.map(follow -> follow.getArtist().getId())
253+
.toList();
254+
}
254255
}

src/test/java/back/kalender/domain/schedule/service/ScheduleServiceImplTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ private MonthlyScheduleItem createDto(Long id, Long artistId, String artistName,
9292
ScheduleCategory.CONCERT,
9393
LocalDateTime.now(),
9494
Optional.empty(),
95-
LocalDate.now(),
9695
Optional.empty()
9796
);
9897
}

0 commit comments

Comments
 (0)