Skip to content

Commit

Permalink
[feat] delete Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
kgy1008 committed Oct 1, 2024
1 parent c4d2fa6 commit 0653cc3
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ tasks.register('copyYml', Copy) {
include "*.yml"
into 'src/main/resources'
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.hankki.hankkiserver.api.menu.controller;

import lombok.RequiredArgsConstructor;
import org.hankki.hankkiserver.api.dto.HankkiResponse;
import org.hankki.hankkiserver.api.menu.service.MenuCommandService;
import org.hankki.hankkiserver.common.code.CommonSuccessCode;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1")
public class MenuController {

private final MenuCommandService menuCommandService;

@DeleteMapping("/menus/{id}")
public HankkiResponse<Void> deleteMenu(@PathVariable final Long id) {
menuCommandService.deleteMenu(id);
return HankkiResponse.success(CommonSuccessCode.NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.hankki.hankkiserver.api.menu.service;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class MenuCommandService {

private final MenuDeleter menuDeleter;
private final MenuFinder menuFinder;

@Transactional
public void deleteMenu(final long menuId) {
menuDeleter.deleteMenu(menuFinder.findById(menuId));
}
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.hankki.hankkiserver.api.menu.service;

import lombok.RequiredArgsConstructor;
import org.hankki.hankkiserver.common.code.MenuErrorCode;
import org.hankki.hankkiserver.common.exception.NotFoundException;
import org.hankki.hankkiserver.domain.menu.model.Menu;
import org.hankki.hankkiserver.domain.menu.repository.MenuRepository;
import org.hankki.hankkiserver.domain.store.model.Store;
Expand All @@ -17,4 +19,8 @@ public class MenuFinder {
public List<Menu> findAllByStore(final Store store) {
return menuRepository.findAllByStore(store);
}

protected Menu findById(final Long id) {
return menuRepository.findById(id).orElseThrow(() -> new NotFoundException(MenuErrorCode.MENU_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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, "존재하지 않는 메뉴입니다.");

private final HttpStatus httpStatus;
private final String message;
}

0 comments on commit 0653cc3

Please sign in to comment.