handling for nullable abbreviation
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
package dev.mars3142.fhq.timezone_service.timezone.web.controllers;
|
package dev.mars3142.fhq.timezone_service.timezone.web.controllers;
|
||||||
|
|
||||||
|
import dev.mars3142.fhq.timezone_service.timezone.domain.entities.response.TimeApiTimezoneZoneResponse;
|
||||||
import dev.mars3142.fhq.timezone_service.timezone.domain.model.response.LocationResponse;
|
import dev.mars3142.fhq.timezone_service.timezone.domain.model.response.LocationResponse;
|
||||||
import dev.mars3142.fhq.timezone_service.timezone.domain.model.response.TimeZoneResponse;
|
import dev.mars3142.fhq.timezone_service.timezone.domain.model.response.TimeZoneResponse;
|
||||||
import dev.mars3142.fhq.timezone_service.timezone.service.TimeZoneService;
|
import dev.mars3142.fhq.timezone_service.timezone.service.TimeZoneService;
|
||||||
|
import java.util.Objects;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -19,8 +21,8 @@ public class TimeZoneController {
|
|||||||
private final TimeZoneService timeZoneService;
|
private final TimeZoneService timeZoneService;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public TimeZoneResponse getTimeZone(@RequestHeader(value = "X-Forwarded-For", defaultValue = "127.0.0.1") String data) {
|
public TimeZoneResponse getTimeZone(@RequestHeader(value = "X-Forwarded-For", defaultValue = "127.0.0.1") String header) {
|
||||||
val clientIp = data.split(",")[0];
|
val clientIp = header.split(",")[0];
|
||||||
val ip = timeZoneService.getExternalIp(clientIp);
|
val ip = timeZoneService.getExternalIp(clientIp);
|
||||||
val timezoneInfo = timeZoneService.getTimeZoneInfoByIp(ip);
|
val timezoneInfo = timeZoneService.getTimeZoneInfoByIp(ip);
|
||||||
val posix = timeZoneService.getPosixTimeZone(timezoneInfo.timezone());
|
val posix = timeZoneService.getPosixTimeZone(timezoneInfo.timezone());
|
||||||
@@ -37,7 +39,8 @@ public class TimeZoneController {
|
|||||||
public TimeZoneResponse getTimeZone(@PathVariable String area, @PathVariable String location) {
|
public TimeZoneResponse getTimeZone(@PathVariable String area, @PathVariable String location) {
|
||||||
val timezone = area + "/" + location;
|
val timezone = area + "/" + location;
|
||||||
val timezoneInfo = timeZoneService.getTimeZoneInfo(timezone);
|
val timezoneInfo = timeZoneService.getTimeZoneInfo(timezone);
|
||||||
|
val abbreviation = Objects.requireNonNullElse(timezoneInfo.dstInterval(), new TimeApiTimezoneZoneResponse.Interval(null)).dstName();
|
||||||
val posix = timeZoneService.getPosixTimeZone(timezone);
|
val posix = timeZoneService.getPosixTimeZone(timezone);
|
||||||
return new TimeZoneResponse(timezone, timezoneInfo.dstInterval().dstName(), posix);
|
return new TimeZoneResponse(timezone, abbreviation, posix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user