Skip to content

Commit 594fc8b

Browse files
authored
feat : 게임 캐릭터 체크 api 추가 (#161)
1 parent 5025e44 commit 594fc8b

File tree

9 files changed

+52
-4
lines changed

9 files changed

+52
-4
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.ezcode.codetest.application.game.dto.response.character;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
5+
@Schema(description = "캐릭터 생성 여부 확인 response")
6+
public record CharacterCheckResponse(
7+
8+
boolean isCharacterExist
9+
10+
) {
11+
}

src/main/java/org/ezcode/codetest/application/game/play/GamePlayUseCase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.ezcode.codetest.application.game.dto.request.encounter.EncounterChoiceRequest;
88
import org.ezcode.codetest.application.game.dto.request.skill.SkillEquipRequest;
99
import org.ezcode.codetest.application.game.dto.request.skill.SkillUnEquipRequest;
10+
import org.ezcode.codetest.application.game.dto.response.character.CharacterCheckResponse;
1011
import org.ezcode.codetest.application.game.dto.response.character.CharacterStatusResponse;
1112
import org.ezcode.codetest.application.game.dto.response.encounter.BattleHistoryResponse;
1213
import org.ezcode.codetest.application.game.dto.response.encounter.DefenceBattleHistoryResponse;
@@ -59,6 +60,12 @@ public void createCharacter(String email) {
5960
characterService.createGameCharacter(new GameCharacter(user));
6061
}
6162

63+
@Transactional
64+
public CharacterCheckResponse isCharacterExist(Long userId) {
65+
66+
return new CharacterCheckResponse(characterService.isCharacterExist(userId));
67+
}
68+
6269
@Transactional
6370
public CharacterStatusResponse characterStatusOpen(Long userId) {
6471

src/main/java/org/ezcode/codetest/domain/game/exception/GameExceptionCode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public enum GameExceptionCode implements ResponseCode {
1414
ITEM_NOT_FOUND(false, HttpStatus.NOT_FOUND, "해당 아이템이 인벤토리에 없습니다."),
1515
SKILL_NOT_EXISTS(false, HttpStatus.NOT_FOUND, "해당 스킬이 존재하지 않습니다."),
1616
ITEM_NOT_EXISTS(false, HttpStatus.NOT_FOUND, "해당 아이템이 존재하지 않습니다."),
17-
CHARACTER_NOT_FOUND(false, HttpStatus.NOT_FOUND, "해당 캐릭터가 조회되지 없습니다."),
17+
CHARACTER_NOT_FOUND(false, HttpStatus.NOT_FOUND, "해당 캐릭터가 조회되지 않습니다."),
1818
RANDOM_CHARACTER_MATCHING_FAIL(false, HttpStatus.NOT_FOUND, "현재 매칭가능한 유저가 존재하지 않습니다."),
1919
NOT_ENOUGH_GOLD(false, HttpStatus.BAD_REQUEST, "도박을 하기에 충분한 골드가 있지 않습니다."),
2020
SKILL_NOT_FOUND(false, HttpStatus.NOT_FOUND, "해당 스킬이 조회되지 없습니다."),

src/main/java/org/ezcode/codetest/domain/game/repository/GameCharacterRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public interface GameCharacterRepository {
1111
Optional<GameCharacter> findByUserId(Long userId);
1212

1313
Optional<GameCharacter> findRandomCharacter(Long userId);
14+
15+
boolean isCharacterExist(Long userId);
1416
}

src/main/java/org/ezcode/codetest/domain/game/service/CharacterStatusDomainService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public GameCharacter createGameCharacter(GameCharacter character) {
5151
return savedCharacter;
5252
}
5353

54+
public boolean isCharacterExist(Long userId) {
55+
56+
return characterRepository.isCharacterExist(userId);
57+
}
58+
5459
public GameCharacter getGameCharacter(Long userId) {
5560

5661
return characterRepository.findByUserId(userId)

src/main/java/org/ezcode/codetest/infrastructure/persistence/repository/game/mysql/character/GameCharacterJpaRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ public interface GameCharacterJpaRepository extends JpaRepository<GameCharacter,
2020

2121
@Cacheable(value = "counts", key = "'count'")
2222
long count();
23+
24+
boolean existsByUserId(Long userId);
2325
}

src/main/java/org/ezcode/codetest/infrastructure/persistence/repository/game/mysql/character/GameCharacterRepositoryImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public GameCharacter save(GameCharacter character) {
2121
return characterRepository.save(character);
2222
}
2323

24+
@Override
25+
public boolean isCharacterExist(Long userId) {
26+
27+
return characterRepository.existsByUserId(userId);
28+
}
29+
2430
@Override
2531
public Optional<GameCharacter> findByUserId(Long userId) {
2632

src/main/java/org/ezcode/codetest/presentation/game/play/GamePlayController.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.ezcode.codetest.application.game.dto.request.item.ItemGamblingRequest;
99
import org.ezcode.codetest.application.game.dto.request.skill.SkillEquipRequest;
1010
import org.ezcode.codetest.application.game.dto.request.skill.SkillUnEquipRequest;
11+
import org.ezcode.codetest.application.game.dto.response.character.CharacterCheckResponse;
1112
import org.ezcode.codetest.application.game.dto.response.character.CharacterStatusResponse;
1213
import org.ezcode.codetest.application.game.dto.response.encounter.BattleHistoryResponse;
1314
import org.ezcode.codetest.application.game.dto.response.encounter.DefenceBattleHistoryResponse;
@@ -60,6 +61,20 @@ public ResponseEntity<Void> createCharacter(
6061
return ResponseEntity.status(HttpStatus.CREATED).build();
6162
}
6263

64+
@Operation(
65+
summary = "게임 캐릭터 생성 확인 API",
66+
description = "현재 사용자가 게임 캐릭터를 생성했는지 확인합니다..",
67+
responses = {
68+
@ApiResponse(responseCode = "200", description = "확인후 true / false 반환")
69+
}
70+
)
71+
@GetMapping("/characters/check")
72+
public ResponseEntity<CharacterCheckResponse> checkCharacter(
73+
@AuthenticationPrincipal AuthUser authUser
74+
) {
75+
return ResponseEntity.status(HttpStatus.OK).body(gamePlayUseCase.isCharacterExist(authUser.getId()));
76+
}
77+
6378
@Operation(
6479
summary = "스테이터스 조회 API",
6580
description = "현재 캐릭터의 상태를 조회합니다.",

src/main/resources/templates/chat-page.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ <h2>채팅방 목록</h2>
262262
stompClient = Stomp.over(socket);
263263

264264
// ─── Heartbeat 5분(300,000ms) 설정 ───
265-
stompClient.heartbeat.outgoing = 300000; // 클라이언트→서버 heartbeat 전송 간격
266-
stompClient.heartbeat.incoming = 300000; // 서버→클라이언트 heartbeat 수신 허용 최대 간격
267-
const hbHeader = {'heart-beat': '300000,300000'};
265+
stompClient.heartbeat.outgoing = 20000; // 클라이언트→서버 heartbeat 전송 간격
266+
stompClient.heartbeat.incoming = 600000; // 서버→클라이언트 heartbeat 수신 허용 최대 간격
267+
const hbHeader = {'heart-beat': '20000,600000'};
268268
// ────────────────────────────────────
269269

270270
stompClient.connect(

0 commit comments

Comments
 (0)