Skip to content

Commit

Permalink
fix: batch bulk 업데이트로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanna committed Jan 23, 2024
1 parent 4173bba commit 9be4b02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SeatReleaseTasklet implements Tasklet{
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
List<Ticket> tickets = ticketRepository.findAll(LocalDateTime.now(), BookingStatus.WAITING_FOR_PAYMENT);
tickets.forEach(ticket -> ticket.getSeat().updateStatus(EventSeatStatus.AVAILABLE));
ticketRepository.updateSeatStatusBulk(EventSeatStatus.AVAILABLE, tickets.stream().map(Ticket::getId).toList());
return RepeatStatus.FINISHED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.pgms.coredomain.domain.booking.BookingStatus;
import com.pgms.coredomain.domain.booking.Ticket;
import com.pgms.coredomain.domain.event.EventSeatStatus;

public interface TicketRepository extends JpaRepository<Ticket, Long> {

Expand All @@ -23,4 +25,8 @@ public interface TicketRepository extends JpaRepository<Ticket, Long> {
+ "AND b.status = :bookingStatus ")
List<Ticket> findAll(@Param("datetime") LocalDateTime dateTime,
@Param("bookingStatus") BookingStatus bookingStatus);

@Modifying
@Query("UPDATE Ticket t SET t.seat.status = :status WHERE t IN :ticketIds")
void updateSeatStatusBulk(@Param("status") EventSeatStatus status, @Param("ticketIds") List<Long> ticketIds);
}

0 comments on commit 9be4b02

Please sign in to comment.