feat(cw2): /api/v1/droneDetails impl
This commit is contained in:
parent
3c96f9d5af
commit
44d510ddd4
7 changed files with 141 additions and 14 deletions
29
ilp-cw-api/[GET] droneDetails/drone 1 details.bru
Normal file
29
ilp-cw-api/[GET] droneDetails/drone 1 details.bru
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
meta {
|
||||||
|
name: drone 1 details
|
||||||
|
type: http
|
||||||
|
seq: 1
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{API_BASE}}/droneDetails/1
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {
|
||||||
|
res.body.id: eq "1"
|
||||||
|
res.body.capability.capacity: eq 4.0
|
||||||
|
res.body.capability.heating: eq true
|
||||||
|
}
|
||||||
|
|
||||||
|
tests {
|
||||||
|
test("Status code is 200", function() {
|
||||||
|
expect(res.status).to.equal(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
settings {
|
||||||
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
|
}
|
||||||
29
ilp-cw-api/[GET] droneDetails/drone 10 details.bru
Normal file
29
ilp-cw-api/[GET] droneDetails/drone 10 details.bru
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
meta {
|
||||||
|
name: drone 10 details
|
||||||
|
type: http
|
||||||
|
seq: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{API_BASE}}/droneDetails/10
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {
|
||||||
|
res.body.id: eq "10"
|
||||||
|
res.body.capability.capacity: eq 12.0
|
||||||
|
res.body.capability.heating: eq false
|
||||||
|
}
|
||||||
|
|
||||||
|
tests {
|
||||||
|
test("Status code is 200", function() {
|
||||||
|
expect(res.status).to.equal(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
settings {
|
||||||
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
|
}
|
||||||
23
ilp-cw-api/[GET] droneDetails/drone 11 details.bru
Normal file
23
ilp-cw-api/[GET] droneDetails/drone 11 details.bru
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
meta {
|
||||||
|
name: drone 11 details
|
||||||
|
type: http
|
||||||
|
seq: 3
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{API_BASE}}/droneDetails/11
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
tests {
|
||||||
|
test("Status code is 404", function() {
|
||||||
|
expect(res.status).to.equal(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
settings {
|
||||||
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
|
}
|
||||||
23
ilp-cw-api/[GET] droneDetails/drone NaN details.bru
Normal file
23
ilp-cw-api/[GET] droneDetails/drone NaN details.bru
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
meta {
|
||||||
|
name: drone NaN details
|
||||||
|
type: http
|
||||||
|
seq: 4
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{API_BASE}}/droneDetails/droneNaN
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
tests {
|
||||||
|
test("Status code is 404", function() {
|
||||||
|
expect(res.status).to.equal(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
settings {
|
||||||
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
|
}
|
||||||
8
ilp-cw-api/[GET] droneDetails/folder.bru
Normal file
8
ilp-cw-api/[GET] droneDetails/folder.bru
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
meta {
|
||||||
|
name: [GET] droneDetails
|
||||||
|
seq: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
auth {
|
||||||
|
mode: inherit
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package io.github.js0ny.ilp_coursework.controller;
|
package io.github.js0ny.ilp_coursework.controller;
|
||||||
|
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import io.github.js0ny.ilp_coursework.service.DroneInfoService;
|
import io.github.js0ny.ilp_coursework.service.DroneInfoService;
|
||||||
|
|
@ -43,15 +44,15 @@ public class DroneController {
|
||||||
return droneService.dronesWithCooling(state);
|
return droneService.dronesWithCooling(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @GetMapping("/droneDetails/{id}")
|
@GetMapping("/droneDetails/{id}")
|
||||||
// public DroneDto getDroneDetail(@PathVariable int id) {
|
public ResponseEntity<DroneDto> getDroneDetail(@PathVariable String id) {
|
||||||
// String droneUrl = baseUrl + "drones";
|
try {
|
||||||
//
|
DroneDto drone = droneService.droneDetail(id);
|
||||||
// DroneDto[] drones = restTemplate.getForObject(droneUrl, DroneDto[].class);
|
return ResponseEntity.ok(drone);
|
||||||
//
|
} catch (IllegalArgumentException ex) {
|
||||||
// return new DroneDto();
|
return ResponseEntity.notFound().build();
|
||||||
//
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
@PostMapping("queryAvailableDrones")
|
@PostMapping("queryAvailableDrones")
|
||||||
public int queryAvailableDrones() {
|
public int queryAvailableDrones() {
|
||||||
|
|
|
||||||
|
|
@ -56,18 +56,32 @@ public class DroneInfoService {
|
||||||
toArray();
|
toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This is function is WIP
|
/**
|
||||||
public Stream<DroneDto> droneDetail(int id) {
|
* Return a {@link DroneDto}-style json data structure with the given {@code id}
|
||||||
|
*
|
||||||
|
* @param id The id of the drone
|
||||||
|
* @return drone json body of given id
|
||||||
|
* @throws NullPointerException when cannot fetch available drones from remote
|
||||||
|
* @throws IllegalArgumentException when drone with given {@code id} cannot be found
|
||||||
|
* this should lead to a 404
|
||||||
|
*/
|
||||||
|
public DroneDto droneDetail(String id) {
|
||||||
String droneUrl = baseUrl + dronesEndpoint;
|
String droneUrl = baseUrl + dronesEndpoint;
|
||||||
|
|
||||||
DroneDto[] drones = restTemplate.getForObject(droneUrl, DroneDto[].class);
|
DroneDto[] drones = restTemplate.getForObject(droneUrl, DroneDto[].class);
|
||||||
|
|
||||||
if (drones == null) {
|
if (drones == null) {
|
||||||
throw new IllegalArgumentException("drone with that ID cannot be found");
|
throw new NullPointerException("drone cannot be found");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Arrays.stream(drones).
|
for (var drone : drones) {
|
||||||
filter(drone -> Integer.parseInt(String.valueOf(drone.id())) == id);
|
if (drone.id().equals(id)) {
|
||||||
|
return drone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("drone with that ID cannot be found");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue