-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat : 예매대기 처리 스케줄러 구현 #43
Changes from 5 commits
a384874
b350dfa
239049b
6cff378
0b86696
7901712
8921b03
566ab5d
5aa39f2
0924434
47d2ab0
6c771ce
5d75bc6
b84ab45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
package dev.hooon.show.domain.repository; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import dev.hooon.show.domain.entity.seat.Seat; | ||
import dev.hooon.show.domain.entity.seat.SeatStatus; | ||
import dev.hooon.show.dto.query.SeatDateRoundDto; | ||
|
||
public interface SeatRepository { | ||
|
||
void saveAll(Iterable<Seat> seats); | ||
|
||
Optional<Seat> findById(Long id); | ||
|
||
List<SeatDateRoundDto> findSeatDateRoundInfoByShowId(Long showId); | ||
|
||
List<Seat> findByStatusIsCanceled(); | ||
|
||
void updateStatusByIdIn(Collection<Long> ids, SeatStatus status); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,7 @@ | |
|
||
public interface UserRepository { | ||
|
||
User save(User user); | ||
|
||
Optional<User> findById(Long id); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import static jakarta.persistence.FetchType.*; | ||
import static jakarta.persistence.GenerationType.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
@@ -52,6 +53,8 @@ public class WaitingBooking extends TimeBaseEntity { | |
|
||
private int seatCount; | ||
|
||
private LocalDateTime expireAt; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expiredAt 은 어떤가요?! (근데 사실 너무 사소함 ㅎㅎ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 의미적으로 그게 더 맞는거같네요! 수정하겠습니다 ㅎㅎ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. b84ab45 |
||
|
||
@OneToMany(mappedBy = "waitingBooking", cascade = {REMOVE, PERSIST}) | ||
List<WaitingBookingSeat> waitingBookingSeats = new ArrayList<>(); | ||
|
||
|
@@ -108,4 +111,10 @@ public static WaitingBooking of( | |
) { | ||
return new WaitingBooking(user, seatCount, seatIds); | ||
} | ||
|
||
public List<Long> getSelectedSeatIds() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 예약 대기 좌석에 해당하는 좌석 id값을 list로 반환하는 함수가 맞을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 맞습니다~ 👍 |
||
return waitingBookingSeats.stream() | ||
.map(WaitingBookingSeat::getSeatId) | ||
.toList(); | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 테스트 꼼꼼히 잘 작성하셨어요!! 굿굿 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,17 +10,23 @@ | |
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
import dev.hooon.common.fixture.SeatFixture; | ||
import dev.hooon.common.support.DataJpaTestSupport; | ||
import dev.hooon.show.domain.entity.seat.Seat; | ||
import dev.hooon.show.domain.entity.seat.SeatStatus; | ||
import dev.hooon.show.dto.query.SeatDateRoundDto; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
|
||
@DisplayName("[SeatJpaRepository 테스트]") | ||
class SeatRepositoryTest extends DataJpaTestSupport { | ||
|
||
@Autowired | ||
private SeatRepository seatRepository; | ||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
private void assertSeatDateRoundDto(SeatDateRoundDto dto, Seat expected) { | ||
assertAll( | ||
|
@@ -52,4 +58,54 @@ void findSeatDateRoundInfoByShowIdTest() { | |
assertSeatDateRoundDto(result.get(1), seats.get(2)); | ||
assertSeatDateRoundDto(result.get(2), seats.get(3)); | ||
} | ||
|
||
@Test | ||
@DisplayName("[상태가 CANCELED 상태인 좌석을 조회한다]") | ||
void findByStatusIsCanceledTest() { | ||
//given | ||
List<Seat> seats = List.of( | ||
SeatFixture.getSeat(), | ||
SeatFixture.getSeat(), | ||
SeatFixture.getSeat() | ||
); | ||
// 0번 Seat 만 Canceled 상태로 변경(취소 기능이 아직 구현되지 않아서 리플렉션 사용) | ||
ReflectionTestUtils.setField(seats.get(0), "seatStatus", SeatStatus.CANCELED); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻👍🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리플랙션이 정말 사기적인 기술이긴한데.. 안좋은 측면도 있어서 남발하지만 않으면 좋은거같아요! |
||
|
||
seatRepository.saveAll(seats); | ||
|
||
//when | ||
List<Seat> result = seatRepository.findByStatusIsCanceled(); | ||
|
||
//then | ||
assertThat(result) | ||
.hasSize(1) | ||
.contains(seats.get(0)); | ||
} | ||
|
||
@Test | ||
@DisplayName("[id 와 status 를 입력하면 id 에 해당하는 좌석의 상태를 입력한 status 로 변경한다]") | ||
void updateStatusByIdInTest() { | ||
//given | ||
List<Seat> seats = List.of( | ||
SeatFixture.getSeat(), | ||
SeatFixture.getSeat(), | ||
SeatFixture.getSeat() | ||
); | ||
seatRepository.saveAll(seats); | ||
|
||
List<Long> seatIds = seats.stream().map(Seat::getId).toList(); | ||
|
||
//when | ||
seatRepository.updateStatusByIdIn(seatIds, SeatStatus.CANCELED); | ||
entityManager.flush(); | ||
entityManager.clear(); | ||
|
||
//then | ||
List<Seat> actual = seatRepository.findByStatusIsCanceled(); | ||
List<Long> actualIds = actual.stream().map(Seat::getId).toList(); | ||
|
||
assertThat(actualIds) | ||
.hasSameSizeAs(seatIds) | ||
.containsAll(seatIds); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dependencies { | ||
implementation project(':core') | ||
testImplementation(testFixtures(project(':core'))) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.hooon; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class SchedulerApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SchedulerApplication.class, args); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
spring: | ||
jpa: | ||
show-sql: true | ||
hibernate: | ||
ddl-auto: create | ||
properties: | ||
hibernate: | ||
dialect: org.hibernate.dialect.PostgreSQLDialect | ||
format_sql: true | ||
|
||
logging: | ||
level: | ||
org.hibernate.sql: info |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 스케줄러 모듈 설정 잘 추가하신 것 같아요! 👍🏻 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ rootProject.name = 'interpark' | |
|
||
include 'api' | ||
include 'core' | ||
include 'scheduler' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻👍🏻