1
|
|
|
package com.osomapps.pt.tokenemail; |
2
|
|
|
|
3
|
|
|
import com.osomapps.pt.token.InUser; |
4
|
|
|
import java.util.Collections; |
5
|
|
|
import java.util.List; |
6
|
|
|
import javax.servlet.http.HttpServletRequest; |
7
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
8
|
|
|
import org.springframework.http.HttpStatus; |
9
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping; |
10
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
11
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
12
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
13
|
|
|
import org.springframework.web.bind.annotation.RequestHeader; |
14
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
15
|
|
|
import org.springframework.web.bind.annotation.ResponseStatus; |
16
|
|
|
import org.springframework.web.bind.annotation.RestController; |
17
|
|
|
|
18
|
|
|
@RestController |
19
|
|
|
@RequestMapping("api/v1/token-email") |
20
|
|
|
class TokenEmailResource { |
21
|
|
|
|
22
|
|
|
private final TokenEmailService tokenEmailService; |
23
|
|
|
|
24
|
|
|
@Autowired |
25
|
|
|
TokenEmailResource(TokenEmailService tokenEmailService) { |
26
|
|
|
this.tokenEmailService = tokenEmailService; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
@GetMapping |
30
|
|
|
List<InUser> list() { |
31
|
|
|
return Collections.emptyList(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
@PostMapping |
35
|
|
|
TokenEmailResponseDTO create( |
36
|
|
|
@RequestBody TokenEmailRequestDTO tokenEmailRequest, HttpServletRequest request) { |
37
|
|
|
return tokenEmailService.createOrReadNewToken(tokenEmailRequest, request.getRemoteAddr()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
@DeleteMapping |
41
|
|
|
@ResponseStatus(value = HttpStatus.NO_CONTENT) |
42
|
|
|
void delete(@RequestHeader(value = "X-Token") String token, HttpServletRequest request) { |
43
|
|
|
tokenEmailService.deleteToken(token, request.getRemoteAddr()); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|