1
|
package cz.zcu.kiv.backendapi.catalog;
|
2
|
|
3
|
import io.swagger.v3.oas.annotations.Operation;
|
4
|
import lombok.RequiredArgsConstructor;
|
5
|
import org.springframework.http.HttpStatus;
|
6
|
import org.springframework.http.ResponseEntity;
|
7
|
import org.springframework.web.bind.annotation.*;
|
8
|
|
9
|
import java.util.List;
|
10
|
import java.util.UUID;
|
11
|
|
12
|
/**
|
13
|
* Controller for catalog
|
14
|
*/
|
15
|
@RestController
|
16
|
@RequiredArgsConstructor
|
17
|
@RequestMapping("/catalog-items")
|
18
|
public class CatalogController {
|
19
|
|
20
|
/**
|
21
|
* Catalog service
|
22
|
*/
|
23
|
private final ICatalogItemService catalogService;
|
24
|
|
25
|
/**
|
26
|
* Saves new catalog item
|
27
|
*
|
28
|
* @param catalogItemDto catalog item DTO
|
29
|
*/
|
30
|
@PostMapping("")
|
31
|
@Operation(summary = "creates new catalog item")
|
32
|
public void addCatalogItem(@RequestBody CatalogItemDto catalogItemDto) {
|
33
|
catalogService.saveCatalogItem(catalogItemDto);
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* Returns catalog items satisfying given filter
|
38
|
*
|
39
|
* @param name name - optional
|
40
|
* @param country country - optional
|
41
|
* @param type type - optional
|
42
|
* @return list of catalog items satisfying given filter
|
43
|
*/
|
44
|
@GetMapping("")
|
45
|
@Operation(summary = "returns catalog items based on filter")
|
46
|
public ResponseEntity<List<CatalogItemDto>> getCatalog(@RequestParam(defaultValue = "") String name, @RequestParam(defaultValue = "") String country, @RequestParam(defaultValue = "") String type, @RequestParam(defaultValue = "") String writtenForm) {
|
47
|
return new ResponseEntity<>(catalogService.getCatalog(name, country, type, writtenForm), HttpStatus.OK);
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Updates catalog item with given ID
|
52
|
*
|
53
|
* @param id ID
|
54
|
* @param catalogItemDto catalog item DTO
|
55
|
*/
|
56
|
@PutMapping("/{id}")
|
57
|
@Operation(summary = "updates catalog item with given ID")
|
58
|
public void updateCatalogItem(@PathVariable UUID id, @RequestBody CatalogItemDto catalogItemDto) {
|
59
|
catalogService.updateCatalogItem(id, catalogItemDto);
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Deletes catalog item with given ID
|
64
|
*
|
65
|
* @param id ID
|
66
|
*/
|
67
|
@DeleteMapping("/{id}")
|
68
|
@Operation(summary = "deletes catalog item with given ID")
|
69
|
public void deleteCatalogItem(@PathVariable UUID id) {
|
70
|
catalogService.deleteCatalogItem(id);
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* Returns catalog item with given ID
|
75
|
*
|
76
|
* @param id ID
|
77
|
* @return catalog item with given ID
|
78
|
*/
|
79
|
@GetMapping(value = "/{id}")
|
80
|
@Operation(summary = "returns catalog item with given ID")
|
81
|
public CatalogItemDto getCatalogItem(@PathVariable UUID id) {
|
82
|
return catalogService.getCatalogItem(id);
|
83
|
}
|
84
|
}
|