-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 메뉴 카테고리 목록 조회 #153
Merged
Merged
feat: 메뉴 카테고리 목록 조회 #153
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/in/koreatech/koin/domain/shop/dto/MenuCategoriesResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package in.koreatech.koin.domain.shop.dto; | ||
|
||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
import in.koreatech.koin.domain.shop.model.MenuCategory; | ||
|
||
@JsonNaming(value = SnakeCaseStrategy.class) | ||
public record MenuCategoriesResponse(Long count, List<MenuCategoryResponse> menuCategories) { | ||
public static MenuCategoriesResponse from(List<MenuCategory> menuCategories) { | ||
List<MenuCategoryResponse> categories = menuCategories.stream() | ||
.map(menuCategory -> MenuCategoryResponse.of(menuCategory.getId(), menuCategory.getName())) | ||
.toList(); | ||
|
||
return new MenuCategoriesResponse((long)categories.size(), categories); | ||
} | ||
|
||
private record MenuCategoryResponse(Long id, String name) { | ||
public static MenuCategoryResponse of(Long id, String name) { | ||
return new MenuCategoryResponse(id, name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/in/koreatech/koin/domain/shop/repository/MenuCategoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package in.koreatech.koin.domain.shop.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.repository.Repository; | ||
|
||
import in.koreatech.koin.domain.shop.model.MenuCategory; | ||
|
||
public interface MenuCategoryRepository extends Repository<MenuCategory, Long> { | ||
List<MenuCategory> findAllByShopId(Long shopId); | ||
|
||
MenuCategory save(MenuCategory menuCategory); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import in.koreatech.koin.domain.shop.model.MenuCategoryMap; | ||
import in.koreatech.koin.domain.shop.model.MenuImage; | ||
import in.koreatech.koin.domain.shop.model.MenuOption; | ||
import in.koreatech.koin.domain.shop.repository.MenuCategoryRepository; | ||
import in.koreatech.koin.domain.shop.repository.MenuRepository; | ||
import io.restassured.RestAssured; | ||
import io.restassured.response.ExtractableResponse; | ||
|
@@ -22,6 +23,9 @@ class ShopApiTest extends AcceptanceTest { | |
@Autowired | ||
private MenuRepository menuRepository; | ||
|
||
@Autowired | ||
private MenuCategoryRepository menuCategoryRepository; | ||
|
||
@Test | ||
@DisplayName("옵션이 하나 있는 상점의 메뉴를 조회한다.") | ||
void findMenuSingleOption() { | ||
|
@@ -54,6 +58,7 @@ void findMenuSingleOption() { | |
|
||
menuCategoryMap.map(menu, menuCategory); | ||
|
||
menuCategoryRepository.save(menuCategory); | ||
menuRepository.save(menu); | ||
|
||
ExtractableResponse<Response> response = RestAssured | ||
|
@@ -133,6 +138,7 @@ void findMenuMultipleOption() { | |
|
||
menuCategoryMap.map(menu, menuCategory); | ||
|
||
menuCategoryRepository.save(menuCategory); | ||
menuRepository.save(menu); | ||
|
||
ExtractableResponse<Response> response = RestAssured | ||
|
@@ -177,4 +183,68 @@ void findMenuMultipleOption() { | |
} | ||
); | ||
} | ||
|
||
@Test | ||
@DisplayName("상점의 메뉴 카테고리들을 조회한다.") | ||
void findShopMenuCategories() { | ||
// given | ||
final long SHOP_ID = 1L; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A실제로 Shop Entity를 하나 save() 하고 그 ID를 활용하는건 어떨까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 상점 객체는 아직 안만들기도 했고, 일부로 의존하지 않도록 의존관계가 아니라 id만 유지하도록 해서 필요하지 않을 것 같습니다! |
||
|
||
Menu menu = Menu.builder() | ||
.shopId(SHOP_ID) | ||
.name("짜장면") | ||
.description("맛있는 짜장면") | ||
.build(); | ||
|
||
MenuCategory menuCategory1 = MenuCategory.builder() | ||
.shopId(SHOP_ID) | ||
.name("이벤트 메뉴") | ||
.build(); | ||
|
||
MenuCategory menuCategory2 = MenuCategory.builder() | ||
.shopId(SHOP_ID) | ||
.name("메인 메뉴") | ||
.build(); | ||
|
||
MenuCategoryMap menuCategoryMap1 = MenuCategoryMap.create(); | ||
MenuCategoryMap menuCategoryMap2 = MenuCategoryMap.create(); | ||
|
||
// when then | ||
menuCategoryMap1.map(menu, menuCategory1); | ||
menuCategoryMap2.map(menu, menuCategory2); | ||
|
||
menuCategoryRepository.save(menuCategory1); | ||
menuCategoryRepository.save(menuCategory2); | ||
menuRepository.save(menu); | ||
|
||
ExtractableResponse<Response> response = RestAssured | ||
.given() | ||
.log().all() | ||
.when() | ||
.log().all() | ||
.get("/shops/{shopId}/menus/categories", menu.getShopId()) | ||
.then() | ||
.log().all() | ||
.statusCode(HttpStatus.OK.value()) | ||
.extract(); | ||
|
||
SoftAssertions.assertSoftly( | ||
softly -> { | ||
softly.assertThat(response.body().jsonPath().getLong("count")).isEqualTo(2); | ||
|
||
softly.assertThat(response.body().jsonPath().getList("menu_categories")) | ||
.hasSize(2); | ||
|
||
softly.assertThat(response.body().jsonPath().getLong("menu_categories[0].id")) | ||
.isEqualTo(menuCategory1.getId()); | ||
softly.assertThat(response.body().jsonPath().getString("menu_categories[0].name")) | ||
.isEqualTo(menuCategory1.getName()); | ||
|
||
softly.assertThat(response.body().jsonPath().getLong("menu_categories[1].id")) | ||
.isEqualTo(menuCategory2.getId()); | ||
softly.assertThat(response.body().jsonPath().getString("menu_categories[1].name")) | ||
.isEqualTo(menuCategory2.getName()); | ||
} | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CasCade 옵션이 말썽이군요 😅
상점과 메뉴 카테고리는 같은 생명주기를 가지지 않는다고 생각해요
해당 상황에서는 cascade 옵션을 제거해줘도 문제없다고 생각합니다.
해당 의견에 동의합니다~
이렇게되면 shopMenuCategoryMap은 사용하지 않게 되려나요?
shop_menu_category_map 상의 연결 컬럼이 nullable하게 구성되어야할거 같네요? 제가 맞게 이해한걸까요~?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는
~~map
테이블은 N:M 관계를 매핑하기 위한 중간 테이블 목적으로 설계해서 필요하다고 생각합니다~