Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public void preReserveSeat(UUID scheduleId, UUID seatId, UUID userId) {
luaScriptService.preReserveSeat(scheduleId, seatId, userId);
}

public void cancelPreReserveSeat(UUID scheduleId, UUID seatId, UUID userId) {
validatePreserve(scheduleId, seatId, userId);
cacheService.canclePreReserveSeat(scheduleId, seatId);
}

public OrderSeatResponse getOrderInfo(UUID scheduleId, UUID seatId, UUID userId) {
validatePreserve(scheduleId, seatId, userId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ticketPing.performance.domain.model.entity;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.ticketPing.performance.domain.model.enums.SeatStatus;
import lombok.*;

import java.util.UUID;
Expand Down Expand Up @@ -29,4 +30,9 @@ public static SeatCache from(Seat seat) {
.cost(seat.getSeatCost().getCost())
.build();
}

public void cancelPreReserveSeat() {
seatStatus = SeatStatus.AVAILABLE.getValue();;
userId = null;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.ticketPing.performance.infrastructure.service;

import com.ticketPing.performance.application.dtos.SeatResponse;
import com.ticketPing.performance.common.exception.SeatExceptionCase;
import com.ticketPing.performance.domain.model.entity.SeatCache;
import exception.ApplicationException;
Expand All @@ -15,6 +14,8 @@
import java.util.Optional;
import java.util.UUID;

import static caching.enums.RedisKeyPrefix.AVAILABLE_SEATS;

@Service
@RequiredArgsConstructor
public class CacheService {
Expand All @@ -29,14 +30,10 @@ public void cacheSeats(UUID scheduleId, Map<String, SeatCache> seatMap, Duration
seatCache.expire(ttl);
}

public void cacheAvailableSeats(UUID performanceId, long availableSeats) {
String key = "availableSeats:" + performanceId;
redissonClient.getBucket(key).set(availableSeats);
}

public Map<String, SeatCache> getSeatsFromCache(UUID scheduleId) {
String key = "seat:{" + scheduleId + "}";
return redissonClient.getMap(key, JsonJacksonCodec.INSTANCE);
RMap<String, SeatCache> seatCacheRMap = redissonClient.getMap(key, JsonJacksonCodec.INSTANCE);
return seatCacheRMap.readAllMap();
}

public SeatCache getSeatFromCache(UUID scheduleId, UUID seatId) {
Expand All @@ -46,4 +43,23 @@ public SeatCache getSeatFromCache(UUID scheduleId, UUID seatId) {
return Optional.ofNullable(seatCacheMap.get(seatId.toString()))
.orElseThrow(() -> new ApplicationException(SeatExceptionCase.SEAT_CACHE_NOT_FOUND));
}

public void canclePreReserveSeat(UUID scheduleId, UUID seatId) {
String key = "seat:{" + scheduleId + "}";
RMap<String, SeatCache> seatCacheMap = redissonClient.getMap(key, JsonJacksonCodec.INSTANCE);

SeatCache seatCache = Optional.ofNullable(seatCacheMap.get(seatId.toString()))
.orElseThrow(() -> new ApplicationException(SeatExceptionCase.SEAT_CACHE_NOT_FOUND));
seatCache.cancelPreReserveSeat();

seatCacheMap.put(seatId.toString(), seatCache);

String ttlKey = "ttl:{" + scheduleId + "}:" + seatId;
redissonClient.getBucket(ttlKey).delete();
}

public void cacheAvailableSeats(UUID performanceId, long availableSeats) {
String key = AVAILABLE_SEATS.getValue() + performanceId;
redissonClient.getBucket(key).set(availableSeats);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ public ResponseEntity<CommonResponse<Object>> preReserveSeat(@RequestHeader("X_U
.body(CommonResponse.success());
}

// TODO: 좌석 선점 취소
@Operation(summary = "좌석 선점 취소")
@PostMapping("/{seatId}/cancel-reserve")
public ResponseEntity<CommonResponse<Object>> cancelPreReserveSeat(@RequestHeader("X_USER_ID") UUID userId,
@RequestParam("performanceId") UUID performanceId,
@RequestParam("scheduleId") UUID scheduleId,
@PathVariable("seatId") UUID seatId) {
seatService.cancelPreReserveSeat(scheduleId, seatId, userId);
return ResponseEntity
.status(200)
.body(CommonResponse.success());
}

@Operation(summary = "좌석 주문 정보 조회 (order 서비스에서 호출용)")
@GetMapping("/{seatId}/order-info")
Expand Down
Loading