Projekt

Obecné

Profil

Stáhnout (2.54 KB) Statistiky
| Větev: | Tag: | Revize:
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
     * Creates new or updates catalog item
27
     *
28
     * @param catalogItemDto catalog item DTO
29
     */
30
    @PostMapping("")
31
    @Operation(summary = "creates new or updates catalog item")
32
    public void saveCatalogItem(@RequestBody CatalogItemDto catalogItemDto) {
33
        catalogService.saveCatalogItem(catalogItemDto);
34
    }
35

    
36
    /**
37
     * Saves list of catalog items
38
     *
39
     * @param catalogItemDtoList list of catalog items DTO
40
     */
41
    @PostMapping("/batch")
42
    @Operation(summary = "saves list of catalog items")
43
    public void saveCatalogItems(@RequestBody List<CatalogItemDto> catalogItemDtoList) {
44
        catalogService.saveCatalogItems(catalogItemDtoList);
45
    }
46

    
47
    /**
48
     * Returns catalog items satisfying given filter
49
     *
50
     * @param name    name - optional
51
     * @param country country - optional
52
     * @param type    type - optional
53
     * @return list of catalog items satisfying given filter
54
     */
55
    @GetMapping("")
56
    @Operation(summary = "returns catalog items based on filter")
57
    public ResponseEntity<List<CatalogItemDto>> getCatalog(@RequestParam(defaultValue = "") String name, @RequestParam(defaultValue = "") String country, @RequestParam(defaultValue = "") String type, @RequestParam(defaultValue = "") String writtenForm) {
58
        return new ResponseEntity<>(catalogService.getCatalog(name, country, type, writtenForm), HttpStatus.OK);
59
    }
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
}
(1-1/6)