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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target/
.idea/
${project.build.directory}/

*.iml
*.log
50 changes: 50 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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.2.5</version>
<relativePath/>
</parent>

<groupId>com.ironhack</groupId>
<artifactId>lab-springboot-fundamentals</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lab-springboot-fundamentals</name>
<description>LAB SpringBoot Fundamentals - Ironhack</description>

<properties>
<java.version>17</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>
14 changes: 14 additions & 0 deletions src/main/java/com/ironhack/lab/LabApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ironhack.lab;

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

/**
* LabApplication — Entry point for the Spring Boot application.
*/
@SpringBootApplication
public class LabApplication {
public static void main(String[] args) {
SpringApplication.run(LabApplication.class, args);
}
}
49 changes: 49 additions & 0 deletions src/main/java/com/ironhack/lab/controller/GreetingController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.ironhack.lab.controller;

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

/**
* GreetingController — Handles basic greeting and math endpoints.
* Task 2 of the lab.
*/
@RestController
public class GreetingController {

/**
* GET /hello
* Returns a static greeting message.
*/
@GetMapping("/hello")
public String hello() {
return "Hello World!";
}

/**
* GET /hello/{name}
* Returns a personalized greeting using a path variable.
*/
@GetMapping("/hello/{name}")
public String helloName(@PathVariable String name) {
return "Hello " + name + "!";
}

/**
* GET /add/{num1}/{num2}
* Returns the sum of two numbers.
*/
@GetMapping("/add/{num1}/{num2}")
public String add(@PathVariable double num1, @PathVariable double num2) {
return num1 + " + " + num2 + " = " + (num1 + num2);
}

/**
* GET /multiply/{num1}/{num2}
* Returns the product of two numbers.
*/
@GetMapping("/multiply/{num1}/{num2}")
public String multiply(@PathVariable double num1, @PathVariable double num2) {
return num1 + " x " + num2 + " = " + (num1 * num2);
}
}
59 changes: 59 additions & 0 deletions src/main/java/com/ironhack/lab/controller/TimeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.ironhack.lab.controller;

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

/**
* TimeController — Exposes time endpoints using TimeService.
* Uses constructor injection (no @Autowired).
* Task 6 of the lab.
*/
@RestController
public class TimeController {

private final TimeService timeService;

// Constructor injection
public TimeController(TimeService timeService) {
this.timeService = timeService;
}

/**
* GET /time
* Returns the current time.
*/
@GetMapping("/time")
public String getTime() {
return "Current time: " + timeService.getCurrentTime();
}

/**
* GET /date
* Returns the current date.
*/
@GetMapping("/date")
public String getDate() {
return "Current date: " + timeService.getCurrentDate();
}

/**
* GET /day
* Returns the current day of the week.
*/
@GetMapping("/day")
public String getDay() {
return "Current day: " + timeService.getCurrentDayOfWeek();
}

/**
* GET /all
* Returns all time information in a single response.
*/
@GetMapping("/all")
public String getAll() {
return "Time: " + timeService.getCurrentTime() + " | " +
"Date: " + timeService.getCurrentDate() + " | " +
"Day: " + timeService.getCurrentDayOfWeek();
}
}
61 changes: 61 additions & 0 deletions src/main/java/com/ironhack/lab/controller/WeatherController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.ironhack.lab.controller;

import com.ironhack.lab.service.WeatherService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* WeatherController — Exposes weather endpoints using WeatherService.
* Uses constructor injection (no @Autowired).
* Task 4 of the lab.
*/
@RestController
@RequestMapping("/weather")
public class WeatherController {

private final WeatherService weatherService;

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

/**
* GET /weather/temperature
* Returns the current simulated temperature.
*/
@GetMapping("/temperature")
public String getTemperature() {
return "Current temperature: " + weatherService.getCurrentTemperature() + "°C";
}

/**
* GET /weather/condition
* Returns the current simulated weather condition.
*/
@GetMapping("/condition")
public String getCondition() {
return "Current condition: " + weatherService.getWeatherCondition();
}

/**
* GET /weather/wind
* Returns the current simulated wind speed.
*/
@GetMapping("/wind")
public String getWind() {
return "Current wind speed: " + weatherService.getWindSpeed() + " km/h";
}

/**
* GET /weather/all
* Returns all weather information in a single response.
*/
@GetMapping("/all")
public String getAll() {
return "Temperature: " + weatherService.getCurrentTemperature() + "°C | " +
"Condition: " + weatherService.getWeatherCondition() + " | " +
"Wind: " + weatherService.getWindSpeed() + " km/h";
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/ironhack/lab/service/TimeService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.ironhack.lab.service;

import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
* TimeService — Provides current time, date and day of the week.
* Task 5 of the lab.
*/
@Service
public class TimeService {

/**
* Returns the current time in HH:mm:ss format.
*/
public String getCurrentTime() {
return LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
}

/**
* Returns the current date in yyyy-MM-dd format.
*/
public String getCurrentDate() {
return LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}

/**
* Returns the current day of the week (e.g. MONDAY).
*/
public String getCurrentDayOfWeek() {
return LocalDate.now().getDayOfWeek().toString();
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/ironhack/lab/service/WeatherService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.ironhack.lab.service;

import org.springframework.stereotype.Service;
import java.util.Random;

/**
* WeatherService — Simulates weather data using random values.
* Task 3 of the lab.
*/
@Service
public class WeatherService {

private final Random random = new Random();

/**
* Returns a simulated temperature between -10 and 40 degrees.
*/
public int getCurrentTemperature() {
return random.nextInt(51) - 10; // range: -10 to 40
}

/**
* Returns a randomly selected weather condition.
*/
public String getWeatherCondition() {
String[] conditions = {"Sunny", "Rainy", "Cloudy", "Windy"};
return conditions[random.nextInt(conditions.length)];
}

/**
* Returns a simulated wind speed between 0 and 100 km/h.
*/
public int getWindSpeed() {
return random.nextInt(101); // range: 0 to 100
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
spring.application.name=lab-springboot-fundamentals
server.port=8080