Skip to content
Snippets Groups Projects
Commit 8c65289b authored by Mathieu.Vonlanthen's avatar Mathieu.Vonlanthen
Browse files

refactor(Relation3TiersController): use existsByIdOrThrowException in update method

parent eaf2caa9
Branches
Tags
1 merge request!362refactor(Relation3TiersController): use existsByIdOrThrowException in update method
...@@ -378,17 +378,19 @@ public abstract class Relation3TiersController<T extends Resource, V extends Res ...@@ -378,17 +378,19 @@ public abstract class Relation3TiersController<T extends Resource, V extends Res
*/ */
@PatchMapping(SolidifyConstants.URL_ID) @PatchMapping(SolidifyConstants.URL_ID)
public HttpEntity<List<J>> update(@PathVariable String parentid, @PathVariable String id, @RequestBody J joinResource) { public HttpEntity<List<J>> update(@PathVariable String parentid, @PathVariable String id, @RequestBody J joinResource) {
V childItem = this.childItemService.findOne(id); // Check if parents exist
List<J> joinResources = this.relationItemService.findAllRelations(parentid, childItem.getResId()); this.itemService.existsByIdOrThrowException(parentid);
final List<J> list = new ArrayList<>(); this.childItemService.existsByIdOrThrowException(id);
for (final J existingJoinResource : joinResources) {
J updatedJoinResource = this.relationItemService.completeJoinResourceRelations(joinResource, parentid, id, final List<J> savedRelationsList = new ArrayList<>();
this.relationItemService.getGrandChildResource(existingJoinResource).getResId()); for (final J existingJoinResource : this.relationItemService.findAllRelations(parentid, id)) {
final J savedJoinResource = this.relationItemService.saveRelation(updatedJoinResource); final String grandChildId = this.relationItemService.getGrandChildResource(existingJoinResource).getResId();
list.add(savedJoinResource); final J updatedJoinResource = this.relationItemService.completeJoinResourceRelations(joinResource, parentid, id, grandChildId);
final J savedRelation = this.relationItemService.saveRelation(updatedJoinResource);
savedRelationsList.add(savedRelation);
} }
if (!list.isEmpty()) { if (!savedRelationsList.isEmpty()) {
return new ResponseEntity<>(list, HttpStatus.CREATED); return new ResponseEntity<>(savedRelationsList, HttpStatus.CREATED);
} }
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment