-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from Team-Hankki/develop
[feat] 메뉴편집, 둘러보기 추가
- Loading branch information
Showing
20 changed files
with
255 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,7 @@ Temporary Items | |
|
||
application-local.yml | ||
application-dev.yml | ||
application-prod.yml | ||
|
||
# Qclass | ||
/src/main/generated |
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 |
---|---|---|
|
@@ -89,4 +89,4 @@ tasks.register('copyYml', Copy) { | |
include "*.yml" | ||
into 'src/main/resources' | ||
} | ||
} | ||
} |
Submodule server-yml
updated
from 2002c8 to 763eb8
45 changes: 45 additions & 0 deletions
45
src/main/java/org/hankki/hankkiserver/api/menu/controller/MenuController.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,45 @@ | ||
package org.hankki.hankkiserver.api.menu.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.hankki.hankkiserver.api.dto.HankkiResponse; | ||
import org.hankki.hankkiserver.api.menu.service.MenuCommandService; | ||
import org.hankki.hankkiserver.api.menu.service.command.MenuDeleteCommand; | ||
import org.hankki.hankkiserver.api.menu.service.command.MenuPatchCommand; | ||
import org.hankki.hankkiserver.api.menu.service.command.MenuPostCommand; | ||
import org.hankki.hankkiserver.api.menu.service.command.MenusPostCommand; | ||
import org.hankki.hankkiserver.api.menu.service.response.MenusPostResponse; | ||
import org.hankki.hankkiserver.api.store.controller.request.MenuPostRequest; | ||
import org.hankki.hankkiserver.common.code.CommonSuccessCode; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
public class MenuController { | ||
|
||
private final MenuCommandService menuCommandService; | ||
|
||
@DeleteMapping("/{storeId}/menus/{id}") | ||
public HankkiResponse<Void> deleteMenu(@PathVariable("storeId") final Long storeId, @PathVariable("id") final Long id) { | ||
menuCommandService.deleteMenu(MenuDeleteCommand.of(storeId, id)); | ||
return HankkiResponse.success(CommonSuccessCode.NO_CONTENT); | ||
} | ||
|
||
@PatchMapping("/{storeId}/menus/{id}") | ||
public HankkiResponse<Void> updateMenu(@PathVariable("storeId") final Long storeId, @PathVariable("id") final Long id, | ||
@Valid @RequestBody final MenuPostRequest request) { | ||
menuCommandService.modifyMenu(MenuPatchCommand.of(storeId, id, request.name(), request.price())); | ||
return HankkiResponse.success(CommonSuccessCode.OK); | ||
} | ||
|
||
@PostMapping("{storeId}/menus/bulk") | ||
public HankkiResponse<MenusPostResponse> createMenu(@PathVariable final Long storeId, @Valid @RequestBody final List<MenuPostRequest> request) { | ||
List<MenuPostCommand> command = request.stream() | ||
.map(r -> MenuPostCommand.of(r.name(), r.price())) | ||
.toList(); | ||
return HankkiResponse.success(CommonSuccessCode.CREATED, menuCommandService.createMenus(MenusPostCommand.of(storeId, command))); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/org/hankki/hankkiserver/api/menu/service/MenuCommandService.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,58 @@ | ||
package org.hankki.hankkiserver.api.menu.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.hankki.hankkiserver.api.menu.service.command.MenuDeleteCommand; | ||
import org.hankki.hankkiserver.api.menu.service.command.MenuPatchCommand; | ||
import org.hankki.hankkiserver.api.menu.service.command.MenusPostCommand; | ||
import org.hankki.hankkiserver.api.menu.service.response.MenusPostResponse; | ||
import org.hankki.hankkiserver.api.store.service.StoreFinder; | ||
import org.hankki.hankkiserver.domain.menu.model.Menu; | ||
import org.hankki.hankkiserver.domain.store.model.Store; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MenuCommandService { | ||
|
||
private final MenuDeleter menuDeleter; | ||
private final MenuFinder menuFinder; | ||
private final MenuUpdater menuUpdater; | ||
private final StoreFinder storeFinder; | ||
|
||
@Transactional | ||
public void deleteMenu(final MenuDeleteCommand command) { | ||
Menu menu = menuFinder.findByStoreIdAndId(command.storeId(), command.id()); | ||
menuDeleter.deleteMenu(menu); | ||
updateLowestPriceInStore(storeFinder.findByIdWhereDeletedIsFalse(command.storeId())); | ||
} | ||
|
||
@Transactional | ||
public void modifyMenu(final MenuPatchCommand command) { | ||
Menu menu = menuFinder.findByStoreIdAndId(command.storeId(), command.id()); | ||
menu.update(command.name(), command.price()); | ||
updateLowestPriceInStore(storeFinder.findByIdWhereDeletedIsFalse(command.storeId())); | ||
} | ||
|
||
@Transactional | ||
public MenusPostResponse createMenus(final MenusPostCommand command) { | ||
Store findStore = storeFinder.findByIdWhereDeletedIsFalse(command.storeId()); | ||
List<Menu> menus = command.menu().stream() | ||
.filter(c -> !validateMenuConflict(findStore, c.name())) | ||
.map(c -> Menu.create(findStore, c.name(), c.price())) | ||
.toList(); | ||
menuUpdater.saveAll(menus); | ||
updateLowestPriceInStore(findStore); | ||
return MenusPostResponse.of(menus); | ||
} | ||
|
||
private void updateLowestPriceInStore(final Store findStore) { | ||
findStore.updateLowestPrice(menuFinder.findLowestPriceByStore(findStore)); | ||
} | ||
|
||
private boolean validateMenuConflict(Store store, String menuName) { | ||
return menuFinder.existsByStoreAndName(store, menuName); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/hankki/hankkiserver/api/menu/service/MenuDeleter.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,17 @@ | ||
package org.hankki.hankkiserver.api.menu.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.hankki.hankkiserver.domain.menu.model.Menu; | ||
import org.hankki.hankkiserver.domain.menu.repository.MenuRepository; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class MenuDeleter { | ||
|
||
private final MenuRepository menuRepository; | ||
|
||
protected void deleteMenu(final Menu menu) { | ||
menuRepository.delete(menu); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/main/java/org/hankki/hankkiserver/api/menu/service/command/MenuDeleteCommand.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,10 @@ | ||
package org.hankki.hankkiserver.api.menu.service.command; | ||
|
||
public record MenuDeleteCommand( | ||
long storeId, | ||
long id | ||
) { | ||
public static MenuDeleteCommand of(long storeId, long id) { | ||
return new MenuDeleteCommand(storeId, id); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/hankki/hankkiserver/api/menu/service/command/MenuPatchCommand.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,12 @@ | ||
package org.hankki.hankkiserver.api.menu.service.command; | ||
|
||
public record MenuPatchCommand( | ||
long storeId, | ||
long id, | ||
String name, | ||
int price | ||
) { | ||
public static MenuPatchCommand of(final long storeId, final long id, final String name, final int price) { | ||
return new MenuPatchCommand(storeId, id, name, price); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/hankki/hankkiserver/api/menu/service/command/MenuPostCommand.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,10 @@ | ||
package org.hankki.hankkiserver.api.menu.service.command; | ||
|
||
public record MenuPostCommand( | ||
String name, | ||
int price | ||
) { | ||
public static MenuPostCommand of(final String name, final int price) { | ||
return new MenuPostCommand(name, price); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/hankki/hankkiserver/api/menu/service/command/MenusPostCommand.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,12 @@ | ||
package org.hankki.hankkiserver.api.menu.service.command; | ||
|
||
import java.util.List; | ||
|
||
public record MenusPostCommand ( | ||
long storeId, | ||
List<MenuPostCommand> menu | ||
){ | ||
public static MenusPostCommand of (final long storeId, final List<MenuPostCommand> menu) { | ||
return new MenusPostCommand(storeId, menu); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/hankki/hankkiserver/api/menu/service/response/MenuPostResponse.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,14 @@ | ||
package org.hankki.hankkiserver.api.menu.service.response; | ||
|
||
import org.hankki.hankkiserver.domain.menu.model.Menu; | ||
|
||
public record MenuPostResponse ( | ||
long id, | ||
String name, | ||
int price | ||
) { | ||
|
||
public static MenuPostResponse of(final Menu menu) { | ||
return new MenuPostResponse(menu.getId(), menu.getName(), menu.getPrice()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/hankki/hankkiserver/api/menu/service/response/MenusPostResponse.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,16 @@ | ||
package org.hankki.hankkiserver.api.menu.service.response; | ||
|
||
import org.hankki.hankkiserver.domain.menu.model.Menu; | ||
|
||
import java.util.List; | ||
|
||
public record MenusPostResponse( | ||
List<MenuPostResponse> menuList | ||
) { | ||
public static MenusPostResponse of(List<Menu> menus) { | ||
List<MenuPostResponse> menuResponses = menus.stream() | ||
.map(MenuPostResponse::of) | ||
.toList(); | ||
return new MenusPostResponse(menuResponses); | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/java/org/hankki/hankkiserver/common/code/MenuErrorCode.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,16 @@ | ||
package org.hankki.hankkiserver.common.code; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum MenuErrorCode implements ErrorCode { | ||
|
||
MENU_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 메뉴입니다."), | ||
ALREADY_EXISTED_MENU(HttpStatus.CONFLICT, "이미 존재하는 메뉴입니다."); | ||
|
||
private final HttpStatus httpStatus; | ||
private final String message; | ||
} |
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
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