-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated implementation of Weather services.
- Loading branch information
Showing
5 changed files
with
181 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,51 @@ | ||
package tfip.strava.model; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
|
||
public class Weather { | ||
|
||
private String description; | ||
private double temp; | ||
private String name; | ||
private String forecast; | ||
private double lat; | ||
private double lng; | ||
|
||
public Weather() { | ||
} | ||
|
||
public Weather(String description, double temp) { | ||
this.description = description; | ||
this.temp = temp; | ||
public Weather(String name, double lat, double lng) { | ||
this.name = name; | ||
this.lat = lat; | ||
this.lng = lng; | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public String getDescription() { | ||
return this.description; | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
public String getForecast() { | ||
return this.forecast; | ||
} | ||
|
||
public double getTemp() { | ||
return this.temp; | ||
public void setForecast(String forecast) { | ||
this.forecast = forecast; | ||
} | ||
|
||
public void setTemp(double temp) { | ||
this.temp = temp; | ||
public double getLat() { | ||
return this.lat; | ||
} | ||
|
||
public static Weather toWeather(String json) { | ||
JsonObject openWeather = JsonParser | ||
.parseString(json) | ||
.getAsJsonObject(); | ||
return new Weather( | ||
openWeather | ||
.get("weather") | ||
.getAsJsonArray() | ||
.get(0) | ||
.getAsJsonObject() | ||
.get("description") | ||
.getAsString(), | ||
public void setLat(double lat) { | ||
this.lat = lat; | ||
} | ||
|
||
openWeather | ||
.get("main") | ||
.getAsJsonObject() | ||
.get("temp") | ||
.getAsDouble()); | ||
public double getLng() { | ||
return this.lng; | ||
} | ||
|
||
public void setLng(double lng) { | ||
this.lng = lng; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package tfip.strava.model; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.jdbc.support.rowset.SqlRowSet; | ||
|
||
import tfip.strava.util.ListToStringConverter; | ||
|
||
public class Workout { | ||
|
||
private int id; | ||
private Long start; | ||
private List<String> waypoints; | ||
private double distance; | ||
private int user_id; | ||
|
||
public Workout(int id, Long start, List<String> waypoints, double distance, int user_id) { | ||
this.id = id; | ||
this.start = start; | ||
this.waypoints = waypoints; | ||
this.distance = distance; | ||
this.user_id = user_id; | ||
} | ||
|
||
public int getId() { | ||
return this.id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public Long getStart() { | ||
return this.start; | ||
} | ||
|
||
public void setStart(Long start) { | ||
this.start = start; | ||
} | ||
|
||
public List<String> getWaypoints() { | ||
return this.waypoints; | ||
} | ||
|
||
public void setWaypoints(List<String> waypoints) { | ||
this.waypoints = waypoints; | ||
} | ||
|
||
public double getDistance() { | ||
return this.distance; | ||
} | ||
|
||
public void setDistance(double distance) { | ||
this.distance = distance; | ||
} | ||
|
||
public int getUser_id() { | ||
return this.user_id; | ||
} | ||
|
||
public void setUser_id(int user_id) { | ||
this.user_id = user_id; | ||
} | ||
|
||
public static Workout populate(SqlRowSet rs) { | ||
return new Workout( | ||
rs.getInt("id"), | ||
rs.getDate("start").getTime(), | ||
ListToStringConverter.toList(rs.getString("waypoints")), | ||
rs.getDouble("distance"), | ||
rs.getInt("user_id")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters