-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloController.java
More file actions
33 lines (27 loc) · 1.09 KB
/
HelloController.java
File metadata and controls
33 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package fr.inote.inote_api.controller;
import java.util.Locale;
import org.springframework.context.MessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
private final MessageSource source;
public HelloController(MessageSource source){
this.source = source;
}
@GetMapping(path = "/api/hello")
public ResponseEntity<String> hello(
@RequestHeader(name = "Accept-Language", required = false)
final Locale locale,
@RequestParam(name = "user", required = false, defaultValue = "")
final String USER){
return ResponseEntity
.status(HttpStatus.OK)
.header("Content-Type", "text/plain")
.body(source.getMessage("hello", new Object[]{USER}, locale));
}
}