Skip to content
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] 식당 Id로 메뉴 목록 불러오기 #218

Merged
merged 13 commits into from
Nov 13, 2024
Merged

[feat] 식당 Id로 메뉴 목록 불러오기 #218

merged 13 commits into from
Nov 13, 2024

Conversation

kgy1008
Copy link
Member

@kgy1008 kgy1008 commented Nov 12, 2024

Related Issue 📌

close #217

Description ✔️

  • 해당 식당에 존재하는 메뉴 목록 불러오는 API

To Reviewers

API 테스트 완료
image

public MenusGetResponse getMenus(final long storeId) {
Store findStore = storeFinder.findByIdWhereDeletedIsFalse(storeId);
List<Menu> findmenus = menuFinder.findAllByStore(findStore);
List<MenuGetResponse> menus = findmenus.stream()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entity -> DTO 변환로직이니 DTO에 있어도 되지 않을까 생각을 해봅니다.. 👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

옮기겠슴돠

@@ -42,4 +43,9 @@ public HankkiResponse<MenusPostResponse> createMenu(@PathVariable final Long sto
.toList();
return HankkiResponse.success(CommonSuccessCode.CREATED, menuCommandService.createMenus(MenusPostCommand.of(storeId, command)));
}

@GetMapping("{storeId}/menus")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 맨앞에 /를 생략하신 이유가 있으실까요? 제가 모르는 부분이 있나 싶어서 여쭤보아요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

까먹었어여

@Valid @RequestBody final List<MenuPostRequest> request) {
@PostMapping("/{storeId}/menus/bulk")
public HankkiResponse<MenusPostResponse> createMenu(@PathVariable @Min(value = 1L) final long storeId,
@Valid @RequestBody final List<MenuPostRequest> request) {
List<MenuPostCommand> command = request.stream()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 변환과정 자체도 dto에 있어도 될 것 같아여

List<MenuGetResponse> findmenus = menus.stream()
.map(MenuGetResponse::of)
.toList();
return new MenusGetResponse(findmenus);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

매개변수에 바로 안넣고 변수 따로 생성해서 넣는 이유가 궁금해여


import org.hankki.hankkiserver.domain.menu.model.Menu;

public record MenuGetResponse (
Copy link
Contributor

@PicturePark1101 PicturePark1101 Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 DTO는 지금 MenusGetResponse에서만 사용하고 있는 것 같은데 접근제어자 public말고 default로 해줘도 될 것 같슴둥

int price,
String name
){
public static MenuGetResponse of(final Menu menu) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얘도 default여도 될 것 같아유

Copy link
Member Author

@kgy1008 kgy1008 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

바뀐 부분 표시

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "deleted_menu")
public class DeletedMenu extends BaseCreatedAtEntity {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엔티티 새로 만든곳

Comment on lines 75 to 85
private void checkNoMenuInStore(final Store store, final long userId, final Menu menu) {
if (!menuFinder.existsByStoreId(store.getId())) {
storeUpdater.deleteStore(store.getId());
DeletedMenu deletedMenu = convertToDeletedMenu(menu, store.getId());
deletedMenuUpdater.save(deletedMenu);
publisher.publish(DeleteStoreEvent.of(store.getName(), userId));
}
}

private DeletedMenu convertToDeletedMenu(final Menu menu, final long storeId) {
return DeletedMenu.create(menu.getName(), menu.getPrice(), storeId);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 추가 된 곳 -> 메뉴 없을 때, 식당 삭제하고 삭제된 메뉴 deletedMenu 형태로 바꾼 후, 해당 테이블에 저장

@kgy1008 kgy1008 merged commit 963655d into develop Nov 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] 식당 Id로 메뉴 목록 불러오기
2 participants