mirror of
https://github.com/katanemo/plano.git
synced 2026-06-17 15:25:17 +02:00
working draft
This commit is contained in:
parent
2bd61d628c
commit
ae28ab8612
78 changed files with 239 additions and 1085 deletions
18
demos/sample_apps/java/weather_forcecast_service/Dockerfile
Normal file
18
demos/sample_apps/java/weather_forcecast_service/Dockerfile
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Stage 1: Build the application using Maven
|
||||
FROM maven:3.8.7-openjdk-17 AS build
|
||||
WORKDIR /app
|
||||
# Copy pom.xml and download dependencies first (caching)
|
||||
COPY pom.xml .
|
||||
RUN mvn dependency:go-offline
|
||||
# Copy the source code and build the application
|
||||
COPY src ./src
|
||||
RUN mvn clean package -DskipTests
|
||||
|
||||
# Stage 2: Run the application using a slim JDK image
|
||||
FROM openjdk:17-jdk-slim
|
||||
WORKDIR /app
|
||||
# Copy the built jar from the previous stage
|
||||
COPY --from=build /app/target/weather-forecast-service-0.0.1-SNAPSHOT.jar app.jar
|
||||
# Expose the port on which the app runs (default Spring Boot is 8080)
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["java", "-jar", "app.jar"]
|
||||
40
demos/sample_apps/java/weather_forcecast_service/pom.xml
Normal file
40
demos/sample_apps/java/weather_forcecast_service/pom.xml
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId></groupId>
|
||||
<artifactId>weather-forecast-service</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.10</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring Boot Starter Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Spring Boot Maven Plugin -->
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
// File: src/main/java/com/example/weather/WeatherForecastApplication.java
|
||||
package weather;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class WeatherForecastApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WeatherForecastApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package weather.controller;
|
||||
|
||||
import weather.model.DayForecast;
|
||||
import weeather.model.Temperature;
|
||||
import weather.model.WeatherForecastResponse;
|
||||
import weather.model.WeatherRequest;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@RestController
|
||||
public class WeatherController {
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
@PostMapping("/weather")
|
||||
public WeatherForecastResponse getWeather(@RequestBody WeatherRequest req) {
|
||||
WeatherForecastResponse response = new WeatherForecastResponse();
|
||||
response.setLocation(req.getLocation());
|
||||
response.setUnits(req.getUnits());
|
||||
|
||||
List<DayForecast> forecasts = new ArrayList<>();
|
||||
for (int i = 0; i < req.getDays(); i++) {
|
||||
// Generate a random min temperature between 50 and 89 (inclusive)
|
||||
int minTemp = random.nextInt(90 - 50) + 50;
|
||||
// Generate a max temperature between (minTemp + 5) and (minTemp + 19)
|
||||
int maxTemp = random.nextInt(15) + (minTemp + 5);
|
||||
|
||||
double finalMinTemp = minTemp;
|
||||
double finalMaxTemp = maxTemp;
|
||||
|
||||
// Convert to Celsius if necessary
|
||||
if (req.getUnits().equalsIgnoreCase("celsius") || req.getUnits().equalsIgnoreCase("c")) {
|
||||
finalMinTemp = (minTemp - 32) * 5.0 / 9.0;
|
||||
finalMaxTemp = (maxTemp - 32) * 5.0 / 9.0;
|
||||
}
|
||||
|
||||
DayForecast dayForecast = new DayForecast();
|
||||
dayForecast.setDate(LocalDate.now().plusDays(i).toString());
|
||||
dayForecast.setMin(finalMinTemp);
|
||||
dayForecast.setMax(finalMaxTemp);
|
||||
dayForecast.setUnits(req.getUnits());
|
||||
|
||||
forecasts.add(dayForecast);
|
||||
}
|
||||
response.setDailyForecast(forecasts);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package weather.model;
|
||||
|
||||
public class DayForecast {
|
||||
private String date;
|
||||
private String units;
|
||||
private double min;
|
||||
private double max;
|
||||
|
||||
public DayForecast() {}
|
||||
|
||||
// Getters and setters
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getUnits() {
|
||||
return units;
|
||||
}
|
||||
|
||||
public void setUnits(String units) {
|
||||
this.units = units;
|
||||
}
|
||||
|
||||
public double getMin() {
|
||||
return min;
|
||||
}
|
||||
public void setMin(double min) {
|
||||
this.min = min;
|
||||
}
|
||||
public double getMax() {
|
||||
return max;
|
||||
}
|
||||
public void setMax(double max) {
|
||||
this.max = max;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package weather.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WeatherForecastResponse {
|
||||
private String location;
|
||||
private String units;
|
||||
private List<DayForecast> temperature;
|
||||
|
||||
// Default Constructor
|
||||
public WeatherForecastResponse() {}
|
||||
|
||||
// Getters and Setters
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getUnits() {
|
||||
return units;
|
||||
}
|
||||
|
||||
public void setUnits(String units) {
|
||||
this.units = units;
|
||||
}
|
||||
|
||||
public List<DayForecast> getDailyForecast() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void setDailyForecas(List<DayForecast> forecast) {
|
||||
this.forecast = forecast;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package weather.model;
|
||||
|
||||
public class WeatherRequest {
|
||||
private String location;
|
||||
private int days = 7;
|
||||
private String units = "Farenheit";
|
||||
|
||||
public WeatherRequest() {}
|
||||
|
||||
// Getters and setters
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
public int getDays() {
|
||||
return days;
|
||||
}
|
||||
public void setDays(int days) {
|
||||
this.days = days;
|
||||
}
|
||||
public String getUnits() {
|
||||
return units;
|
||||
}
|
||||
public void setUnits(String units) {
|
||||
this.units = units;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue