Skip to content

Commit

Permalink
Feature/#151 show (#153)
Browse files Browse the repository at this point in the history
* feat: ShowFavorite MemberId 적용

* feat: 회원 공연 좋아요 여부 MEmberId 적용

* feat: 좋아요 공연 리스트 조회 MemberId 적용

* prune: ShowDateTime 제거

* style: BoxOffice 패키지 이동

* feat: ShowJob

* feat: Show 값 타입 리스트 생성자에 추가

* feat: ShowJob 업데이트 추가

* feat: cache evict 스케줄링 설정 변경
  • Loading branch information
Cho-D-YoungRae authored Dec 27, 2023
1 parent a114ac5 commit fd27d9f
Show file tree
Hide file tree
Showing 41 changed files with 181 additions and 675 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cmc.curtaincall.batch.job.facility;
package org.cmc.curtaincall.batch.job.show;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cmc.curtaincall.batch.job.facility;
package org.cmc.curtaincall.batch.job.show;

import jakarta.persistence.EntityManagerFactory;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cmc.curtaincall.batch.job.facility;
package org.cmc.curtaincall.batch.job.show;

import lombok.RequiredArgsConstructor;
import org.cmc.curtaincall.batch.service.kopis.KopisService;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,14 @@ public ShowKopisPagingItemReader showKopisPagingItemReader(
@Bean
@StepScope
public ShowKopisItemProcessor showKopisItemProcessor() {
return new ShowKopisItemProcessor(kopisService, showExistsDao);
return new ShowKopisItemProcessor(kopisService);
}

@Bean
@StepScope
public JpaItemWriter<Show> showItemWriter() {
return new JpaItemWriterBuilder<Show>()
.entityManagerFactory(emf)
.usePersist(true)
.build();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@
import org.cmc.curtaincall.domain.show.Facility;
import org.cmc.curtaincall.domain.show.FacilityId;
import org.cmc.curtaincall.domain.show.Show;
import org.cmc.curtaincall.domain.show.ShowDay;
import org.cmc.curtaincall.domain.show.ShowGenre;
import org.cmc.curtaincall.domain.show.ShowId;
import org.cmc.curtaincall.domain.show.ShowState;
import org.cmc.curtaincall.domain.show.ShowTime;
import org.cmc.curtaincall.domain.show.dao.ShowExistsDao;
import org.springframework.batch.item.ItemProcessor;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand All @@ -35,8 +29,6 @@ public class ShowKopisItemProcessor implements ItemProcessor<ShowResponse, Show>

private final KopisService kopisService;

private final ShowExistsDao showExistsDao;

private final Set<String> allowedGenreNames = Arrays.stream(ShowGenre.values())
.map(ShowGenre::getTitle)
.collect(Collectors.toSet());
Expand All @@ -51,23 +43,9 @@ public class ShowKopisItemProcessor implements ItemProcessor<ShowResponse, Show>
private final Map<String, ShowState> stateMapper = Arrays.stream(ShowState.values())
.collect(Collectors.toMap(ShowState::getTitle, Function.identity()));

private final Map<ShowDay, DayOfWeek> showDayToDayOfWeek = Map.of(
ShowDay.MONDAY, DayOfWeek.MONDAY,
ShowDay.TUESDAY, DayOfWeek.TUESDAY,
ShowDay.WEDNESDAY, DayOfWeek.WEDNESDAY,
ShowDay.THURSDAY, DayOfWeek.THURSDAY,
ShowDay.FRIDAY, DayOfWeek.FRIDAY,
ShowDay.SATURDAY, DayOfWeek.SATURDAY,
ShowDay.SUNDAY, DayOfWeek.SUNDAY
);

@Override
public Show process(ShowResponse item) throws Exception {
final ShowId showId = new ShowId(item.id());
if (showExistsDao.exists(showId)) {
log.debug("공연({})은 존재하는 데이터입니다.", showId);
return null;
}
if (!allowedGenreNames.contains(item.genreName())) {
log.debug("공연({})은 다루지 않는 장르({})입니다.", item.id(), item.genreName());
return null;
Expand All @@ -78,10 +56,9 @@ public Show process(ShowResponse item) throws Exception {
List<ShowTime> showTimes = showTimeParser.parse(showDetail.showTimes());
LocalDate startDate = LocalDate.parse(showDetail.startDate(), showDateFormatter);
LocalDate endDate = LocalDate.parse(showDetail.endDate(), showDateFormatter);
List<LocalDateTime> showDateTimes = getShowDateTimes(startDate, endDate, showTimes);

Show show = Show.builder()
.id(new ShowId(showDetail.id()))
return Show.builder()
.id(showId)
.facility(new Facility(new FacilityId(showDetail.facilityId())))
.name(showDetail.name())
.startDate(startDate)
Expand All @@ -97,29 +74,9 @@ public Show process(ShowResponse item) throws Exception {
.genre(showGenre)
.state(stateMapper.get(showDetail.state()))
.openRun(showDetail.openRun())
.showTimes(showTimes)
.introductionImages(showDetail.introductionImages())
.build();
show.getShowTimes().addAll(showTimes);
show.getIntroductionImages().addAll(showDetail.introductionImages());
showDateTimes.forEach(show::addShowDateTime);
return show;
}

private List<LocalDateTime> getShowDateTimes(LocalDate startDate, LocalDate endDate, List<ShowTime> showTimes) {
Map<DayOfWeek, List<ShowTime>> dayOfWeekToShowTimes = showTimes.stream()
.filter(showTime -> showDayToDayOfWeek.containsKey(showTime.getDayOfWeek()))
.collect(Collectors.groupingBy(showTime -> showDayToDayOfWeek.get(showTime.getDayOfWeek())));

List<LocalDateTime> result = new ArrayList<>();
for (int i = 0; i < Period.between(startDate, endDate).getDays(); i++) {
LocalDate date = startDate.plusDays(i);
DayOfWeek dayOfWeek = date.getDayOfWeek();
if (dayOfWeekToShowTimes.containsKey(dayOfWeek)) {
result.addAll(dayOfWeekToShowTimes.get(dayOfWeek).stream()
.map(showTime -> LocalDateTime.of(date, showTime.getTime()))
.toList()
);
}
}
return result;
}
}
Loading

0 comments on commit fd27d9f

Please sign in to comment.