Skip to content

Commit 89fad84

Browse files
committed
feat : 가게 상세 조회 API 구현
1 parent 023ed2d commit 89fad84

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed

src/main/java/eatda/controller/store/StoreController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import lombok.RequiredArgsConstructor;
88
import org.springframework.http.ResponseEntity;
99
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.PathVariable;
1011
import org.springframework.web.bind.annotation.RequestParam;
1112
import org.springframework.web.bind.annotation.RestController;
1213

@@ -21,6 +22,12 @@ public ResponseEntity<StoresResponse> getStores(@RequestParam @Min(1) @Max(50) i
2122
return ResponseEntity.ok(storeService.getStores(size));
2223
}
2324

25+
@GetMapping("/api/shops/{storeId}")
26+
public ResponseEntity<StoreResponse> getStore(@PathVariable long storeId) {
27+
StoreResponse response = storeService.getStore(storeId);
28+
return ResponseEntity.ok(response);
29+
}
30+
2431
@GetMapping("/api/shop/search")
2532
public ResponseEntity<StoreSearchResponses> searchStore(@RequestParam String query, LoginMember member) {
2633
StoreSearchResponses response = storeService.searchStores(query);

src/test/java/eatda/controller/store/StoreControllerTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,32 @@
1212

1313
class StoreControllerTest extends BaseControllerTest {
1414

15+
@Nested
16+
class GetStore {
17+
18+
@Test
19+
void 음식점_정보를_조회한다() {
20+
Member member = memberGenerator.generate("111");
21+
Store store = storeGenerator.generate("농민백암순대", "서울 강남구 대치동 896-33");
22+
cheerGenerator.generateCommon(member, store, "image-key");
23+
24+
StoreResponse response = given()
25+
.pathParam("storeId", store.getId())
26+
.when()
27+
.get("/api/shops/{storeId}")
28+
.then()
29+
.statusCode(200)
30+
.extract().as(StoreResponse.class);
31+
32+
assertAll(
33+
() -> assertThat(response.id()).isEqualTo(store.getId()),
34+
() -> assertThat(response.name()).isEqualTo(store.getName()),
35+
() -> assertThat(response.district()).isEqualTo("강남구"),
36+
() -> assertThat(response.neighborhood()).isEqualTo("대치동")
37+
);
38+
}
39+
}
40+
1541
@Nested
1642
class GetStores {
1743

src/test/java/eatda/document/store/StoreDocumentTest.java

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import static org.mockito.ArgumentMatchers.anyInt;
5+
import static org.mockito.ArgumentMatchers.anyLong;
56
import static org.mockito.ArgumentMatchers.anyString;
67
import static org.mockito.Mockito.doReturn;
78
import static org.mockito.Mockito.doThrow;
@@ -13,6 +14,7 @@
1314
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
1415

1516
import eatda.controller.store.StorePreviewResponse;
17+
import eatda.controller.store.StoreResponse;
1618
import eatda.controller.store.StoreSearchResponse;
1719
import eatda.controller.store.StoreSearchResponses;
1820
import eatda.controller.store.StoresResponse;
@@ -32,6 +34,64 @@
3234

3335
public class StoreDocumentTest extends BaseDocumentTest {
3436

37+
@Nested
38+
class GetStore {
39+
RestDocsRequest requestDocument = request()
40+
.tag(Tag.STORE_API)
41+
.summary("음식점 정보 조회")
42+
.pathParameter(
43+
parameterWithName("storeId").description("음식점 ID")
44+
);
45+
46+
RestDocsResponse responseDocument = response()
47+
.responseBodyField(
48+
fieldWithPath("id").type(NUMBER).description("음식점 ID"),
49+
fieldWithPath("kakaoId").type(STRING).description("카카오 음식점 ID"),
50+
fieldWithPath("name").type(STRING).description("음식점 이름"),
51+
fieldWithPath("district").type(STRING).description("음식점 주소 (구)"),
52+
fieldWithPath("neighborhood").type(STRING).description("음식점 주소 (동)"),
53+
fieldWithPath("category").type(STRING).description("음식점 카테고리"),
54+
fieldWithPath("placeUrl").type(STRING).description("음식점 카카오맵 URL")
55+
);
56+
57+
@Test
58+
void 음식점_정보를_조회() {
59+
StoreResponse response = new StoreResponse(1L, "17163273", "농민백암순대", "강남구", "대치동",
60+
"한식", "https://place.map.kakao.com/17163273");
61+
doReturn(response).when(storeService).getStore(anyLong());
62+
63+
long storeId = 1L;
64+
var document = document("store/get-store", 200)
65+
.request(requestDocument)
66+
.response(responseDocument)
67+
.build();
68+
69+
given(document)
70+
.contentType(ContentType.JSON)
71+
.pathParam("storeId", storeId)
72+
.when().get("/api/shops/{storeId}")
73+
.then().statusCode(200);
74+
}
75+
76+
@EnumSource(value = BusinessErrorCode.class, names = {"STORE_NOT_FOUND"})
77+
@ParameterizedTest
78+
void 음식점_정보_조회_실패(BusinessErrorCode errorCode) {
79+
doThrow(new BusinessException(errorCode)).when(storeService).getStore(anyLong());
80+
81+
long storeId = 1L;
82+
var document = document("store/get-store", errorCode)
83+
.request(requestDocument)
84+
.response(ERROR_RESPONSE)
85+
.build();
86+
87+
given(document)
88+
.contentType(ContentType.JSON)
89+
.pathParam("storeId", storeId)
90+
.when().get("/api/shops/{storeId}")
91+
.then().statusCode(errorCode.getStatus().value());
92+
}
93+
}
94+
3595
@Nested
3696
class GetStores {
3797

@@ -62,7 +122,7 @@ class GetStores {
62122
doReturn(response).when(storeService).getStores(anyInt());
63123

64124
int size = 2;
65-
var document = document("store/get", 200)
125+
var document = document("store/get-stores", 200)
66126
.request(requestDocument)
67127
.response(responseDocument)
68128
.build();
@@ -80,7 +140,7 @@ class GetStores {
80140
doThrow(new BusinessException(errorCode)).when(storeService).getStores(anyInt());
81141

82142
int size = 2;
83-
var document = document("store/get", errorCode)
143+
var document = document("store/get-stores", errorCode)
84144
.request(requestDocument)
85145
.response(ERROR_RESPONSE)
86146
.build();

0 commit comments

Comments
 (0)