Skip to content

Instantly share code, notes, and snippets.

@walidum
Last active May 4, 2021 11:22
Show Gist options
  • Save walidum/25c329c2e112982e8c34edd7a9cc52f4 to your computer and use it in GitHub Desktop.
Save walidum/25c329c2e112982e8c34edd7a9cc52f4 to your computer and use it in GitHub Desktop.
ProvicesController
import com.meyl.spring.reactor.demo.model.Province;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
public class ProvicesController {
private static List<Province> provinces = new ArrayList<>();
static {
provinces.add(Province._new(16, "Algiers"));
provinces.add(Province._new(19, "Setif"));
provinces.add(Province._new(9, "Blida"));
provinces.add(Province._new(23, "Annaba"));
provinces.add(Province._new(31, "Oran"));
provinces.add(Province._new(39, "El Oued"));
}
@GetMapping("/province/{id}")
public Province getState(@PathVariable final int id) throws InterruptedException {
Thread.sleep(2 * 1000);
return provinces.stream()
.filter((p) -> p.getId() == id)
.findFirst()
.orElse(Province._new());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment