It's a web application. It should provide a service for entering data. Data is then evaluated and uses itself another service.
It was part of an interview process where I was given that task to solve. The feedback was that it was not sufficient and I got rejected. But I don't know what exactly they don't like. Could you please review it and give me improvement suggestions, please?
pom.xml
<?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>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>de.interview.fizzbuzz</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Controller
package de.interview.fizzbuzz.demo.controller;
import de.interview.fizzbuzz.demo.model.FizzBuzzInput;
import de.interview.fizzbuzz.demo.model.FizzBuzzOutput;
import de.interview.fizzbuzz.demo.model.WorldClock;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import javax.validation.Valid;
import java.util.Collection;
import java.util.SortedMap;
import java.util.TreeMap;
@NoArgsConstructor
@RestController
@RequestMapping("/api")
public class FizzBuzzController {
private final Logger log = LoggerFactory.getLogger(FizzBuzzController.class);
private SortedMap<Integer, FizzBuzzOutput> fizzBuzzOutputsRepo = new TreeMap<Integer, FizzBuzzOutput>();
@GetMapping("/allFizzBuzzItems")
public Collection<FizzBuzzOutput> allFizzBuzzItems() {
System.out.println(fizzBuzzOutputsRepo.values());
return fizzBuzzOutputsRepo.values();
}
@PutMapping("/fizzbuzz")
public void createFizzBuzzItem(@Valid @RequestBody @NonNull FizzBuzzInput fizzBuzzInput) {
Integer input = Integer.parseInt(fizzBuzzInput.getValue());
if (input <= 0) {
return;
}
String value = BusinessLogic.fizzBuzzOf(Integer.parseInt(fizzBuzzInput.getValue()));
String timestamp = getTimestampFrom("http://worldclockapi.com/api/json/cet/now");
FizzBuzzOutput fizzBuzzOutput = new FizzBuzzOutput(input, value, timestamp);
fizzBuzzOutputsRepo.put(input, fizzBuzzOutput);
}
// delete all
@DeleteMapping("/fizzbuzz/all")
public void deleteAllFizzBuzzItems() {
fizzBuzzOutputsRepo.clear();
}
public String getTimestampFrom(String serviceURL) {
RestTemplate restTemplate = new RestTemplate();
WorldClock result = restTemplate.getForObject(serviceURL, WorldClock.class);
return result.getCurrentDateTime();
}
}
The whole project: https://github.com/kodingreview/1