Code Duplication    Length = 20-22 lines in 2 locations

main.py 2 locations

@@ 509-530 (lines=22) @@
506
        evc.sync()
507
        return JSONResponse("Operation successful", status_code=201)
508
509
    @rest("/v2/evc/metadata/{key}", methods=["DELETE"])
510
    @validate_openapi(spec)
511
    def bulk_delete_metadata(self, request: Request) -> JSONResponse:
512
        """Delete metada from a bulk of EVCs"""
513
        data = get_json_or_400(request, self.controller.loop)
514
        key = request.path_params["key"]
515
        circuit_ids = data.pop("circuit_ids")
516
        self.mongo_controller.update_evcs_metadata(
517
            circuit_ids, {key: ""}, "del"
518
        )
519
520
        fail_evcs = []
521
        for _id in circuit_ids:
522
            try:
523
                evc = self.circuits[_id]
524
                evc.remove_metadata(key)
525
            except KeyError:
526
                fail_evcs.append(_id)
527
528
        if fail_evcs:
529
            raise HTTPException(404, detail=fail_evcs)
530
        return JSONResponse("Operation successful")
531
532
    @rest("/v2/evc/{circuit_id}/metadata/{key}", methods=["DELETE"])
533
    def delete_metadata(self, request: Request) -> JSONResponse:
@@ 468-487 (lines=20) @@
465
                detail=f"circuit_id {circuit_id} not found."
466
            ) from error
467
468
    @rest("/v2/evc/metadata", methods=["POST"])
469
    @validate_openapi(spec)
470
    def bulk_add_metadata(self, request: Request) -> JSONResponse:
471
        """Add metadata to a bulk of EVCs."""
472
        data = get_json_or_400(request, self.controller.loop)
473
        circuit_ids = data.pop("circuit_ids")
474
475
        self.mongo_controller.update_evcs_metadata(circuit_ids, data, "add")
476
477
        fail_evcs = []
478
        for _id in circuit_ids:
479
            try:
480
                evc = self.circuits[_id]
481
                evc.extend_metadata(data)
482
            except KeyError:
483
                fail_evcs.append(_id)
484
485
        if fail_evcs:
486
            raise HTTPException(404, detail=fail_evcs)
487
        return JSONResponse("Operation successful", status_code=201)
488
489
    @rest("/v2/evc/{circuit_id}/metadata", methods=["POST"])
490
    @validate_openapi(spec)