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
60 changes: 60 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.ironhack</groupId>
<artifactId>lab-java-springboot-fundamentals-solutions</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lab-java-springboot-fundamentals-solutions</name>
<description>lab-java-springboot-fundamentals-solutions</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ironhack.labjavaspringbootfundamentalssolutions;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class LabJavaSpringbootFundamentalsSolutionsApplication {

public static void main(String[] args) {
SpringApplication.run(LabJavaSpringbootFundamentalsSolutionsApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.ironhack.labjavaspringbootfundamentalssolutions.controller;

import com.ironhack.labjavaspringbootfundamentalssolutions.service.GreetingService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

//A GreetingService-service that contains a getGreeting-method

@RestController
public class GreetingController {

// Service variable name of Service
private final GreetingService greetingService;

//Constructor for Controller for DI
public GreetingController(GreetingService greetingService) {
this.greetingService = greetingService;
}

//Method
@GetMapping("/hello")
public String getGreeting(){
return greetingService.getGreeting();
}

@GetMapping("/hello/{name}")
public String getGreetingName(@PathVariable String name){
return greetingService.getGreetingName(name);
}

@GetMapping("/add/{num1}/{num2}")
public String addition(@PathVariable Double num1,@PathVariable Double num2){
Double sum = greetingService.addition(num1,num2);
return "The sum of this addition is: " + sum;
}

@GetMapping("/multiply/{num1}/{num2}")
public String multiplication(@PathVariable Double num1,@PathVariable Double num2){
Double multi = greetingService.multiplication(num1,num2);
return "The product of this multiplication is: " + multi;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.ironhack.labjavaspringbootfundamentalssolutions.controller;

import com.ironhack.labjavaspringbootfundamentalssolutions.service.TimeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping()
public class TimeController {

private final TimeService timeService;

public TimeController(TimeService timeService){
this.timeService = timeService;
}
//Methods
@GetMapping("/time")
public String getCurrentTime(){
return timeService.getCurrentTime();
}

@GetMapping("/date")
public String getCurrentDate(){
return timeService.getCurrentDate();
}

@GetMapping("/day")
public String getCurrentDay(){
return timeService.getCurrentDay();
}

@GetMapping("/all")
public String getCurrentAll(){
return timeService.getCurrentAll();
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.ironhack.labjavaspringbootfundamentalssolutions.controller;

import com.ironhack.labjavaspringbootfundamentalssolutions.model.Weather;
import com.ironhack.labjavaspringbootfundamentalssolutions.service.WeatherService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/weather")
public class WeatherController {

private final WeatherService weatherService;

public WeatherController(WeatherService weatherService) {
this.weatherService = weatherService;
}

//Methods
@GetMapping("/temperature")
public String getCurrentTemperature() {
Weather weather = weatherService.getRandomWeatherAll();
return "The current temperature is: "+ weather.getCurrentTemperature();
}

@GetMapping("/condition")
public String getWeatherCondition() {
Weather weather = weatherService.getRandomWeatherAll();
return "The weather is: "+ weather.getWeatherCondition();
}

@GetMapping("/wind")
public String getWindSpeed() {
Weather weather = weatherService.getRandomWeatherAll();
return "The speed of the wind is: "+ weather.getWindSpeed();
}

@GetMapping("/all")
public String getRandomWeatherAll() {
Weather weather = weatherService.getRandomWeatherAll();
return weather.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.ironhack.labjavaspringbootfundamentalssolutions.enums;

public enum WeatherCondition {
Sunny,Rainy, Cloudy, Windy;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.ironhack.labjavaspringbootfundamentalssolutions.model;

import com.ironhack.labjavaspringbootfundamentalssolutions.enums.WeatherCondition;

public class Weather {
private Double currentTemperature;
private WeatherCondition weatherCondition;
private Double windSpeed;

//Getters
public Double getCurrentTemperature() {
return currentTemperature;
}

public WeatherCondition getWeatherCondition() {
return weatherCondition;
}

public Double getWindSpeed() {
return windSpeed;
}

//Setters
public void setCurrentTemperature(Double currentTemperature) {
this.currentTemperature = currentTemperature;
}

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

public void setWindSpeed(Double windSpeed) {
this.windSpeed = windSpeed;
}

@Override
public String toString(){
return "The current temperature is: " + currentTemperature + "\n" +
"The weather is: " + weatherCondition + "\n" +
"The speed of the wind is: " + windSpeed;}

//Constructor Empty
public Weather(){
}

//Constructor All
public Weather(Double currentTemperature,WeatherCondition weatherCondition,Double windSpeed){
this.currentTemperature =currentTemperature;
this.weatherCondition=weatherCondition;
this.windSpeed =windSpeed;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.ironhack.labjavaspringbootfundamentalssolutions.service;

import org.springframework.stereotype.Service;

@Service
public class GreetingService {

// Methods
public String getGreeting() {
return "Hello World !";
}

public String getGreetingName(String name){
return "Hello " + name + " !";
}

public Double addition(Double num1,Double num2){
return num1 + num2;
}

public Double multiplication(Double num1,Double num2){
return num1 * num2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.ironhack.labjavaspringbootfundamentalssolutions.service;

import org.springframework.stereotype.Service;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalTime;

@Service
public class TimeService {

public String getCurrentTime(){
LocalTime time = LocalTime.now();
return "The current time is: " + time;
}

public String getCurrentDate(){
LocalDate date = LocalDate.now();
return "The current date is: " + date;
}

public String getCurrentDay(){
DayOfWeek day = LocalDate.now().getDayOfWeek();
return "The current day of the week is: " + day;
}

public String getCurrentAll(){
LocalTime time = LocalTime.now();
LocalDate date = LocalDate.now();
DayOfWeek day = LocalDate.now().getDayOfWeek();
return "The current time is: " + time + "\n"+
"The current date is: " + date + "\n"+
"The current day of the week is: " + day;
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.ironhack.labjavaspringbootfundamentalssolutions.service;

import com.ironhack.labjavaspringbootfundamentalssolutions.enums.WeatherCondition;
import com.ironhack.labjavaspringbootfundamentalssolutions.model.Weather;
import org.springframework.stereotype.Service;

@Service
public class WeatherService {

// We declare them outside if we dont want change for every refresh!!
//____________________________________________________________________
//WeatherCondition[] conditions = WeatherCondition.values();
//WeatherCondition condition = conditions[(int)(Math.random() * conditions.length)];


public Weather getRandomWeatherAll() {
double currentTemperature = -10 + Math.random() * 50;
double windSpeed = 0 + Math.random() * 100;

WeatherCondition[] conditions = WeatherCondition.values();
WeatherCondition condition = conditions[(int)(Math.random() * conditions.length)];

Weather weather = new Weather(
currentTemperature,
condition,
windSpeed
);
return weather;
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.application.name=lab-java-springboot-fundamentals-solutions
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ironhack.labjavaspringbootfundamentalssolutions;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class LabJavaSpringbootFundamentalsSolutionsApplicationTests {

@Test
void contextLoads() {
}

}