From dd31e08c4f6d458014430a240c28ffae5584535c Mon Sep 17 00:00:00 2001 From: dyhj625 Date: Tue, 1 Apr 2025 14:46:09 +0900 Subject: [PATCH] =?UTF-8?q?=EB=82=A0=EC=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB-INF/web.xml | 27 ++++++++++------ .../mapper/MapBasedUrlRoleMapper.java | 13 ++++---- .../controller/common/WeatherController.java | 32 +++++++++++++++++++ src/main/resources/application.yml | 3 +- 4 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 src/main/java/io/company/localhost/controller/common/WeatherController.java diff --git a/WEB-INF/web.xml b/WEB-INF/web.xml index 21a5309..e291f74 100644 --- a/WEB-INF/web.xml +++ b/WEB-INF/web.xml @@ -1,12 +1,19 @@ - - localhost - - index.html - index.htm - index.jsp - default.html - default.htm - default.jsp - + + + localhost + + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + diff --git a/src/main/java/io/company/localhost/common/security/mapper/MapBasedUrlRoleMapper.java b/src/main/java/io/company/localhost/common/security/mapper/MapBasedUrlRoleMapper.java index 804f9d1..64fb5fc 100644 --- a/src/main/java/io/company/localhost/common/security/mapper/MapBasedUrlRoleMapper.java +++ b/src/main/java/io/company/localhost/common/security/mapper/MapBasedUrlRoleMapper.java @@ -30,12 +30,13 @@ public class MapBasedUrlRoleMapper implements UrlRoleMapper{ public Map getUrlRoleMappings() { urlRoleMappings.put("/api/user/**", PERMIT_ALL); urlRoleMappings.put("/api/project/**", ROLE_MEMBER); - urlRoleMappings.put("/api/vacation/**", PERMIT_ALL); - urlRoleMappings.put("/api/board/**", PERMIT_ALL); - urlRoleMappings.put("/api/vote/**", PERMIT_ALL); - urlRoleMappings.put("/api/worddict/**", PERMIT_ALL); - urlRoleMappings.put("/api/quilleditor/**", PERMIT_ALL); - urlRoleMappings.put("/api/commuters/**", PERMIT_ALL); + urlRoleMappings.put("/api/vacation/**", ROLE_MEMBER); + urlRoleMappings.put("/api/board/**", ROLE_MEMBER); + urlRoleMappings.put("/api/vote/**", ROLE_MEMBER); + urlRoleMappings.put("/api/worddict/**", ROLE_MEMBER); + urlRoleMappings.put("/api/quilleditor/**", ROLE_MEMBER); + urlRoleMappings.put("/api/commuters/**", ROLE_MEMBER); + urlRoleMappings.put("/api/weather/**", ROLE_MEMBER); urlRoleMappings.put("/api/admin/**", PERMIT_ALL); return new HashMap<>(urlRoleMappings); } diff --git a/src/main/java/io/company/localhost/controller/common/WeatherController.java b/src/main/java/io/company/localhost/controller/common/WeatherController.java new file mode 100644 index 0000000..1f003ea --- /dev/null +++ b/src/main/java/io/company/localhost/controller/common/WeatherController.java @@ -0,0 +1,32 @@ +package io.company.localhost.controller.common; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +import io.company.localhost.common.dto.ApiResponse; + +@RestController +@RequestMapping("/api/weather") +public class WeatherController { + + @Value("${api.weather.key}") + private String weatherApiKey; + + @GetMapping + public ApiResponse getWeather(@RequestParam("lat") double lat,@RequestParam("lon") double lon) { + String url = String.format( + "https://api.openweathermap.org/data/2.5/forecast?lat=%f&lon=%f&appid=%s&units=metric&lang=kr", + lat, lon, weatherApiKey + ); + + RestTemplate restTemplate = new RestTemplate(); + String response = restTemplate.getForObject(url, String.class); + + return ApiResponse.ok(response); + } +} + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 911b646..48372df 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -55,7 +55,8 @@ management: api: public-holiday: key: "MugzCRZ7VmR/LJ3BZ1Ehmmg5yiI0GPFt4evLjNkNuwKoiWbKbe/M9U5pLjAxfSP13OOwHi943aMFM9yiI8OADA==" - + weather: + key: "3505b3500aacf34c4497bf449996ea09" server: shutdown: graceful