Skip to content
Closed
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
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ dependencies {

implementation 'org.hibernate.orm:hibernate-spatial:'

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// REDIS CACHE
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.yscp.catchtable.application.queue;

import com.yscp.catchtable.application.queue.dto.StoreQueueDto;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class StoreQueueService {
private final RedisTemplate<String, String> redisTemplate;

public void registerWaiting(StoreQueueDto storeQueueDto) {
redisTemplate.opsForZSet().add(storeQueueDto.key(), storeQueueDto.value(), storeQueueDto.score());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.yscp.catchtable.application.queue.dto;

import java.time.Instant;

public record StoreQueueDto(
Long storeIdx,
String date,
String time,
String userId
) {
private static final String WAITING_KEY_FORMAT = "store:%s:waiting:%s:%s";

public String key() {
return String.format(WAITING_KEY_FORMAT, storeIdx, date, time);
}

public String value() {
return userId.toString();
}

public double score() {
return Instant.now().toEpochMilli();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.yscp.catchtable.application.store.mapper;

import com.yscp.catchtable.application.queue.dto.StoreQueueDto;
import com.yscp.catchtable.presentation.store.dto.StoreQueueRequestDto;
import lombok.experimental.UtilityClass;

@UtilityClass
public class StoreQueueMapper {
public static StoreQueueDto toQueueDto(StoreQueueRequestDto storeQueueRequestDto) {
return new StoreQueueDto(
storeQueueRequestDto.storeIdx(),
storeQueueRequestDto.date(),
storeQueueRequestDto.time(),
storeQueueRequestDto.userId()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.yscp.catchtable.presentation.store;

import com.yscp.catchtable.application.queue.StoreQueueService;
import com.yscp.catchtable.application.store.mapper.StoreQueueMapper;
import com.yscp.catchtable.presentation.store.dto.StoreQueueRequestDto;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
public class StoreQueueController {
private final StoreQueueService storeQueueService;

@PostMapping("/store/reservation/enter")
public ResponseEntity<Void> enter(@RequestBody StoreQueueRequestDto storeQueueRequestDto) {
storeQueueService.registerWaiting(StoreQueueMapper.toQueueDto(storeQueueRequestDto));
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.yscp.catchtable.presentation.store.dto;

public record StoreQueueRequestDto(
Long storeIdx,
String date,
String time,
String userId
) {
}