UserResource(UserService)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
1
package com.osomapps.pt.user;
2
3
import org.springframework.beans.factory.annotation.Autowired;
4
import org.springframework.web.bind.annotation.GetMapping;
5
import org.springframework.web.bind.annotation.PutMapping;
6
import org.springframework.web.bind.annotation.RequestBody;
7
import org.springframework.web.bind.annotation.RequestHeader;
8
import org.springframework.web.bind.annotation.RequestMapping;
9
import org.springframework.web.bind.annotation.RestController;
10
11
@RestController
12
@RequestMapping("api/v1/user")
13
class UserResource {
14
15
    private final UserService userService;
16
17
    @Autowired
18
    UserResource(UserService userService) {
19
        this.userService = userService;
20
    }
21
22
    @GetMapping
23
    UserResponseDTO findOne(@RequestHeader(value = "X-Token") String token) {
24
        if (!token.isEmpty()) {
25
            return userService.findOne(token);
26
        }
27
        return new UserResponseDTO();
28
    }
29
30
    @PutMapping
31
    UserResponseDTO update(
32
            @RequestHeader(value = "X-Token") String token,
33
            @RequestBody UserRequestDTO userRequest) {
34
        return userService.updateUser(token, userRequest);
35
    }
36
}
37