From 5b79f605a4f85309970abd2fee67ed6d0b1cae20 Mon Sep 17 00:00:00 2001 From: pivovarit Date: Sun, 5 Feb 2017 17:06:12 +0100 Subject: [PATCH] Refactor ResourceEndpoint --- spring-security-cache-control/pom.xml | 5 ++++ .../cachecontrol/ResourceEndpoint.java | 29 +++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/spring-security-cache-control/pom.xml b/spring-security-cache-control/pom.xml index c30b0cd1aa..da363a75af 100644 --- a/spring-security-cache-control/pom.xml +++ b/spring-security-cache-control/pom.xml @@ -14,6 +14,11 @@ 1.4.3.RELEASE + + 1.8 + + + org.springframework.boot diff --git a/spring-security-cache-control/src/main/java/com/baeldung/cachecontrol/ResourceEndpoint.java b/spring-security-cache-control/src/main/java/com/baeldung/cachecontrol/ResourceEndpoint.java index bd129cbdfa..038df43165 100644 --- a/spring-security-cache-control/src/main/java/com/baeldung/cachecontrol/ResourceEndpoint.java +++ b/spring-security-cache-control/src/main/java/com/baeldung/cachecontrol/ResourceEndpoint.java @@ -1,6 +1,5 @@ package com.baeldung.cachecontrol; - import com.baeldung.cachecontrol.model.TimestampDto; import com.baeldung.cachecontrol.model.UserDto; import org.springframework.http.CacheControl; @@ -21,23 +20,29 @@ public class ResourceEndpoint { return ResponseEntity.ok(new UserDto(name)); } - @GetMapping(value = "/users/{name}") + @GetMapping("/users/{name}") public ResponseEntity getUser(@PathVariable String name) { - return ResponseEntity.ok() - .cacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS)) - .body(new UserDto(name)); + return ResponseEntity + .ok() + .cacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS)) + .body(new UserDto(name)); } - @GetMapping(value = "/timestamp") + @GetMapping("/timestamp") public ResponseEntity getServerTimestamp() { - return ResponseEntity.ok() - .cacheControl(CacheControl.noStore()) - .body(new TimestampDto(LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli())); + return ResponseEntity + .ok() + .cacheControl(CacheControl.noStore()) + .body(new TimestampDto(LocalDateTime + .now() + .toInstant(ZoneOffset.UTC) + .toEpochMilli())); } - @GetMapping(value = "/private/users/{name}") + @GetMapping("/private/users/{name}") public ResponseEntity getUserNotCached(@PathVariable String name) { - return ResponseEntity.ok() - .body(new UserDto(name)); + return ResponseEntity + .ok() + .body(new UserDto(name)); } }