Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

@@ 457-476 (lines=20) @@
454
        evc.sync()
455
        return JSONResponse("Operation successful", status_code=201)
456
457
    @rest("v2/evc/metadata/{key}", methods=["DELETE"])
458
    @validate_openapi(spec)
459
    def bulk_delete_metadata(self, request: Request) -> JSONResponse:
460
        """Delete metada from a bulk of EVCs"""
461
        data = get_json_or_400(request, self.controller.loop)
462
        key = request.path_params["key"]
463
        circuit_ids = data.pop("circuit_ids")
464
        self.mongo_controller.update_evcs(circuit_ids, {key: ""}, "del")
465
466
        fail_evcs = []
467
        for _id in circuit_ids:
468
            try:
469
                evc = self.circuits[_id]
470
                evc.remove_metadata(key)
471
            except KeyError:
472
                fail_evcs.append(_id)
473
474
        if fail_evcs:
475
            raise HTTPException(404, detail=fail_evcs)
476
        return JSONResponse("Operation successful")
477
478
    @rest("v2/evc/{circuit_id}/metadata/{key}", methods=["DELETE"])
479
    def delete_metadata(self, request: Request) -> JSONResponse:
@@ 416-435 (lines=20) @@
413
                detail=f"circuit_id {circuit_id} not found."
414
            ) from error
415
416
    @rest("v2/evc/metadata", methods=["POST"])
417
    @validate_openapi(spec)
418
    def bulk_add_metadata(self, request: Request) -> JSONResponse:
419
        """Add metadata to a bulk of EVCs."""
420
        data = get_json_or_400(request, self.controller.loop)
421
        circuit_ids = data.pop("circuit_ids")
422
423
        self.mongo_controller.update_evcs(circuit_ids, data, "add")
424
425
        fail_evcs = []
426
        for _id in circuit_ids:
427
            try:
428
                evc = self.circuits[_id]
429
                evc.extend_metadata(data)
430
            except KeyError:
431
                fail_evcs.append(_id)
432
433
        if fail_evcs:
434
            raise HTTPException(404, detail=fail_evcs)
435
        return JSONResponse("Operation successful", status_code=201)
436
437
    @rest("v2/evc/{circuit_id}/metadata", methods=["POST"])
438
    @validate_openapi(spec)