Skip to content

Commit 93290f7

Browse files
authored
Merge pull request #63 from swyp-app-team-4/feat#62-implement-member-place-detail
[Feat] 사용자 장소 상세 API 구현 및 무한 스크롤 적용
2 parents bcc76a8 + 4a8fc6e commit 93290f7

15 files changed

Lines changed: 454 additions & 152 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ out/
4040
src/main/resources/*.sql
4141

4242
### application-dev ###
43-
src/main/resources/application-dev.yml
43+
src/main/resources/application-dev.yml
44+
45+
### env ###
46+
/env
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package boombimapi.domain.congestion.dto.response;
2+
3+
import boombimapi.domain.congestion.entity.MemberCongestion;
4+
import java.time.LocalDateTime;
5+
6+
public record MemberCongestionItemResponse(
7+
Long memberCongestionId,
8+
String congestionLevelName,
9+
String congestionLevelMessage,
10+
LocalDateTime createdAt
11+
) {
12+
13+
public static MemberCongestionItemResponse of(
14+
MemberCongestion memberCongestion
15+
) {
16+
return new MemberCongestionItemResponse(
17+
memberCongestion.getId(),
18+
memberCongestion.getCongestionLevel().getName(),
19+
memberCongestion.getCongestionMessage(),
20+
memberCongestion.getCreatedAt()
21+
);
22+
}
23+
24+
}

src/main/java/boombimapi/domain/congestion/repository/MemberCongestionRepository.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.Optional;
66

77
import feign.Param;
8+
import org.springframework.data.domain.Pageable;
9+
import org.springframework.data.domain.Slice;
810
import org.springframework.data.jpa.repository.JpaRepository;
911
import org.springframework.data.jpa.repository.Query;
1012

@@ -21,11 +23,22 @@ Optional<MemberCongestion> findFirstByMemberPlaceIdAndExpiresAtAfterOrderByCreat
2123
);
2224

2325
@Query("""
24-
SELECT COUNT(mc)
25-
FROM MemberCongestion mc
26-
WHERE mc.memberPlace.id = :placeId
27-
AND CAST(mc.createdAt AS DATE) = CURRENT_DATE
28-
""")
26+
SELECT COUNT(mc)
27+
FROM MemberCongestion mc
28+
WHERE mc.memberPlace.id = :placeId
29+
AND CAST(mc.createdAt AS DATE) = CURRENT_DATE
30+
""")
2931
long countTodayByPlace(@Param("placeId") Long placeId);
3032

33+
Slice<MemberCongestion> findByMemberPlaceIdOrderByIdDesc(
34+
Long memberPlaceId,
35+
Pageable pageable
36+
);
37+
38+
Slice<MemberCongestion> findByMemberPlaceIdAndIdLessThanOrderByIdDesc(
39+
Long memberPlaceId,
40+
Long cursor,
41+
Pageable pageable
42+
);
43+
3144
}

src/main/java/boombimapi/domain/place/api/MemberPlaceController.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,27 @@
55
import boombimapi.domain.place.application.MemberPlaceService;
66
import boombimapi.domain.place.dto.request.ResolveMemberPlaceRequest;
77
import boombimapi.domain.place.dto.request.ViewportRequest;
8-
import boombimapi.domain.place.dto.response.ResolveMemberPlaceResponse;
8+
import boombimapi.domain.place.dto.response.member.GetMemberPlaceDetailResponse;
9+
import boombimapi.domain.place.dto.response.member.ResolveMemberPlaceResponse;
910
import boombimapi.domain.place.dto.response.node.ViewportNodeResponse;
1011
import boombimapi.global.response.BaseResponse;
1112
import io.swagger.v3.oas.annotations.Operation;
1213
import io.swagger.v3.oas.annotations.responses.ApiResponse;
1314
import io.swagger.v3.oas.annotations.responses.ApiResponses;
1415
import io.swagger.v3.oas.annotations.tags.Tag;
16+
import jakarta.validation.constraints.Max;
17+
import jakarta.validation.constraints.Min;
1518
import java.util.List;
1619
import lombok.RequiredArgsConstructor;
1720
import org.springframework.http.HttpStatus;
1821
import org.springframework.http.ResponseEntity;
22+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
23+
import org.springframework.web.bind.annotation.GetMapping;
24+
import org.springframework.web.bind.annotation.PathVariable;
1925
import org.springframework.web.bind.annotation.PostMapping;
2026
import org.springframework.web.bind.annotation.RequestBody;
2127
import org.springframework.web.bind.annotation.RequestMapping;
28+
import org.springframework.web.bind.annotation.RequestParam;
2229
import org.springframework.web.bind.annotation.RestController;
2330

2431
@RestController
@@ -52,15 +59,45 @@ public ResponseEntity<BaseResponse<ResolveMemberPlaceResponse>> resolveMemberPla
5259
})
5360
@PostMapping
5461
public ResponseEntity<BaseResponse<List<ViewportNodeResponse>>> getMemberPlacesInViewport(
62+
@AuthenticationPrincipal String memberId,
5563
@RequestBody ViewportRequest request
5664
) {
5765
return ResponseEntity.ok(
5866
BaseResponse.of(
5967
HttpStatus.OK,
6068
GET_MEMBER_PLACES_IN_VIEWPORT_SUCCESS,
61-
memberPlaceService.getViewportNodes(request)
69+
memberPlaceService.getViewportNodes(memberId, request)
6270
)
6371
);
6472
}
6573

74+
@Operation(summary = "특정 사용자 장소 상세 조회", description = "특정 사용자 장소를 상세 조회하여 해당 장소에 작성된 혼잡도들을 확인합니다.")
75+
@ApiResponses(value = {
76+
@ApiResponse(responseCode = "200", description = "특정 사용자 장소 상세 조회 성공")
77+
})
78+
@GetMapping("/{memberPlaceId}")
79+
public ResponseEntity<BaseResponse<GetMemberPlaceDetailResponse>> getMemberPlaceDetail(
80+
@PathVariable Long memberPlaceId,
81+
@RequestParam(required = false) @Min(1) @Max(100) Integer size,
82+
@RequestParam(required = false) Long cursor,
83+
@AuthenticationPrincipal String memberId
84+
) {
85+
86+
GetMemberPlaceDetailResponse memberPlaceDetailResponse = memberPlaceService.getMemberPlaceDetail(
87+
memberId,
88+
memberPlaceId,
89+
size,
90+
cursor
91+
);
92+
93+
return ResponseEntity.ok(
94+
BaseResponse.of(
95+
HttpStatus.OK,
96+
GET_MEMBER_PLACE_DETAIL_SUCCESS,
97+
memberPlaceDetailResponse
98+
)
99+
);
100+
101+
}
102+
66103
}

0 commit comments

Comments
 (0)