Skip to content

Commit 6b6a6ad

Browse files
committed
[feat] 힐링장소 상세조회 api 구현
1 parent 8c4f966 commit 6b6a6ad

File tree

6 files changed

+61
-11
lines changed

6 files changed

+61
-11
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package com.sopkathon.domain.place.dto;
22

3+
import java.util.List;
4+
35
public record GetPlaceDetailRes(
46
Long placeId,
57
String name,
68
String address,
79
String recruitDate,
810
String startedAt,
911
String endAt,
10-
String duration,
12+
int duration,
1113
String description,
1214
String mapLink,
1315
String photoUrl,
1416
int price,
15-
ReviewListDto reviewList
17+
List<ReviewDto> reviewList
1618
) {
1719
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.sopkathon.domain.place.dto;
2+
3+
import com.sopkathon.domain.review.entity.ReviewEntity;
4+
5+
public record ReviewDto(
6+
String author,
7+
String date,
8+
String content,
9+
String profileImageUrl
10+
) {
11+
public static ReviewDto from(ReviewEntity entity) {
12+
return new ReviewDto(
13+
entity.getAuthor(),
14+
entity.getCreatedAt(),
15+
entity.getContent(),
16+
entity.getProfileImageUrl()
17+
);
18+
}
19+
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.sopkathon.domain.place.dto;
22

3-
import com.sopkathon.domain.place.entity.PlaceEntity;
43
import com.sopkathon.domain.review.entity.ReviewEntity;
54

65
import java.util.List;
76

87
public record ReviewListDto(
9-
List<ReviewEntity> reviewList
8+
List<ReviewEntity> reviews
109
) {
1110
public static ReviewListDto from(List<ReviewEntity> reviews) {
1211
return new ReviewListDto(reviews);
1312
}
14-
}
13+
}

src/main/java/com/sopkathon/domain/place/service/PlaceService.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import java.util.List;
44

5-
import com.sopkathon.domain.place.dto.GetPlaceDetailRes;
5+
import com.sopkathon.domain.place.dto.*;
6+
import com.sopkathon.domain.review.entity.ReviewEntity;
7+
import com.sopkathon.domain.review.repository.ReviewRepository;
8+
import com.sopkathon.global.error.code.ErrorCode;
9+
import com.sopkathon.global.error.exception.BusinessException;
610
import org.springframework.stereotype.Service;
711

8-
import com.sopkathon.domain.place.dto.GetPlaceListResponse;
9-
import com.sopkathon.domain.place.dto.GetPlaceResponse;
1012
import com.sopkathon.domain.place.entity.Category;
1113
import com.sopkathon.domain.place.entity.PlaceEntity;
1214
import com.sopkathon.domain.place.repository.PlaceRepository;
@@ -19,6 +21,7 @@
1921
@RequiredArgsConstructor
2022
public class PlaceService {
2123
private final PlaceRepository placeRepository;
24+
private final ReviewRepository reviewRepository;
2225
private final SubwayService SubwayService;
2326

2427
public GetPlaceListResponse getPlaceList(String category, String subway){
@@ -39,7 +42,29 @@ private List<PlaceEntity> getPlacesByCategory(SubwayEntity subwayEntity, String
3942
return placeRepository.findAllBySubwayEntityAndCategory(subwayEntity, Category.fromKorName(category));
4043
}
4144

42-
// public GetPlaceDetailRes getPlaceDetailById(Long placeId) {
43-
//
44-
// }
45+
public GetPlaceDetailRes getPlaceDetailById(Long placeId) {
46+
PlaceEntity place = placeRepository.findById(placeId)
47+
.orElseThrow(() -> new BusinessException(ErrorCode.PLACE_NOT_FOUND));
48+
49+
List<ReviewEntity> reviews = reviewRepository.findByPlaceEntity_Id(placeId);
50+
51+
List<ReviewDto> reviewDtos = reviews.stream()
52+
.map(ReviewDto::from)
53+
.toList();
54+
55+
return new GetPlaceDetailRes(
56+
place.getId(),
57+
place.getName(),
58+
place.getLocation(),
59+
place.getDate(),
60+
place.getStartedAt(),
61+
place.getEndAt(),
62+
place.getDuration(),
63+
place.getDescription(),
64+
place.getMapLink(),
65+
place.getPhotoUrl(),
66+
place.getPrice(),
67+
reviewDtos
68+
);
69+
}
4570
}

src/main/java/com/sopkathon/domain/review/repository/ReviewRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import org.springframework.data.jpa.repository.JpaRepository;
55
import org.springframework.stereotype.Repository;
66

7+
import java.util.List;
8+
79
@Repository
810
public interface ReviewRepository extends JpaRepository<ReviewEntity, Long> {
11+
List<ReviewEntity> findByPlaceEntity_Id(Long placeId);
912
}

src/main/java/com/sopkathon/global/error/code/ErrorCode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public enum ErrorCode {
4545
TOOL_NOT_FOUND(HttpStatus.NOT_FOUND, "E404005", "툴 존재하지 않습니다"),
4646
BOARD_NOT_FOUND(HttpStatus.NOT_FOUND, "E404006", "게시글이 존재하지 않습니다"),
4747
SCRAP_NOT_FOUND(HttpStatus.NOT_FOUND, "E404006", "스크랩이 존재하지 않습니다"),
48+
PLACE_NOT_FOUND(HttpStatus.NOT_FOUND, "E404007", "해당하는 id의 장소가 존재하지 않습니다."),
49+
4850
/* 409 CONFLICT */
4951
DUPLICATED_NICKNAME(HttpStatus.CONFLICT, "E409001", "닉네임 중복입니다"),
5052
DUPLICATED_EMAIL(HttpStatus.CONFLICT, "E409002", "이메일 중복입니다"),

0 commit comments

Comments
 (0)