add controllers. add dummy data
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
package ua.com.dxrkness.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ua.com.dxrkness.model.Freight;
|
||||||
|
import ua.com.dxrkness.service.FreightService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/freight")
|
||||||
|
public class FreightController {
|
||||||
|
private final FreightService service;
|
||||||
|
|
||||||
|
public FreightController(FreightService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<Freight> getAll() {
|
||||||
|
return service.getAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package ua.com.dxrkness.controller;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/hello")
|
|
||||||
public class HelloController {
|
|
||||||
@GetMapping
|
|
||||||
public String hello(@RequestParam(name = "name", required = false) Optional<String> name) {
|
|
||||||
return "Hello, %s".formatted(name.orElse("world"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package ua.com.dxrkness.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ua.com.dxrkness.model.Route;
|
||||||
|
import ua.com.dxrkness.service.RouteService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/route")
|
||||||
|
public class RouteController {
|
||||||
|
private final RouteService service;
|
||||||
|
|
||||||
|
public RouteController(RouteService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<Route> getAll() {
|
||||||
|
return service.getAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package ua.com.dxrkness.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ua.com.dxrkness.model.Vehicle;
|
||||||
|
import ua.com.dxrkness.service.VehicleService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/vehicle")
|
||||||
|
public class VehicleController {
|
||||||
|
private final VehicleService service;
|
||||||
|
|
||||||
|
public VehicleController(VehicleService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<Vehicle> getAll() {
|
||||||
|
return service.getAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,14 @@
|
|||||||
package ua.com.dxrkness.repository;
|
package ua.com.dxrkness.repository;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import ua.com.dxrkness.model.Freight;
|
import ua.com.dxrkness.model.Freight;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public final class FreightRepository extends CrudRepository<Freight> {
|
public final class FreightRepository extends CrudRepository<Freight> {
|
||||||
|
@PostConstruct
|
||||||
|
private void initData() {
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
add(new Freight(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,22 @@
|
|||||||
package ua.com.dxrkness.repository;
|
package ua.com.dxrkness.repository;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
import ua.com.dxrkness.model.Freight;
|
||||||
import ua.com.dxrkness.model.Route;
|
import ua.com.dxrkness.model.Route;
|
||||||
|
import ua.com.dxrkness.model.Vehicle;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public final class RouteRepository extends CrudRepository<Route> {
|
public final class RouteRepository extends CrudRepository<Route> {
|
||||||
|
@PostConstruct
|
||||||
|
private void initData() {
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
add(new Route(i, new Vehicle(i), List.of(new Freight(i))));
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<Route> getByFreightId(long freightId) {
|
public Optional<Route> getByFreightId(long freightId) {
|
||||||
return STORAGE.stream()
|
return STORAGE.stream()
|
||||||
.filter(route -> route.freights().stream().anyMatch(freight -> freight.id() == freightId))
|
.filter(route -> route.freights().stream().anyMatch(freight -> freight.id() == freightId))
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
package ua.com.dxrkness.repository;
|
package ua.com.dxrkness.repository;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import ua.com.dxrkness.model.Vehicle;
|
import ua.com.dxrkness.model.Vehicle;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public final class VehicleRepository extends CrudRepository<Vehicle> {
|
public final class VehicleRepository extends CrudRepository<Vehicle> {
|
||||||
|
@PostConstruct
|
||||||
|
private void initData() {
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
add(new Vehicle(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user