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,13 @@
package com.workshop.labspringbootfundamentals;

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

@SpringBootApplication
public class LabSpringBootFundamentalsApplication {

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.workshop.labspringbootfundamentals.controller;

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

@RestController
public class GreetingController {

@GetMapping("/hello")
public String sayHello() {
return "Hello World!";
}

@GetMapping("/hello/{name}")
public String sayHelloName(@PathVariable String name) {
return "Hello " + name + "!";
}

@GetMapping("/add/{num1}/{num2}")
public int add(@PathVariable int num1, @PathVariable int num2) {
return num1 + num2;
}

@GetMapping("/multiply/{num1}/{num2}")
public int multiply(@PathVariable int num1, @PathVariable int num2) {
return num1 * num2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.workshop.labspringbootfundamentals.controller;

import com.workshop.labspringbootfundamentals.model.Time;
import com.workshop.labspringbootfundamentals.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;
}

@GetMapping("/time")
public String getTime() {
return timeService.getTime();
}

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

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

@GetMapping("/all")
public String getAll() {
return timeService.getTime() + timeService.getDate() + timeService.getCurrentDayOfWeek();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.workshop.labspringbootfundamentals.controller;

import com.workshop.labspringbootfundamentals.model.Weather;
import com.workshop.labspringbootfundamentals.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;
}

@GetMapping("/temperature")
public int getTemperature() {
return weatherService.getTemperature();
}

@GetMapping("/condition")
public String getCondition() {
return weatherService.getCondition();
}

@GetMapping("/wind")
public int getWindSpeed() {
return weatherService.getWindSpeed();
}

@GetMapping("/all")
public Weather getAll(){
return weatherService.getAll();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.workshop.labspringbootfundamentals.model;

public class Time {

private String time;
private String date;
private String day;

public Time(String time, String date, String day) {
this.time = time;
this.date = date;
this.day = day;
}

public String getTime() {
return time;
}

public String getDate() {
return date;
}

public String getDay() {
return day;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.workshop.labspringbootfundamentals.model;

public class Weather {
private int temperature;
private String condition;
private int windspeed;

public Weather(int temperature, String condition, int speed) {
this.temperature = temperature;
this.condition = condition;
this.windspeed = speed;
}

public int getTemperature() {
return temperature;
}

public void setTemperature(int temperature) {
this.temperature = temperature;
}

public String getCondition() {
return condition;
}

public void setCondition(String condition) {
this.condition = condition;
}

public int getWindspeed() {
return windspeed;
}

public void setWindspeed(int windspeed) {
this.windspeed = windspeed;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.workshop.labspringbootfundamentals.service;

import org.springframework.stereotype.Service;

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

@Service
public class TimeService {

public String getTime() {
return LocalTime.now().toString();
}

public String getDate() {
return LocalDate.now().toString();
}

public String getCurrentDayOfWeek() {
return LocalDate.now().getDayOfWeek().toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.workshop.labspringbootfundamentals.service;

import com.workshop.labspringbootfundamentals.model.Weather;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class WeatherService {

private final Random random = new Random();

private int temp = random.nextInt(-10, 41);
private int condition = random.nextInt(0, 4);
private int windSpeed = random.nextInt(0, 101);

public int getTemperature() {
return temp;
}

public String getCondition() {

if (condition == 0) {
return "Sunny";
} else if (condition == 1) {
return "Rainy";
} else if (condition == 2) {
return "Cloudy";
} else {
return "Windy";
}
}

public int getWindSpeed() {
return windSpeed;
}

public Weather getAll() {
return new Weather(
getTemperature(),
getCondition(),
getWindSpeed()
);
}
}
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=LabSpringBootFundamentals
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.workshop.labspringbootfundamentals;

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

@SpringBootTest
class LabSpringBootFundamentalsApplicationTests {

@Test
void contextLoads() {
}

}