Skip to content

Commit

Permalink
✨ Add: Batch end-point, Hourly weather query
Browse files Browse the repository at this point in the history
  • Loading branch information
jun108059 committed Nov 9, 2024
1 parent afb0317 commit 7a9d350
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 135 deletions.
9 changes: 9 additions & 0 deletions http/API-TEST.http
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ POST http://localhost:8080/api/snow-maker/{{resortId}}/vote?isPositive=true

### 혼잡도 조회
GET http://localhost:8080/api/congestion/{{resortId}}

### 현재 날씨 Batch
GET http://localhost:8080/batch/current-weather

### 주간 날씨 Batch
GET http://localhost:8080/batch/weekly-weather

### 시간별 날씨 Batch
GET http://localhost:8080/batch/hourly-weather
251 changes: 117 additions & 134 deletions init.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
CREATE
USER IF NOT EXISTS 'master'@'%' IDENTIFIED BY 'master';
GRANT ALL PRIVILEGES ON *.* TO
'master'@'%';
FLUSH
PRIVILEGES;
CREATE USER IF NOT EXISTS 'master'@'%' IDENTIFIED BY 'master';
GRANT ALL PRIVILEGES ON *.* TO 'master'@'%';
FLUSH PRIVILEGES;

CREATE
DATABASE IF NOT EXISTS ski_db;
CREATE DATABASE IF NOT EXISTS ski_db;

USE
ski_db;
USE ski_db;

DROP TABLE IF EXISTS current_weather;
DROP TABLE IF EXISTS daily_weather;
DROP TABLE IF EXISTS hourly_weather;
DROP TABLE IF EXISTS snow_quality_votes;
DROP TABLE IF EXISTS congestion;
DROP TABLE IF EXISTS webcams;
DROP TABLE IF EXISTS slopes;
DROP TABLE IF EXISTS ski_resorts;
Expand Down Expand Up @@ -150,118 +146,6 @@ CREATE TABLE congestion
FOREIGN KEY (resort_id) REFERENCES ski_resorts (resort_id)
);

INSERT INTO congestion (resort_id, congestion, description, time)
VALUES (1, 1, '여유', '오전 8시'),
(1, 3, '혼잡', '오전 10시'),
(1, 1, '여유', '오후 12시'),
(1, 3, '혼잡', '오후 2시'),
(1, 1, '여유', '오후 4시'),
(1, 3, '혼잡', '오후 6시'),
(1, 1, '여유', '오후 8시'),
(1, 3, '혼잡', '오후 10시'),
(1, 4, '매우 혼잡', '오전 12시'),
(1, 4, '매우 혼잡', '오전 2시'),
(2, 1, '여유', '오전 8시'),
(2, 3, '혼잡', '오전 10시'),
(2, 1, '여유', '오후 12시'),
(2, 3, '혼잡', '오후 2시'),
(2, 1, '여유', '오후 4시'),
(2, 3, '혼잡', '오후 6시'),
(2, 1, '여유', '오후 8시'),
(2, 3, '혼잡', '오후 10시'),
(2, 4, '매우 혼잡', '오전 12시'),
(2, 4, '매우 혼잡', '오전 2시'),
(3, 1, '여유', '오전 8시'),
(3, 3, '혼잡', '오전 10시'),
(3, 1, '여유', '오후 12시'),
(3, 3, '혼잡', '오후 2시'),
(3, 1, '여유', '오후 4시'),
(3, 3, '혼잡', '오후 6시'),
(3, 1, '여유', '오후 8시'),
(3, 3, '혼잡', '오후 10시'),
(3, 4, '매우 혼잡', '오전 12시'),
(3, 4, '매우 혼잡', '오전 2시'),
(4, 1, '여유', '오전 8시'),
(4, 3, '혼잡', '오전 10시'),
(4, 1, '여유', '오후 12시'),
(4, 3, '혼잡', '오후 2시'),
(4, 4, '매우 혼잡', '오후 4시'),
(4, 4, '매우 혼잡', '오후 6시'),
(4, 4, '매우 혼잡', '오후 8시'),
(4, 4, '매우 혼잡', '오후 10시'),
(4, 4, '매우 혼잡', '오전 12시'),
(4, 4, '매우 혼잡', '오전 2시'),
(5, 1, '여유', '오전 8시'),
(5, 3, '혼잡', '오전 10시'),
(5, 1, '여유', '오후 12시'),
(5, 3, '혼잡', '오후 2시'),
(5, 1, '여유', '오후 4시'),
(5, 3, '혼잡', '오후 6시'),
(5, 1, '여유', '오후 8시'),
(5, 3, '혼잡', '오후 10시'),
(5, 4, '매우 혼잡', '오전 12시'),
(5, 4, '매우 혼잡', '오전 2시'),
(6, 1, '여유', '오전 8시'),
(6, 3, '혼잡', '오전 10시'),
(6, 1, '여유', '오후 12시'),
(6, 3, '혼잡', '오후 2시'),
(6, 1, '여유', '오후 4시'),
(6, 3, '혼잡', '오후 6시'),
(6, 1, '여유', '오후 8시'),
(6, 3, '혼잡', '오후 10시'),
(6, 4, '매우 혼잡', '오전 12시'),
(6, 3, '혼잡', '오전 2시'),
(7, 1, '여유', '오전 8시'),
(7, 3, '혼잡', '오전 10시'),
(7, 1, '여유', '오후 12시'),
(7, 3, '혼잡', '오후 2시'),
(7, 1, '여유', '오후 4시'),
(7, 3, '혼잡', '오후 6시'),
(7, 1, '여유', '오후 8시'),
(7, 3, '혼잡', '오후 10시'),
(7, 4, '매우 혼잡', '오전 12시'),
(7, 4, '매우 혼잡', '오전 2시'),
(8, 1, '여유', '오전 8시'),
(8, 3, '혼잡', '오전 10시'),
(8, 1, '여유', '오후 12시'),
(8, 3, '혼잡', '오후 2시'),
(8, 1, '여유', '오후 4시'),
(8, 3, '혼잡', '오후 6시'),
(8, 1, '여유', '오후 8시'),
(8, 3, '혼잡', '오후 10시'),
(8, 4, '매우 혼잡', '오전 12시'),
(8, 4, '매우 혼잡', '오전 2시'),
(9, 1, '여유', '오전 8시'),
(9, 3, '혼잡', '오전 10시'),
(9, 1, '여유', '오후 12시'),
(9, 3, '혼잡', '오후 2시'),
(9, 1, '여유', '오후 4시'),
(9, 3, '혼잡', '오후 6시'),
(9, 1, '여유', '오후 8시'),
(9, 3, '혼잡', '오후 10시'),
(9, 4, '매우 혼잡', '오전 12시'),
(9, 4, '매우 혼잡', '오전 2시'),
(10, 1, '여유', '오전 8시'),
(10, 3, '혼잡', '오전 10시'),
(10, 1, '여유', '오후 12시'),
(10, 3, '혼잡', '오후 2시'),
(10, 1, '여유', '오후 4시'),
(10, 3, '혼잡', '오후 6시'),
(10, 1, '여유', '오후 8시'),
(10, 3, '혼잡', '오후 10시'),
(10, 4, '매우 혼잡', '오전 12시'),
(10, 4, '매우 혼잡', '오전 2시'),
(11, 1, '여유', '오전 8시'),
(11, 3, '혼잡', '오전 10시'),
(11, 1, '여유', '오후 12시'),
(11, 3, '혼잡', '오후 2시'),
(11, 1, '여유', '오후 4시'),
(11, 3, '혼잡', '오후 6시'),
(11, 1, '여유', '오후 8시'),
(11, 3, '혼잡', '오후 10시'),
(11, 4, '매우 혼잡', '오전 12시'),
(11, 4, '매우 혼잡', '오전 2시');

-- 스키장 정보
INSERT INTO ski_resorts (`name`, status, opening_date, closing_date, open_slopes, total_slopes, day_operating_hours,
night_operating_hours, late_night_operating_hours, dawn_operating_hours,
Expand Down Expand Up @@ -639,15 +523,114 @@ VALUES (1, CURDATE(), '월요일', 10, 5, -2, '맑음', 0),
(11, CURDATE() + INTERVAL 1 DAY, '화요일', 28, -6, -13, '안개', 1),
(11, CURDATE() + INTERVAL 2 DAY, '수요일', 38, -7, -14, '흐림', 2);

INSERT INTO hourly_weather (resort_id, forecast_time, temperature, precipitation_chance, `condition`)
VALUES (1, '2024-10-04 08:00:00', -2, 20, '맑음'),
(1, '2024-10-04 10:00:00', 0, 30, '흐림'),
(1, '2024-10-04 12:00:00', 2, 40, '흐리고 비'),
(1, '2024-10-04 14:00:00', 0, 50, ''),
(1, '2024-10-04 16:00:00', -2, 60, ''),
(1, '2024-10-04 18:00:00', -4, 70, ''),
(1, '2024-10-04 20:00:00', -6, 80, '흐림'),
(1, '2024-10-04 22:00:00', -8, 90, '안개'),
(1, '2024-10-05 00:00:00', -10, 80, '맑음'),
(1, '2024-10-05 02:00:00', -12, 70, '맑음');

INSERT INTO congestion (resort_id, congestion, description, time)
VALUES (1, 1, '여유', '오전 8시'),
(1, 3, '혼잡', '오전 10시'),
(1, 1, '여유', '오후 12시'),
(1, 3, '혼잡', '오후 2시'),
(1, 1, '여유', '오후 4시'),
(1, 3, '혼잡', '오후 6시'),
(1, 1, '여유', '오후 8시'),
(1, 3, '혼잡', '오후 10시'),
(1, 4, '매우 혼잡', '오전 12시'),
(1, 4, '매우 혼잡', '오전 2시'),
(2, 1, '여유', '오전 8시'),
(2, 3, '혼잡', '오전 10시'),
(2, 1, '여유', '오후 12시'),
(2, 3, '혼잡', '오후 2시'),
(2, 1, '여유', '오후 4시'),
(2, 3, '혼잡', '오후 6시'),
(2, 1, '여유', '오후 8시'),
(2, 3, '혼잡', '오후 10시'),
(2, 4, '매우 혼잡', '오전 12시'),
(2, 4, '매우 혼잡', '오전 2시'),
(3, 1, '여유', '오전 8시'),
(3, 3, '혼잡', '오전 10시'),
(3, 1, '여유', '오후 12시'),
(3, 3, '혼잡', '오후 2시'),
(3, 1, '여유', '오후 4시'),
(3, 3, '혼잡', '오후 6시'),
(3, 1, '여유', '오후 8시'),
(3, 3, '혼잡', '오후 10시'),
(3, 4, '매우 혼잡', '오전 12시'),
(3, 4, '매우 혼잡', '오전 2시'),
(4, 1, '여유', '오전 8시'),
(4, 3, '혼잡', '오전 10시'),
(4, 1, '여유', '오후 12시'),
(4, 3, '혼잡', '오후 2시'),
(4, 4, '매우 혼잡', '오후 4시'),
(4, 4, '매우 혼잡', '오후 6시'),
(4, 4, '매우 혼잡', '오후 8시'),
(4, 4, '매우 혼잡', '오후 10시'),
(4, 4, '매우 혼잡', '오전 12시'),
(4, 4, '매우 혼잡', '오전 2시'),
(5, 1, '여유', '오전 8시'),
(5, 3, '혼잡', '오전 10시'),
(5, 1, '여유', '오후 12시'),
(5, 3, '혼잡', '오후 2시'),
(5, 1, '여유', '오후 4시'),
(5, 3, '혼잡', '오후 6시'),
(5, 1, '여유', '오후 8시'),
(5, 3, '혼잡', '오후 10시'),
(5, 4, '매우 혼잡', '오전 12시'),
(5, 4, '매우 혼잡', '오전 2시'),
(6, 1, '여유', '오전 8시'),
(6, 3, '혼잡', '오전 10시'),
(6, 1, '여유', '오후 12시'),
(6, 3, '혼잡', '오후 2시'),
(6, 1, '여유', '오후 4시'),
(6, 3, '혼잡', '오후 6시'),
(6, 1, '여유', '오후 8시'),
(6, 3, '혼잡', '오후 10시'),
(6, 4, '매우 혼잡', '오전 12시'),
(6, 3, '혼잡', '오전 2시'),
(7, 1, '여유', '오전 8시'),
(7, 3, '혼잡', '오전 10시'),
(7, 1, '여유', '오후 12시'),
(7, 3, '혼잡', '오후 2시'),
(7, 1, '여유', '오후 4시'),
(7, 3, '혼잡', '오후 6시'),
(7, 1, '여유', '오후 8시'),
(7, 3, '혼잡', '오후 10시'),
(7, 4, '매우 혼잡', '오전 12시'),
(7, 4, '매우 혼잡', '오전 2시'),
(8, 1, '여유', '오전 8시'),
(8, 3, '혼잡', '오전 10시'),
(8, 1, '여유', '오후 12시'),
(8, 3, '혼잡', '오후 2시'),
(8, 1, '여유', '오후 4시'),
(8, 3, '혼잡', '오후 6시'),
(8, 1, '여유', '오후 8시'),
(8, 3, '혼잡', '오후 10시'),
(8, 4, '매우 혼잡', '오전 12시'),
(8, 4, '매우 혼잡', '오전 2시'),
(9, 1, '여유', '오전 8시'),
(9, 3, '혼잡', '오전 10시'),
(9, 1, '여유', '오후 12시'),
(9, 3, '혼잡', '오후 2시'),
(9, 1, '여유', '오후 4시'),
(9, 3, '혼잡', '오후 6시'),
(9, 1, '여유', '오후 8시'),
(9, 3, '혼잡', '오후 10시'),
(9, 4, '매우 혼잡', '오전 12시'),
(9, 4, '매우 혼잡', '오전 2시'),
(10, 1, '여유', '오전 8시'),
(10, 3, '혼잡', '오전 10시'),
(10, 1, '여유', '오후 12시'),
(10, 3, '혼잡', '오후 2시'),
(10, 1, '여유', '오후 4시'),
(10, 3, '혼잡', '오후 6시'),
(10, 1, '여유', '오후 8시'),
(10, 3, '혼잡', '오후 10시'),
(10, 4, '매우 혼잡', '오전 12시'),
(10, 4, '매우 혼잡', '오전 2시'),
(11, 1, '여유', '오전 8시'),
(11, 3, '혼잡', '오전 10시'),
(11, 1, '여유', '오후 12시'),
(11, 3, '혼잡', '오후 2시'),
(11, 1, '여유', '오후 4시'),
(11, 3, '혼잡', '오후 6시'),
(11, 1, '여유', '오후 8시'),
(11, 3, '혼잡', '오후 10시'),
(11, 4, '매우 혼잡', '오전 12시'),
(11, 4, '매우 혼잡', '오전 2시');
25 changes: 25 additions & 0 deletions src/main/kotlin/nexters/weski/batch/WeatherBatchController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package nexters.weski.batch

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class WeatherBatchController(
private val externalWeatherService: ExternalWeatherService
) {

@GetMapping("/batch/current-weather")
fun scheduleWeatherUpdate() {
externalWeatherService.updateCurrentWeather()
}

@GetMapping("/batch/weekly-weather")
fun scheduledDailyWeatherUpdate() {
externalWeatherService.updateDailyWeather()
}

@GetMapping("/batch/hourly-weather")
fun scheduledHourlyAndDailyUpdate() {
externalWeatherService.updateHourlyAndDailyWeather()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository

interface HourlyWeatherRepository : JpaRepository<HourlyWeather, Long> {
fun deleteBySkiResort(skiResort: SkiResort)
fun findBySkiResortResortId(resortId: Long): List<HourlyWeather>
}
2 changes: 1 addition & 1 deletion src/main/kotlin/nexters/weski/weather/WeatherService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WeatherService(
) {
fun getWeatherByResortId(resortId: Long): WeatherDto? {
val currentWeather = currentWeatherRepository.findBySkiResortResortId(resortId) ?: return null
val hourlyWeather = hourlyWeatherRepository.findAll()
val hourlyWeather = hourlyWeatherRepository.findBySkiResortResortId(resortId)
val dailyWeather = dailyWeatherRepository.findAllBySkiResortResortId(resortId)

return WeatherDto.fromEntities(currentWeather, hourlyWeather, dailyWeather)
Expand Down

0 comments on commit 7a9d350

Please sign in to comment.