Coverage Summary for Class: CategoryController (com.app.SuperMarketSystem.controller)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| CategoryController | 100% (1/1) | 14.3% (1/7) | 25% (2/8) |
1 package com.app.SuperMarketSystem.controller; 2 3 import com.app.SuperMarketSystem.dto.ApiResponse; 4 import com.app.SuperMarketSystem.model.Category; 5 import com.app.SuperMarketSystem.model.Product; 6 import com.app.SuperMarketSystem.service.CategoryService; 7 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.web.bind.annotation.*; 9 10 import java.util.List; 11 12 @RestController 13 @RequestMapping("/category") 14 public class CategoryController { 15 private final CategoryService categoryService; 16 17 @Autowired 18 public CategoryController(CategoryService categoryService) { 19 this.categoryService = categoryService; 20 } 21 22 @GetMapping("/list") 23 public ApiResponse list() { 24 return categoryService.findAllCategories(); 25 } 26 27 @PostMapping("/save") 28 public ApiResponse save(@RequestBody Category category) { 29 return categoryService.addCategory(category); 30 } 31 32 @PutMapping("/update") 33 public ApiResponse update(@RequestBody Category category) { 34 return categoryService.updateCategory(category); 35 } 36 37 @DeleteMapping("/delete/{id}") 38 public ApiResponse delete(@PathVariable(name = "id") String categoryId) { 39 return categoryService.deleteCategory(categoryId); 40 } 41 42 @GetMapping("/getBy/{id}") 43 public ApiResponse getById(@PathVariable(name = "id") String categoryId) { 44 return categoryService.getCategoryById(categoryId); 45 } 46 47 @PostMapping("/addProducts") 48 public ApiResponse addProducts(@RequestParam(name = "categoryId") String categoryId, @RequestBody List<Product> productList) { 49 return categoryService.addProductsInCategory(categoryId, productList); 50 } 51 }