-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuController.java
More file actions
101 lines (88 loc) · 3.79 KB
/
MenuController.java
File metadata and controls
101 lines (88 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package me.barion.capstoneprojectbarion.controller;
import me.barion.capstoneprojectbarion.Entity.Menu;
import me.barion.capstoneprojectbarion.dto.MenuOptionRequestDto;
import me.barion.capstoneprojectbarion.dto.MenuOptionResponseDto;
import me.barion.capstoneprojectbarion.dto.MenuRequestDto;
import me.barion.capstoneprojectbarion.dto.MenuResponseDto;
import me.barion.capstoneprojectbarion.service.MenuOptionService;
import me.barion.capstoneprojectbarion.service.MenuService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
@RestController
@RequestMapping("/api/menus")
public class MenuController {
private final MenuService menuService;
private final MenuOptionService menuOptionService;
public MenuController(MenuService menuService, MenuOptionService menuOptionService) {
this.menuService = menuService;
this.menuOptionService = menuOptionService;
}
// 메뉴 생성 (base64 이미지 포함)
@PostMapping
public ResponseEntity<MenuResponseDto> createMenu(@RequestBody MenuRequestDto dto) throws IOException {
return ResponseEntity.ok(menuService.createMenu(dto));
}
// 모든 메뉴 조회
@GetMapping
public ResponseEntity<Page<MenuResponseDto>> getAllMenus(
@PageableDefault(size = 10) Pageable pageable,
@RequestParam(required = false) Integer category) {
if (category != null) {
return ResponseEntity.ok(menuService.getMenusByCategory(category, pageable));
}
return ResponseEntity.ok(menuService.getAllMenus(pageable));
}
// 특정 메뉴 조회
@GetMapping("/{menuId}")
public ResponseEntity<MenuResponseDto> getMenu(@PathVariable Long menuId) {
return ResponseEntity.ok(menuService.getMenu(menuId));
}
// 메뉴 수정
@PutMapping("/{menuId}")
public ResponseEntity<MenuResponseDto> updateMenu(
@PathVariable Long menuId,
@RequestBody MenuRequestDto dto) throws IOException {
return ResponseEntity.ok(menuService.updateMenu(menuId, dto));
}
// 메뉴 삭제
@DeleteMapping("/{menuId}")
public ResponseEntity<Void> deleteMenu(@PathVariable Long menuId) {
menuService.deleteMenu(menuId);
return ResponseEntity.noContent().build();
}
// 메뉴 옵션 생성 - 수정된 부분
@PostMapping("/{menuId}/options")
public ResponseEntity<MenuOptionResponseDto> createOption(
@PathVariable Long menuId,
@RequestBody MenuOptionRequestDto dto) {
dto.setMenuId(menuId);
return ResponseEntity.ok(menuOptionService.createOption(dto));
}
// 메뉴 옵션 조회 - 수정된 부분
@GetMapping("/{menuId}/options")
public ResponseEntity<List<MenuOptionResponseDto>> getMenuOptions(@PathVariable Long menuId) {
return ResponseEntity.ok(menuOptionService.getMenuOptions(menuId));
}
// 메뉴 옵션 수정 - 수정된 부분
@PutMapping("/{menuId}/options/{optionId}")
public ResponseEntity<MenuOptionResponseDto> updateOption(
@PathVariable Long menuId,
@PathVariable Long optionId,
@RequestBody MenuOptionRequestDto dto) {
dto.setMenuId(menuId);
return ResponseEntity.ok(menuOptionService.updateOption(optionId, dto));
}
// 메뉴 옵션 삭제
@DeleteMapping("/{menuId}/options/{optionId}")
public ResponseEntity<Void> deleteOption(
@PathVariable Long menuId,
@PathVariable Long optionId) {
menuOptionService.deleteOption(optionId);
return ResponseEntity.noContent().build();
}
}