Projekt

Obecné

Profil

Stáhnout (2.85 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
     * 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) {
47

    
48
        List<CatalogItemDto> catalog = null;
49
        long start = System.currentTimeMillis();
50
        catalog = catalogService.getCatalog3(name, country, type);
51
        System.out.println(catalog.size());
52
        long time1 = System.currentTimeMillis() - start;
53
        start = System.currentTimeMillis();
54
        catalog = catalogService.getCatalog2(name, country, type);
55
        System.out.println(catalog.size());
56

    
57
        long time2 = System.currentTimeMillis() - start;
58
        start = System.currentTimeMillis();
59
        catalog = catalogService.getCatalog(name, country, type);
60
        System.out.println(catalog.size());
61

    
62
        long time3 = System.currentTimeMillis() - start;
63
        System.out.println(time1 + "\t" + time2 + "\t" + time3);
64
        return new ResponseEntity<>(catalog, HttpStatus.OK);
65
    }
66

    
67
    /**
68
     * Updates catalog item with given ID
69
     *
70
     * @param id             ID
71
     * @param catalogItemDto catalog item DTO
72
     */
73
    @PutMapping("/{id}")
74
    @Operation(summary = "updates catalog item with given ID")
75
    public void updateCatalogItem(@PathVariable UUID id, @RequestBody CatalogItemDto catalogItemDto) {
76
        catalogService.updateCatalogItem(id, catalogItemDto);
77
    }
78

    
79
    /**
80
     * Deletes catalog item with given ID
81
     *
82
     * @param id ID
83
     */
84
    @DeleteMapping("/{id}")
85
    @Operation(summary = "deletes catalog item with given ID")
86
    public void deleteCatalogItem(@PathVariable UUID id) {
87
        catalogService.deleteCatalogItem(id);
88
    }
89
}
(1-1/6)