BAEL-542 use @GetMapping annotation
This commit is contained in:
parent
dce9a947ab
commit
c2ed9afc2d
@ -6,9 +6,8 @@ import com.baeldung.cachecontrol.model.UserDto;
|
|||||||
import org.springframework.http.CacheControl;
|
import org.springframework.http.CacheControl;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
@ -17,27 +16,27 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Controller
|
@Controller
|
||||||
public class ResourceEndpoint {
|
public class ResourceEndpoint {
|
||||||
|
|
||||||
@RequestMapping(value = "/default/users/{name}", method = RequestMethod.GET)
|
@GetMapping(value = "/default/users/{name}")
|
||||||
public ResponseEntity<UserDto> getUserWithDefaultCaching(@PathVariable(value = "name") String name) {
|
public ResponseEntity<UserDto> getUserWithDefaultCaching(@PathVariable String name) {
|
||||||
return ResponseEntity.ok(new UserDto(name));
|
return ResponseEntity.ok(new UserDto(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/users/{name}", method = RequestMethod.GET)
|
@GetMapping(value = "/users/{name}")
|
||||||
public ResponseEntity<UserDto> getUser(@PathVariable(value = "name") String name) {
|
public ResponseEntity<UserDto> getUser(@PathVariable String name) {
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.cacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS))
|
.cacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS))
|
||||||
.body(new UserDto(name));
|
.body(new UserDto(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/timestamp", method = RequestMethod.GET)
|
@GetMapping(value = "/timestamp")
|
||||||
public ResponseEntity<TimestampDto> getServerTimestamp() {
|
public ResponseEntity<TimestampDto> getServerTimestamp() {
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.cacheControl(CacheControl.noStore())
|
.cacheControl(CacheControl.noStore())
|
||||||
.body(new TimestampDto(LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli()));
|
.body(new TimestampDto(LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/private/users/{name}", method = RequestMethod.GET)
|
@GetMapping(value = "/private/users/{name}")
|
||||||
public ResponseEntity<UserDto> getUserNotCached(@PathVariable("name") String name) {
|
public ResponseEntity<UserDto> getUserNotCached(@PathVariable String name) {
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.body(new UserDto(name));
|
.body(new UserDto(name));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user