Projekt

Obecné

Profil

« Předchozí | Další » 

Revize e91fef9c

Přidáno uživatelem Jakub Šmíd před více než 2 roky(ů)

Added swagger summary for controllers

Zobrazit rozdíly:

backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogController.java
1 1
package cz.zcu.kiv.backendapi.catalog;
2 2

  
3
import io.swagger.v3.oas.annotations.Operation;
3 4
import lombok.RequiredArgsConstructor;
4 5
import org.springframework.http.HttpStatus;
5 6
import org.springframework.http.ResponseEntity;
......
13 14
 */
14 15
@RestController
15 16
@RequiredArgsConstructor
16
@RequestMapping("")
17
@RequestMapping("/catalog-items")
17 18
public class CatalogController {
18 19

  
19 20
    /**
......
26 27
     *
27 28
     * @param catalogItemDto catalog item DTO
28 29
     */
29
    @PostMapping("/catalog-item")
30
    @PostMapping("")
31
    @Operation(summary = "creates new catalog item")
30 32
    public void addCatalogItem(@RequestBody CatalogItemDto catalogItemDto) {
31 33
        catalogService.saveCatalogItem(catalogItemDto);
32 34
    }
......
39 41
     * @param type    type - optional
40 42
     * @return list of catalog items satisfying given filter
41 43
     */
42
    @GetMapping("/catalog")
44
    @GetMapping("")
45
    @Operation(summary = "returns catalog items based on filter")
43 46
    public ResponseEntity<List<CatalogItemDto>> getCatalog(@RequestParam(defaultValue = "") String name, @RequestParam(defaultValue = "") String country, @RequestParam(defaultValue = "") String type) {
44 47
        return new ResponseEntity<>(catalogService.getCatalog(name, country, type), HttpStatus.OK);
45 48
    }
......
50 53
     * @param id             ID
51 54
     * @param catalogItemDto catalog item DTO
52 55
     */
53
    @PutMapping("/catalog-item/{id}")
56
    @PutMapping("/{id}")
57
    @Operation(summary = "updates catalog item with given ID")
54 58
    public void updateCatalogItem(@PathVariable UUID id, @RequestBody CatalogItemDto catalogItemDto) {
55 59
        catalogService.updateCatalogItem(id, catalogItemDto);
56 60
    }
......
60 64
     *
61 65
     * @param id ID
62 66
     */
63
    @DeleteMapping("/catalog-item/{id}")
67
    @DeleteMapping("/{id}")
68
    @Operation(summary = "deletes catalog item with given ID")
64 69
    public void deleteCatalogItem(@PathVariable UUID id) {
65 70
        catalogService.deleteCatalogItem(id);
66 71
    }
backend/src/main/java/cz/zcu/kiv/backendapi/titlepage/TitlePageController.java
1 1
package cz.zcu.kiv.backendapi.titlepage;
2 2

  
3
import io.swagger.v3.oas.annotations.Operation;
3 4
import lombok.RequiredArgsConstructor;
4 5
import org.springframework.http.HttpStatus;
5 6
import org.springframework.http.ResponseEntity;
......
23 24
     * @return title page
24 25
     */
25 26
    @GetMapping("")
27
    @Operation(summary = "returns title page")
26 28
    public ResponseEntity<TitlePage> getTitlePage() {
27 29
        return new ResponseEntity<>(titlePageService.getTitlePage(), HttpStatus.OK);
28 30
    }
......
33 35
     * @param titlePage title page
34 36
     */
35 37
    @PostMapping("")
38
    @Operation(summary = "updates/creates title page")
36 39
    public void updateTitlePage(@RequestBody TitlePage titlePage) {
37 40
        titlePageService.updateTitlePage(titlePage);
38 41
    }
backend/src/main/java/cz/zcu/kiv/backendapi/user/UserController.java
9 9
import cz.zcu.kiv.backendapi.security.jwt.JwtUtils;
10 10
import cz.zcu.kiv.backendapi.user.password.PasswordDto;
11 11
import cz.zcu.kiv.backendapi.user.permission.PermissionDto;
12
import io.swagger.v3.oas.annotations.Operation;
12 13
import lombok.RequiredArgsConstructor;
13 14
import lombok.extern.slf4j.Slf4j;
14 15
import org.springframework.http.HttpHeaders;
......
33 34
 */
34 35
@RestController
35 36
@RequiredArgsConstructor
37
@RequestMapping("/users")
36 38
@Slf4j
37 39
public class UserController {
38 40

  
......
52 54
     *
53 55
     * @param userDto user DTO
54 56
     */
55
    @PostMapping("/register")
57
    @PostMapping("")
58
    @Operation(summary = "registers new user")
56 59
    public void registerNewUser(@RequestBody @Valid UserDto userDto) {
57 60
        userService.registerNewUser(userDto);
58 61
    }
......
64 67
     * @param oldPassword old password
65 68
     * @param passwordDto password DTO
66 69
     */
67
    @PatchMapping("/user/change-password")
70
    @PatchMapping("/password")
71
    @Operation(summary = "changes password to logged-in user")
68 72
    public void changePassword(@Valid @NotNull(message = "Old password must not be null") @RequestParam String oldPassword, @RequestBody @Valid PasswordDto passwordDto) {
69 73
        userService.changePassword(oldPassword, passwordDto.getPassword());
70 74
    }
......
74 78
     *
75 79
     * @return list of all users
76 80
     */
77
    @GetMapping("/users")
81
    @GetMapping("")
82
    @Operation(summary = "returns all users")
78 83
    public ResponseEntity<List<UserDto>> getAllUsers() {
79 84
        return new ResponseEntity<>(userService.getAllUsers(), HttpStatus.OK);
80 85
    }
......
85 90
     * @param username      username
86 91
     * @param permissionDto permissions
87 92
     */
88
    @PatchMapping("/user/update-permissions/{username}")
93
    @PatchMapping("/{username}/permissions")
94
    @Operation(summary = "changes permissions to given user")
89 95
    public void updatePermissions(@PathVariable String username, @RequestBody PermissionDto permissionDto) {
90 96
        userService.updatePermissions(username, permissionDto);
91 97
    }
......
96 102
     * @param username    username
97 103
     * @param passwordDto password
98 104
     */
99
    @PatchMapping(value = "/user/reset-password/{username}")
105
    @PatchMapping(value = "/{username}/password")
106
    @Operation(summary = "changes password to given user")
100 107
    public void resetPassword(@PathVariable String username, @RequestBody @Valid PasswordDto passwordDto) {
101 108
        userService.resetPassword(username, passwordDto.getPassword());
102 109
    }
103 110

  
104 111
    //TODO check if needed, comment otherwise
105
    @DeleteMapping("/user/{username}")
112
    @DeleteMapping("/{username}")
113
    @Operation(summary = "deletes user with given username")
106 114
    public void deleteUser(@PathVariable String username) {
107 115
        userService.deleteUser(username);
108 116
    }
......
115 123
     * @param response response
116 124
     * @throws IOException I/O Exception
117 125
     */
118
    @GetMapping("token/refresh")
126
    @GetMapping("/token")
127
    @Operation(summary = "returns a new access token and a refresh token to user")
119 128
    public void refreshToken(HttpServletRequest request, HttpServletResponse response) throws IOException {
120 129
        String authorizationHeader = request.getHeader(HttpHeaders.AUTHORIZATION);
121 130
        if (Strings.isNullOrEmpty(authorizationHeader) || !authorizationHeader.startsWith(jwtUtils.getTokenPrefix())) {

Také k dispozici: Unified diff