Projekt

Obecné

Profil

Stáhnout (1.88 KB) Statistiky
| Větev: | Tag: | Revize:
1
package cz.zcu.kiv.backendapi.catalog;
2

    
3
import lombok.RequiredArgsConstructor;
4
import org.springframework.http.HttpStatus;
5
import org.springframework.http.ResponseEntity;
6
import org.springframework.web.bind.annotation.*;
7

    
8
import java.util.List;
9
import java.util.UUID;
10

    
11
/**
12
 * Controller for catalog
13
 */
14
@RestController
15
@RequiredArgsConstructor
16
@RequestMapping("/catalog")
17
public class CatalogController {
18

    
19
    /**
20
     * Catalog service
21
     */
22
    private final ICatalogEntryService catalogService;
23

    
24
    /**
25
     * Saves new catalog entry
26
     *
27
     * @param catalogEntryDto catalog entry DTO
28
     */
29
    @PostMapping("")
30
    public void addCatalogEntry(@RequestBody CatalogEntryDto catalogEntryDto) {
31
        catalogService.saveCatalogEntry(catalogEntryDto);
32
    }
33

    
34
    /**
35
     * Returns catalog entries satisfying given filter
36
     *
37
     * @param name    name - optional
38
     * @param country country - optional
39
     * @param type    type - optional
40
     * @return list of catalog entries satisfying given filter
41
     */
42
    @GetMapping("")
43
    public ResponseEntity<List<CatalogEntryDto>> getCatalog(@RequestParam(defaultValue = "") String name, @RequestParam(defaultValue = "") String country, @RequestParam(defaultValue = "") String type) {
44
        return new ResponseEntity<>(catalogService.getCatalog(name, country, type), HttpStatus.OK);
45
    }
46

    
47
    /**
48
     * Updates catalog entry with given ID
49
     *
50
     * @param id              ID
51
     * @param catalogEntryDto catalog DTO
52
     */
53
    @PutMapping("/{id}")
54
    public void updateCatalogEntry(@PathVariable UUID id, @RequestBody CatalogEntryDto catalogEntryDto) {
55
        catalogService.updateCatalogEntry(id, catalogEntryDto);
56
    }
57

    
58
    /**
59
     * Deletes catalog entry with given ID
60
     *
61
     * @param id ID
62
     */
63
    @DeleteMapping("/{id}")
64
    public void deleteCatalogEntry(@PathVariable UUID id) {
65
        catalogService.deleteCatalogEntry(id);
66
    }
67
}
(1-1/6)