Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package fr.brde.api.controllers;

import fr.brde.api.entities.CurrentWeather;
import fr.brde.api.services.CurrentWeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/currentWeather")
public class CurrentWeatherController
{

@Autowired
CurrentWeatherService currentWeatherService;

@GetMapping("")
public List<CurrentWeather> list()
{
return this.currentWeatherService.listAllWeathers();
}

@CrossOrigin(origins = "http://localhost:8100")
@GetMapping("/last")
public CurrentWeather getLast()
{
return this.currentWeatherService.getLastWeather();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package fr.brde.api.controllers;

import fr.brde.api.entities.ForecastWeather;
import fr.brde.api.services.ForecastWeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/forecastWeather")
public class ForecastWeatherController
{

@Autowired
ForecastWeatherService forecastWeatherService;

@GetMapping("")
public List<ForecastWeather> list()
{
return this.forecastWeatherService.listAllForecastWeathers();
}

@CrossOrigin(originPatterns = "http://localhost:8100")
@GetMapping("/last")
public ForecastWeather getLast()
{
return this.forecastWeatherService.getLastForecastWeather();
}

}
108 changes: 108 additions & 0 deletions src/main/java/fr/brde/api/entities/CurrentWeather.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package fr.brde.api.entities;

import jakarta.persistence.*;

@Entity
@Table(name = "CurrentWeather")
public class CurrentWeather {

private int id;
private String time;

private int temp; // °C
private String lastUpdated;
private String weatherCondition;
private int wind; // km/h
private int feelslike;

public CurrentWeather() {}

public CurrentWeather(int id,
String time,
int temp,
String lastUpdated,
String weatherCondition,
int wind,
int feelslike)
{
this.id = id;
this.time = time;
this.temp = temp;
this.lastUpdated = lastUpdated;
this.weatherCondition = weatherCondition;
this.wind = wind;
this.feelslike = feelslike;
}

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getId()
{
return this.id;
}

public void setId(int id)
{
this.id = id;
}

public String getTime()
{
return time;
}

public void setTime(String time)
{
this.time = time;
}

public int getTemp()
{
return temp;
}

public void setTemp(int temp)
{
this.temp = temp;
}

public String getLastUpdated()
{
return lastUpdated;
}

public void setLastUpdated(String lastUpdated)
{
this.lastUpdated = lastUpdated;
}

public String getWeatherCondition()
{
return weatherCondition;
}

public void setWeatherCondition(String weatherCondition)
{
this.weatherCondition = weatherCondition;
}

public int getWind()
{
return wind;
}

public void setWind(int wind)
{
this.wind = wind;
}

public int getFeelslike()
{
return feelslike;
}

public void setFeelslike(int feelslike)
{
this.feelslike = feelslike;
}
}
163 changes: 163 additions & 0 deletions src/main/java/fr/brde/api/entities/ForecastWeather.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package fr.brde.api.entities;

import jakarta.persistence.*;

@Entity
@Table(name = "ForecastWeather")
public class ForecastWeather
{

private int id;
private String time;

private int morningTemp; // °C
private int morningWind; // km/h
private String morningWeatherCondition;

private int afternoonTemp; // °C
private int afternoonWind; // km/h
private String afternoonWeatherCondition;

private int nightTemp; // °C
private int nightWind; // km/h
private String nightWeatherCondition;

public ForecastWeather() {}

public ForecastWeather(int id,
String time,
int morningTemp,
int morningWind,
String morningWeatherCondition,
int afternoonTemp,
int afternoonWind,
String afternoonWeatherCondition,
int nightTemp,
int nightWind,
String nightWeatherCondition)
{
this.id = id;
this.time = time;
this.morningTemp = morningTemp;
this.morningWind = morningWind;
this.morningWeatherCondition = morningWeatherCondition;
this.afternoonTemp = afternoonTemp;
this.afternoonWind = afternoonWind;
this.afternoonWeatherCondition = afternoonWeatherCondition;
this.nightTemp = nightTemp;
this.nightWind = nightWind;
this.nightWeatherCondition = nightWeatherCondition;
}

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getId()
{
return this.id;
}

public void setId(int id)
{
this.id = id;
}

public String getTime()
{
return time;
}

public void setTime(String time)
{
this.time = time;
}

public int getMorningTemp()
{
return morningTemp;
}

public void setMorningTemp(int morningTemp)
{
this.morningTemp = morningTemp;
}

public int getMorningWind()
{
return morningWind;
}

public void setMorningWind(int morningWind)
{
this.morningWind = morningWind;
}

public String getMorningWeatherCondition()
{
return morningWeatherCondition;
}

public void setMorningWeatherCondition(String morningWeatherCondition)
{
this.morningWeatherCondition = morningWeatherCondition;
}

public int getAfternoonTemp()
{
return afternoonTemp;
}

public void setAfternoonTemp(int afternoonTemp)
{
this.afternoonTemp = afternoonTemp;
}

public int getAfternoonWind()
{
return afternoonWind;
}

public void setAfternoonWind(int afternoonWind)
{
this.afternoonWind = afternoonWind;
}

public String getAfternoonWeatherCondition()
{
return afternoonWeatherCondition;
}

public void setAfternoonWeatherCondition(String afternoonWeatherCondition)
{
this.afternoonWeatherCondition = afternoonWeatherCondition;
}

public int getNightTemp()
{
return nightTemp;
}

public void setNightTemp(int nightTemp)
{
this.nightTemp = nightTemp;
}

public int getNightWind()
{
return nightWind;
}

public void setNightWind(int nightWind)
{
this.nightWind = nightWind;
}

public String getNightWeatherCondition()
{
return nightWeatherCondition;
}

public void setNightWeatherCondition(String nightWeatherCondition)
{
this.nightWeatherCondition = nightWeatherCondition;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fr.brde.api.repositories;

import fr.brde.api.entities.CurrentWeather;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CurrentWeatherRepository extends JpaRepository<CurrentWeather, Long>
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package fr.brde.api.repositories;

import fr.brde.api.entities.ForecastWeather;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ForecastWeatherRepository extends JpaRepository<ForecastWeather, Long>
{ }
Loading