create(TokenRequestDTO,HttpServletRequest)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 3
c 1
b 0
f 0
rs 10
cc 1
1
package com.osomapps.pt.token;
2
3
import java.util.Collections;
4
import java.util.List;
5
import javax.servlet.http.HttpServletRequest;
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.http.HttpStatus;
8
import org.springframework.web.bind.annotation.DeleteMapping;
9
import org.springframework.web.bind.annotation.GetMapping;
10
import org.springframework.web.bind.annotation.PostMapping;
11
import org.springframework.web.bind.annotation.RequestBody;
12
import org.springframework.web.bind.annotation.RequestHeader;
13
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.ResponseStatus;
15
import org.springframework.web.bind.annotation.RestController;
16
17
@RestController
18
@RequestMapping("api/v1/token")
19
class TokenResource {
20
21
    private final TokenService tokenService;
22
23
    @Autowired
24
    TokenResource(TokenService tokenService) {
25
        this.tokenService = tokenService;
26
    }
27
28
    @GetMapping
29
    List<InUser> list() {
30
        return Collections.emptyList();
31
    }
32
33
    @PostMapping
34
    TokenResponseDTO create(@RequestBody TokenRequestDTO tokenRequest, HttpServletRequest request) {
35
        return tokenService.createOrReadNewToken(tokenRequest, request.getRemoteAddr());
36
    }
37
38
    @DeleteMapping
39
    @ResponseStatus(value = HttpStatus.NO_CONTENT)
40
    void delete(@RequestHeader(value = "X-Token") String token, HttpServletRequest request) {
41
        tokenService.deleteToken(token, request.getRemoteAddr());
42
    }
43
}
44