|
| 1 | +package com.amido.stacks.workloads.menu.api.v1; |
| 2 | + |
| 3 | +import static org.springframework.http.HttpStatus.OK; |
| 4 | + |
| 5 | +import com.amido.stacks.core.api.annotations.CreateAPIResponses; |
| 6 | +import com.amido.stacks.core.api.annotations.DeleteAPIResponses; |
| 7 | +import com.amido.stacks.core.api.annotations.UpdateAPIResponses; |
| 8 | +import com.amido.stacks.core.api.dto.response.ResourceCreatedResponse; |
| 9 | +import com.amido.stacks.core.api.dto.response.ResourceUpdatedResponse; |
| 10 | +import com.amido.stacks.workloads.menu.api.v1.dto.request.CreateCategoryRequest; |
| 11 | +import com.amido.stacks.workloads.menu.api.v1.dto.request.UpdateCategoryRequest; |
| 12 | +import io.swagger.v3.oas.annotations.Operation; |
| 13 | +import io.swagger.v3.oas.annotations.Parameter; |
| 14 | +import java.util.UUID; |
| 15 | +import javax.validation.Valid; |
| 16 | +import org.springframework.http.HttpStatus; |
| 17 | +import org.springframework.http.MediaType; |
| 18 | +import org.springframework.http.ResponseEntity; |
| 19 | +import org.springframework.web.bind.annotation.DeleteMapping; |
| 20 | +import org.springframework.web.bind.annotation.PathVariable; |
| 21 | +import org.springframework.web.bind.annotation.PostMapping; |
| 22 | +import org.springframework.web.bind.annotation.PutMapping; |
| 23 | +import org.springframework.web.bind.annotation.RequestAttribute; |
| 24 | +import org.springframework.web.bind.annotation.RequestBody; |
| 25 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 26 | +import org.springframework.web.bind.annotation.RestController; |
| 27 | + |
| 28 | +@RequestMapping( |
| 29 | + path = "/v1/menu/{id}/category", |
| 30 | + produces = MediaType.APPLICATION_JSON_VALUE + "; charset=utf-8") |
| 31 | +@RestController |
| 32 | +public class CategoryController { |
| 33 | + |
| 34 | + @PostMapping |
| 35 | + @Operation( |
| 36 | + tags = "Category", |
| 37 | + summary = "Create a category in the menu", |
| 38 | + description = "Adds a category to menu", |
| 39 | + operationId = "AddMenuCategory") |
| 40 | + @CreateAPIResponses |
| 41 | + ResponseEntity<ResourceCreatedResponse> addMenuCategory( |
| 42 | + @Parameter(description = "Menu id", required = true) @PathVariable("id") UUID menuId, |
| 43 | + @Valid @RequestBody CreateCategoryRequest body, |
| 44 | + @Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) { |
| 45 | + |
| 46 | + return new ResponseEntity<>(new ResourceCreatedResponse(UUID.randomUUID()), HttpStatus.CREATED); |
| 47 | + } |
| 48 | + |
| 49 | + @PutMapping("/{categoryId}") |
| 50 | + @Operation( |
| 51 | + tags = "Category", |
| 52 | + summary = "Update a category in the menu", |
| 53 | + description = "Update a category to menu", |
| 54 | + operationId = "UpdateMenuCategory") |
| 55 | + @UpdateAPIResponses |
| 56 | + ResponseEntity<ResourceUpdatedResponse> updateMenuCategory( |
| 57 | + @Parameter(description = "Menu id", required = true) @PathVariable("id") UUID menuId, |
| 58 | + @Parameter(description = "Category id", required = true) @PathVariable("categoryId") |
| 59 | + UUID categoryId, |
| 60 | + @Valid @RequestBody UpdateCategoryRequest body, |
| 61 | + @Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) { |
| 62 | + |
| 63 | + return new ResponseEntity<>(new ResourceUpdatedResponse(UUID.randomUUID()), OK); |
| 64 | + } |
| 65 | + |
| 66 | + @DeleteMapping("/{categoryId}") |
| 67 | + @Operation( |
| 68 | + tags = "Category", |
| 69 | + summary = "Removes a category and its items from menu", |
| 70 | + description = "Removes a category and its items from menu", |
| 71 | + operationId = "DeleteCategory") |
| 72 | + @DeleteAPIResponses |
| 73 | + ResponseEntity<Void> deleteCategory( |
| 74 | + @Parameter(description = "Menu id", required = true) @PathVariable("id") UUID menuId, |
| 75 | + @Parameter(description = "Category id", required = true) @PathVariable("categoryId") |
| 76 | + UUID categoryId, |
| 77 | + @Parameter(hidden = true) @RequestAttribute("CorrelationId") String correlationId) { |
| 78 | + |
| 79 | + return new ResponseEntity<>(OK); |
| 80 | + } |
| 81 | +} |
0 commit comments