Skip to content

Commit e6245c8

Browse files
authored
Merge pull request #146 from SEMOSAN/feat/#145-hiking-record-session-id
[Feat] 등산 기록 응답에 트래킹 세션 ID를 추가
2 parents 94e9381 + 52f2a93 commit e6245c8

5 files changed

Lines changed: 93 additions & 1 deletion

File tree

src/main/java/com/semosan/api/domain/demo/service/DemoService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class DemoService {
3434
public List<String> getDemoPhotos(Long sessionId, int count) {
3535
List<String> shuffled = new ArrayList<>(demoProperties.photoFilenames());
3636
Collections.shuffle(shuffled);
37-
List<String> randomUrls = shuffled.subList(0, Math.min(count, shuffled.size()))
37+
List<String> randomUrls = shuffled.subList(0, safeRandomPhotoCount(count, shuffled.size()))
3838
.stream()
3939
.map(this::presignedGetUrl)
4040
.toList();
@@ -50,6 +50,11 @@ public List<String> getDemoPhotos(Long sessionId, int count) {
5050
return combined;
5151
}
5252

53+
// 음수 count 요청이 들어와도 subList 범위를 벗어나지 않도록 보정합니다.
54+
private int safeRandomPhotoCount(int count, int availableCount) {
55+
return Math.max(0, Math.min(count, availableCount));
56+
}
57+
5358
private String presignedGetUrl(String objectKey) {
5459
try {
5560
String url = minioClient.getPresignedObjectUrl(

src/main/java/com/semosan/api/domain/hiking/dto/response/GetUserHikingRecordResponse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
public record GetUserHikingRecordResponse(
1010
Long hikingRecordId,
11+
Long sessionId,
1112
Long mountainId,
1213
String mountainName,
1314
Long courseId,
@@ -23,6 +24,7 @@ public record GetUserHikingRecordResponse(
2324
public static GetUserHikingRecordResponse from(UserHikingRecordProjection projection) {
2425
return new GetUserHikingRecordResponse(
2526
projection.getHikingRecordId(),
27+
projection.getSessionId(),
2628
projection.getMountainId(),
2729
projection.getMountainName(),
2830
projection.getCourseId(),
@@ -34,6 +36,7 @@ public static GetUserHikingRecordResponse from(UserHikingRecordProjection projec
3436
);
3537
}
3638

39+
// 사진 URL 필드 중 존재하는 값만 응답 순서에 맞춰 모읍니다.
3740
private static List<String> buildImageUrls(String photoReportImageUrl, String cliveImageUrl) {
3841
List<String> urls = new ArrayList<>(2);
3942
if (photoReportImageUrl != null) {

src/main/java/com/semosan/api/domain/hiking/repository/HikingRecordRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Page<UserHikingMountainRecordProjection> findUserHikingMountainRecordsByUserId(
6262
value = """
6363
SELECT
6464
hr.id AS hikingRecordId,
65+
hr.tracking_session_id AS sessionId,
6566
m.id AS mountainId,
6667
m.name AS mountainName,
6768
c.id AS courseId,
@@ -109,6 +110,7 @@ Page<UserHikingRecordProjection> findUserHikingRecordsByUserId(
109110
value = """
110111
SELECT
111112
hr.id AS hikingRecordId,
113+
hr.tracking_session_id AS sessionId,
112114
m.id AS mountainId,
113115
m.name AS mountainName,
114116
c.id AS courseId,

src/main/java/com/semosan/api/domain/hiking/repository/projection/UserHikingRecordProjection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public interface UserHikingRecordProjection {
66

77
Long getHikingRecordId();
88

9+
Long getSessionId();
10+
911
Long getMountainId();
1012

1113
String getMountainName();
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.semosan.api.domain.hiking.dto.response;
2+
3+
import com.semosan.api.domain.hiking.repository.projection.UserHikingRecordProjection;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.time.LocalDate;
7+
import java.time.LocalDateTime;
8+
9+
import static org.assertj.core.api.Assertions.assertThat;
10+
11+
class GetUserHikingRecordResponseTest {
12+
13+
@Test
14+
void fromMapsSessionId() {
15+
GetUserHikingRecordResponse response = GetUserHikingRecordResponse.from(projection());
16+
17+
assertThat(response.hikingRecordId()).isEqualTo(1L);
18+
assertThat(response.sessionId()).isEqualTo(10L);
19+
assertThat(response.hikedAt()).isEqualTo(LocalDate.of(2026, 5, 28));
20+
}
21+
22+
private UserHikingRecordProjection projection() {
23+
return new UserHikingRecordProjection() {
24+
@Override
25+
public Long getHikingRecordId() {
26+
return 1L;
27+
}
28+
29+
@Override
30+
public Long getSessionId() {
31+
return 10L;
32+
}
33+
34+
@Override
35+
public Long getMountainId() {
36+
return 2L;
37+
}
38+
39+
@Override
40+
public String getMountainName() {
41+
return "관악산";
42+
}
43+
44+
@Override
45+
public Long getCourseId() {
46+
return 3L;
47+
}
48+
49+
@Override
50+
public String getCourseName() {
51+
return "연주대 코스";
52+
}
53+
54+
@Override
55+
public String getPhotoReportImageUrl() {
56+
return "photo-report";
57+
}
58+
59+
@Override
60+
public String getCliveImageUrl() {
61+
return "clive";
62+
}
63+
64+
@Override
65+
public Double getDistance() {
66+
return 6200.0;
67+
}
68+
69+
@Override
70+
public Integer getDuration() {
71+
return 3600;
72+
}
73+
74+
@Override
75+
public LocalDateTime getHikedAt() {
76+
return LocalDateTime.of(2026, 5, 28, 10, 0);
77+
}
78+
};
79+
}
80+
}

0 commit comments

Comments
 (0)