Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
82bd9b8
탐험 도메인 구현 : feat : 탐험 ErrorCode 5종 + INSUFFICIENT_FUEL 응답 보강 #27
EM-H20 May 29, 2026
8b06bd4
탐험 도메인 구현 : feat : NodeType enum + Converter 추가 #27
EM-H20 May 29, 2026
905a830
탐험 도메인 구현 : feat : ExplorationNode 마스터 엔티티 추가 #27
EM-H20 May 29, 2026
596527b
탐험 도메인 구현 : feat : UserExploration 진행 엔티티 추가 #27
EM-H20 May 29, 2026
b348ba3
탐험 도메인 구현 : feat : Exploration Repository 2종 + 테스트 #27
EM-H20 May 29, 2026
1f5d1a0
탐험 도메인 구현 : test : ErrorResponse @JsonInclude 직렬화 검증 추가 #27
EM-H20 May 29, 2026
360da35
탐험 도메인 구현 : feat : Exploration DTO 6종 추가 #27
EM-H20 May 29, 2026
538d468
탐험 도메인 구현 : feat : ExplorationService 목록 조회 2종 #27
EM-H20 May 29, 2026
256b768
탐험 도메인 구현 : feat : 지역 해금 로직 + 잔량 pre-check + 자동 클리어 #27
EM-H20 May 29, 2026
80fd61e
탐험 도메인 구현 : feat : 행성 해금 로직 + 선행 클리어 게이트 #27
EM-H20 May 29, 2026
5e46f7b
탐험 도메인 구현 : test : 해금 서비스 에러 경로에 ErrorCode 검증 추가 #27
EM-H20 May 29, 2026
9b8dce5
탐험 도메인 구현 : feat : ExplorationController 4 엔드포인트 + 테스트 #27
EM-H20 May 29, 2026
ba500de
탐험 도메인 구현 : chore : exploration 테이블 + 시드 38노드 마이그레이션 #27
EM-H20 May 29, 2026
0064c99
탐험 도메인 구현 : docs : 05_exploration 스펙 frontend 계약 정합 갱신 #27
EM-H20 May 29, 2026
00084e0
docs : 구현 문서 #27
EM-H20 May 29, 2026
a24577a
탐험 도메인 구현 : fix : 무료 지역(requiredFuel=0) 행성 클리어 누락 수정 + 진행도 일관성 #27
EM-H20 May 29, 2026
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
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ log.warn("[Action] 경고 설명");
| 0.0.34 | `V0_0_34__add_todos_and_categories.sql` | `todos`, `todo_categories` 테이블 생성 (FK CASCADE, JSONB 컬럼) |
| 0.0.36 | `V0_0_36__add_fuel.sql` | `user_fuel`, `fuel_transactions` 테이블 생성 (CHECK 제약, FK CASCADE) |
| 0.0.39 | `V0_0_39__add_timer_sessions.sql` | `timer_sessions` 테이블 생성 (FK CASCADE, CHECK 제약 3종, 부분 unique 인덱스 on idempotency_key) |
| 0.0.42 | `V0_0_42__add_exploration.sql` | `exploration_nodes`, `user_exploration_progress` 테이블 + 행성/지역 시드 38노드 (프론트 시드 미러, self-FK, FK CASCADE, UNIQUE) |

---

Expand Down
3 changes: 2 additions & 1 deletion SS-Common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ dependencies {
api 'org.springframework.boot:spring-boot-starter-actuator'
api 'org.springframework.boot:spring-boot-starter-security'

// Flyway
// Flyway (Spring Boot 4: autoconfiguration이 spring-boot-flyway 모듈로 분리됨 — 없으면 마이그레이션 미실행)
api 'org.springframework.boot:spring-boot-flyway'
api 'org.flywaydb:flyway-core'
api 'org.flywaydb:flyway-database-postgresql'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public enum ErrorCode {
SESSION_TOO_LONG(HttpStatus.BAD_REQUEST, "공부 시간은 24시간(1440분)을 초과할 수 없습니다."),
FUTURE_SESSION(HttpStatus.BAD_REQUEST, "미래 시각의 세션은 저장할 수 없습니다."),

// Exploration
PLANET_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 행성을 찾을 수 없습니다."),
REGION_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 지역을 찾을 수 없습니다."),
ALREADY_UNLOCKED(HttpStatus.BAD_REQUEST, "이미 해금된 노드입니다."),
PLANET_LOCKED(HttpStatus.BAD_REQUEST, "상위 행성이 아직 해금되지 않았습니다."),
PREREQUISITE_NOT_CLEARED(HttpStatus.BAD_REQUEST, "이전 행성을 먼저 클리어해야 합니다."),

// Common
INVALID_INPUT_VALUE(HttpStatus.BAD_REQUEST, "입력값이 유효하지 않습니다."),
INVALID_REQUEST_BODY(HttpStatus.BAD_REQUEST, "요청 본문의 형식이 잘못되었습니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package com.elipair.spacestudyship.common.exception;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public record ErrorResponse(
String code,
String message
String message,
Integer requiredFuel,
Integer currentFuel
) {
public static ErrorResponse of(ErrorCode errorCode) {
return new ErrorResponse(errorCode.name(), errorCode.getMessage());
return new ErrorResponse(errorCode.name(), errorCode.getMessage(), null, null);
}

public static ErrorResponse of(ErrorCode errorCode, String message) {
return new ErrorResponse(errorCode.name(), message);
return new ErrorResponse(errorCode.name(), message, null, null);
}

public static ErrorResponse ofInsufficientFuel(String message, int requiredFuel, int currentFuel) {
return new ErrorResponse(ErrorCode.INSUFFICIENT_FUEL.name(), message, requiredFuel, currentFuel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ public ResponseEntity<ErrorResponse> handleCustomException(CustomException ex) {
.body(ErrorResponse.of(errorCode));
}

@ExceptionHandler(InsufficientFuelException.class)
public ResponseEntity<ErrorResponse> handleInsufficientFuel(InsufficientFuelException ex) {
log.info("[Exception] 연료 부족 | required={}, current={}", ex.getRequiredFuel(), ex.getCurrentFuel());
return ResponseEntity
.status(ErrorCode.INSUFFICIENT_FUEL.getHttpStatus())
.body(ErrorResponse.ofInsufficientFuel(
ErrorCode.INSUFFICIENT_FUEL.getMessage(),
ex.getRequiredFuel(), ex.getCurrentFuel()));
}

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ErrorResponse> handleValidationException(MethodArgumentNotValidException ex) {
String detail = ex.getBindingResult().getFieldErrors().stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.elipair.spacestudyship.common.exception;

import lombok.Getter;

@Getter
public class InsufficientFuelException extends RuntimeException {

private final int requiredFuel;
private final int currentFuel;

public InsufficientFuelException(int requiredFuel, int currentFuel) {
super(ErrorCode.INSUFFICIENT_FUEL.getMessage());
this.requiredFuel = requiredFuel;
this.currentFuel = currentFuel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.elipair.spacestudyship.common.exception;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class ErrorResponseTest {

private final ObjectMapper objectMapper = new ObjectMapper();

@Test
@DisplayName("of(ErrorCode): requiredFuel/currentFuel은 null")
void of_basic_nullFuelFields() {
ErrorResponse r = ErrorResponse.of(ErrorCode.PLANET_NOT_FOUND);
assertThat(r.code()).isEqualTo("PLANET_NOT_FOUND");
assertThat(r.requiredFuel()).isNull();
assertThat(r.currentFuel()).isNull();
}

@Test
@DisplayName("ofInsufficientFuel: 연료 수치 포함")
void ofInsufficientFuel_includesAmounts() {
ErrorResponse r = ErrorResponse.ofInsufficientFuel("연료가 부족합니다.", 10, 4);
assertThat(r.code()).isEqualTo("INSUFFICIENT_FUEL");
assertThat(r.requiredFuel()).isEqualTo(10);
assertThat(r.currentFuel()).isEqualTo(4);
}

@Test
@DisplayName("InsufficientFuelException: 게터로 수치 노출")
void exception_getters() {
InsufficientFuelException ex = new InsufficientFuelException(10, 4);
assertThat(ex.getRequiredFuel()).isEqualTo(10);
assertThat(ex.getCurrentFuel()).isEqualTo(4);
}

@Test
@DisplayName("@JsonInclude(NON_NULL): null 연료 필드는 JSON에서 제외, 연료 필드 있으면 JSON에 포함")
void jsonInclude_nonNull_wireContract() throws Exception {
String basicJson = objectMapper.writeValueAsString(ErrorResponse.of(ErrorCode.MEMBER_NOT_FOUND));
assertThat(basicJson).doesNotContain("requiredFuel");
assertThat(basicJson).doesNotContain("currentFuel");

String fuelJson = objectMapper.writeValueAsString(
ErrorResponse.ofInsufficientFuel("연료가 부족합니다.", 10, 4));
assertThat(fuelJson).contains("requiredFuel");
assertThat(fuelJson).contains("currentFuel");
assertThat(fuelJson).contains("10");
assertThat(fuelJson).contains("4");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.elipair.spacestudyship.study.exploration.constant;

public enum NodeType {
PLANET,
REGION;

/** DB 컬럼/JSON 직렬화용 소문자 표현 ("planet" / "region"). */
public String value() {
return name().toLowerCase();
}

public static NodeType from(String value) {
return NodeType.valueOf(value.toUpperCase());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.elipair.spacestudyship.study.exploration.constant;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter
public class NodeTypeConverter implements AttributeConverter<NodeType, String> {

@Override
public String convertToDatabaseColumn(NodeType attribute) {
return attribute == null ? null : attribute.value();
}

@Override
public NodeType convertToEntityAttribute(String dbData) {
return dbData == null ? null : NodeType.from(dbData);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.elipair.spacestudyship.study.exploration.dto;

import com.elipair.spacestudyship.study.exploration.entity.ExplorationNode;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

@Schema(description = "행성 응답")
public record PlanetResponse(
String id, String name, String nodeType, int depth, String icon,
@Schema(nullable = true) String parentId,
@Schema(nullable = true) String prerequisiteId,
int requiredFuel, boolean isUnlocked, boolean isCleared, int sortOrder,
String description, double mapX, double mapY,
@Schema(nullable = true, example = "2026-04-01T00:00:00Z") String unlockedAt,
ProgressDto progress
) {
private static final DateTimeFormatter ISO_UTC = DateTimeFormatter.ISO_INSTANT;

public static PlanetResponse of(ExplorationNode n, boolean isUnlocked, boolean isCleared,
int clearedChildren, int totalChildren, double progressRatio,
LocalDateTime unlockedAt) {
return new PlanetResponse(
n.getId(), n.getName(), n.getNodeType().value(), n.getDepth(), n.getIcon(),
n.getParentId(), n.getPrerequisiteNodeId(), n.getRequiredFuel(),
isUnlocked, isCleared, n.getSortOrder(), n.getDescription(), n.getMapX(), n.getMapY(),
formatUtc(unlockedAt),
new ProgressDto(clearedChildren, totalChildren, progressRatio));
}

private static String formatUtc(LocalDateTime time) {
return time == null ? null : ISO_UTC.format(time.toInstant(ZoneOffset.UTC));
}
Comment on lines +33 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# UserExploration의 unlockedAt 설정 방식 및 컬럼 매핑 확인
rg -nP -C3 'unlockedAt|unlocked_at' --type=java
ast-grep --pattern 'public static UserExploration unlock($$$) { $$$ }'

Repository: SpaceStudyShip/SpaceStudyShip-BE

Length of output: 13277


unlockedAt UTC 변환 가정을 점검해 주세요.

UserExploration.unlockedAtUserExploration.unlock()에서 LocalDateTime.now()로 저장(타임존 정보 없음)되는데, PlanetResponse.formatUtc()는 이를 toInstant(ZoneOffset.UTC)로 UTC 기준 가정 후 ISO_INSTANT(Z 접미사)로 직렬화합니다. 서버 기본 타임존이 UTC가 아니면 클라이언트에 내려가는 시각이 실제 저장/의도와 어긋날 수 있습니다. UTC 기준으로 저장하거나, 출력 시 타임존 오프셋을 함께 적용해 Instant로 변환하는 방식으로 통일해 주세요.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@SS-Study/src/main/java/com/elipair/spacestudyship/study/exploration/dto/PlanetResponse.java`
around lines 33 - 35, The formatter assumes the LocalDateTime is UTC which can
misrepresent UserExploration.unlockedAt (set via UserExploration.unlock() using
LocalDateTime.now()); update PlanetResponse.formatUtc(LocalDateTime) to convert
the local time to an Instant using the server timezone explicitly (e.g.
ZonedDateTime.of(time, ZoneId.systemDefault()).toInstant()) before formatting
with ISO_UTC, or alternatively change UserExploration.unlock() to store an
Instant (Instant.now(ZoneOffset.UTC)) and have formatUtc accept/format an
Instant; pick one approach and apply it consistently across formatUtc,
UserExploration.unlock(), and the unlockedAt field handling.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.elipair.spacestudyship.study.exploration.dto;

import com.elipair.spacestudyship.study.exploration.entity.ExplorationNode;
import com.elipair.spacestudyship.study.exploration.entity.UserExploration;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "행성 해금 응답")
public record PlanetUnlockResponse(
UnlockedNodeDto planet, int fuelConsumed, int currentFuel
) {
public static PlanetUnlockResponse of(ExplorationNode planet, UserExploration progress,
int fuelConsumed, int currentFuel) {
return new PlanetUnlockResponse(
UnlockedNodeDto.of(planet, progress, false),
fuelConsumed, currentFuel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.elipair.spacestudyship.study.exploration.dto;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "행성 진행도")
public record ProgressDto(
@Schema(example = "3") int clearedChildren,
@Schema(example = "5") int totalChildren,
@Schema(example = "0.6") double progressRatio
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.elipair.spacestudyship.study.exploration.dto;

import com.elipair.spacestudyship.study.exploration.entity.ExplorationNode;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

@Schema(description = "지역 응답")
public record RegionResponse(
String id, String name, String nodeType, int depth, String icon,
@Schema(nullable = true) String parentId,
int requiredFuel, boolean isUnlocked, boolean isCleared, int sortOrder,
String description, double mapX, double mapY,
@Schema(nullable = true, example = "2026-04-05T15:30:00Z") String unlockedAt
) {
private static final DateTimeFormatter ISO_UTC = DateTimeFormatter.ISO_INSTANT;

public static RegionResponse of(ExplorationNode n, boolean isUnlocked, boolean isCleared,
LocalDateTime unlockedAt) {
return new RegionResponse(
n.getId(), n.getName(), n.getNodeType().value(), n.getDepth(), n.getIcon(),
n.getParentId(), n.getRequiredFuel(), isUnlocked, isCleared,
n.getSortOrder(), n.getDescription(), n.getMapX(), n.getMapY(),
formatUtc(unlockedAt));
}

private static String formatUtc(LocalDateTime time) {
return time == null ? null : ISO_UTC.format(time.toInstant(ZoneOffset.UTC));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.elipair.spacestudyship.study.exploration.dto;

import com.elipair.spacestudyship.study.exploration.entity.ExplorationNode;
import com.elipair.spacestudyship.study.exploration.entity.UserExploration;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "지역 해금 응답")
public record RegionUnlockResponse(
UnlockedNodeDto region, int fuelConsumed, int currentFuel, boolean planetCleared
) {
public static RegionUnlockResponse of(ExplorationNode region, UserExploration progress,
int fuelConsumed, int currentFuel, boolean planetCleared) {
return new RegionUnlockResponse(
UnlockedNodeDto.of(region, progress, true),
fuelConsumed, currentFuel, planetCleared);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.elipair.spacestudyship.study.exploration.dto;

import com.elipair.spacestudyship.study.exploration.entity.ExplorationNode;
import com.elipair.spacestudyship.study.exploration.entity.UserExploration;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

@Schema(description = "해금된 노드 요약")
public record UnlockedNodeDto(
String id, String name, boolean isUnlocked, boolean isCleared,
@Schema(example = "2026-04-16T11:00:00Z") String unlockedAt
) {
private static final DateTimeFormatter ISO_UTC = DateTimeFormatter.ISO_INSTANT;

public static UnlockedNodeDto of(ExplorationNode node, UserExploration progress, boolean cleared) {
return new UnlockedNodeDto(
node.getId(), node.getName(), true, cleared,
formatUtc(progress.getUnlockedAt()));
}

private static String formatUtc(LocalDateTime time) {
return time == null ? null : ISO_UTC.format(time.toInstant(ZoneOffset.UTC));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.elipair.spacestudyship.study.exploration.entity;

import com.elipair.spacestudyship.study.exploration.constant.NodeType;
import com.elipair.spacestudyship.study.exploration.constant.NodeTypeConverter;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "exploration_nodes")
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ExplorationNode {

@Id
@Column(length = 50)
private String id;

@Column(nullable = false, length = 50)
private String name;

@Convert(converter = NodeTypeConverter.class)
@Column(name = "node_type", nullable = false, length = 10)
private NodeType nodeType;

@Column(nullable = false)
private int depth;

@Column(nullable = false, length = 30)
private String icon;

@Column(name = "parent_id", length = 50)
private String parentId;

@Column(name = "prerequisite_node_id", length = 50)
private String prerequisiteNodeId;

@Column(name = "required_fuel", nullable = false)
private int requiredFuel;

@Column(name = "sort_order", nullable = false)
private int sortOrder;

@Column(nullable = false, length = 200)
private String description;

@Column(name = "map_x", nullable = false)
private double mapX;

@Column(name = "map_y", nullable = false)
private double mapY;
}
Loading
Loading