Skip to content

Add a delete network endpoint. #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
Expand Up @@ -73,4 +73,12 @@ public ResponseEntity<MatchedRule> getNetworkMatches(@PathVariable("networkUuid"
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(networkService.getNetworkMatches(networkUuid, ruleToMatch));
}

@DeleteMapping(path = "/{networkUuid}")
@Operation(summary = "delete the network")
@ApiResponse(responseCode = "200", description = "Network deleted")
public ResponseEntity<UUID> deleteNetwork(@PathVariable("networkUuid") UUID networkUuid) {
UUID deletedNetworkUuid = networkService.deleteNetwork(networkUuid);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(deletedNetworkUuid);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface NetworkService {
Network getNetwork(UUID networkUuid);

MatchedRule getNetworkMatches(UUID networkUuid, RuleToMatch ruleToMatch);

UUID deleteNetwork(UUID networkUuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ public NetworkValues getNetworkValuesFromExistingNetwork(UUID networkUuid) {
return new NetworkValues(networkUuid, equipmentValuesList);
}

@Override
public UUID deleteNetwork(UUID networkUuid) {
networkRepository.deleteById(networkUuid);
networkStoreService.deleteNetwork(networkUuid);
return networkUuid;
}

private void setPropertyMap(HashMap<String, Set<String>> propertyMap, String value, String propertyName) {
if (propertyMap.containsKey(propertyName)) {
Set<String> propertyValues = propertyMap.get(propertyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public void fileTest() throws Exception {
NetworkEntity actualEntity = savedNetworks.get(0);
assertTrue(expectedEntity.getNetworkId().equals(actualEntity.getNetworkId()) && expectedEntity.getNetworkName().equals(actualEntity.getNetworkName()));

mvc.perform(MockMvcRequestBuilders.delete("/network/" + networkUUID)).andExpect(status().isOk());
savedNetworks = networkRepository.findAll();
assertEquals(0, savedNetworks.size());

}

private String network(UUID id, String name) {
Expand Down