Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

@@ 487-506 (lines=20) @@
484
        evc.sync()
485
        return JSONResponse("Operation successful", status_code=201)
486
487
    @rest("v2/evc/metadata/{key}", methods=["DELETE"])
488
    @validate_openapi(spec)
489
    def bulk_delete_metadata(self, request: Request) -> JSONResponse:
490
        """Delete metada from a bulk of EVCs"""
491
        data = get_json_or_400(request, self.controller.loop)
492
        key = request.path_params["key"]
493
        circuit_ids = data.pop("circuit_ids")
494
        self.mongo_controller.update_evcs(circuit_ids, {key: ""}, "del")
495
496
        fail_evcs = []
497
        for _id in circuit_ids:
498
            try:
499
                evc = self.circuits[_id]
500
                evc.remove_metadata(key)
501
            except KeyError:
502
                fail_evcs.append(_id)
503
504
        if fail_evcs:
505
            raise HTTPException(404, detail=fail_evcs)
506
        return JSONResponse("Operation successful")
507
508
    @rest("v2/evc/{circuit_id}/metadata/{key}", methods=["DELETE"])
509
    def delete_metadata(self, request: Request) -> JSONResponse:
@@ 446-465 (lines=20) @@
443
                detail=f"circuit_id {circuit_id} not found."
444
            ) from error
445
446
    @rest("v2/evc/metadata", methods=["POST"])
447
    @validate_openapi(spec)
448
    def bulk_add_metadata(self, request: Request) -> JSONResponse:
449
        """Add metadata to a bulk of EVCs."""
450
        data = get_json_or_400(request, self.controller.loop)
451
        circuit_ids = data.pop("circuit_ids")
452
453
        self.mongo_controller.update_evcs(circuit_ids, data, "add")
454
455
        fail_evcs = []
456
        for _id in circuit_ids:
457
            try:
458
                evc = self.circuits[_id]
459
                evc.extend_metadata(data)
460
            except KeyError:
461
                fail_evcs.append(_id)
462
463
        if fail_evcs:
464
            raise HTTPException(404, detail=fail_evcs)
465
        return JSONResponse("Operation successful", status_code=201)
466
467
    @rest("v2/evc/{circuit_id}/metadata", methods=["POST"])
468
    @validate_openapi(spec)