more hal+json optimisation
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package dev.mars3142.fhq.timezone_service.timezone.controllers;
|
||||
|
||||
import static org.springframework.beans.support.PagedListHolder.DEFAULT_PAGE_SIZE;
|
||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
|
||||
|
||||
import dev.mars3142.fhq.timezone_service.timezone.domain.model.response.LocationResponse;
|
||||
@@ -7,6 +8,7 @@ import dev.mars3142.fhq.timezone_service.timezone.domain.model.response.Timezone
|
||||
import dev.mars3142.fhq.timezone_service.timezone.service.TimezoneService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import org.springdoc.core.converters.models.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -25,8 +27,8 @@ public class TimezoneController {
|
||||
@GetMapping
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public TimezoneResponse getTimeZone(
|
||||
@RequestHeader(value = "X-Forwarded-For", defaultValue = "127.0.0.1") String header) {
|
||||
val clientIp = header.split(",")[0];
|
||||
@RequestHeader(value = "X-Forwarded-For", defaultValue = "127.0.0.1") String header_ip) {
|
||||
val clientIp = header_ip.split(",")[0];
|
||||
val ip = timeZoneService.getExternalIp(clientIp);
|
||||
val timezoneInfo = timeZoneService.getTimeZoneInfoByIp(ip);
|
||||
val posix = timeZoneService.getPosixTimeZone(timezoneInfo.timezone());
|
||||
@@ -41,7 +43,10 @@ public class TimezoneController {
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public LocationResponse getLocations(@PathVariable String area) {
|
||||
val locations = timeZoneService.getLocations(area);
|
||||
return new LocationResponse(locations.size(), locations);
|
||||
val result = new LocationResponse();
|
||||
result.setLocations(locations);
|
||||
result.add(linkTo(TimezoneController.class).slash(area).withSelfRel());
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("{area}/{location}")
|
||||
|
@@ -1,7 +1,17 @@
|
||||
package dev.mars3142.fhq.timezone_service.timezone.domain.model.response;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
|
||||
public record LocationResponse(int count, List<String> locations) {
|
||||
@Getter
|
||||
public class LocationResponse extends RepresentationModel<LocationResponse> {
|
||||
|
||||
private int count;
|
||||
private List<String> locations;
|
||||
|
||||
public void setLocations(List<String> locations) {
|
||||
this.count = locations.size();
|
||||
this.locations = locations;
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,11 @@
|
||||
package dev.mars3142.fhq.timezone_service.timezone.domain.model.response;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@RequiredArgsConstructor
|
||||
public class TimezoneResponse extends RepresentationModel<TimezoneResponse> {
|
||||
|
||||
private String timezone;
|
||||
|
Reference in New Issue
Block a user