Code Duplication    Length = 20-22 lines in 2 locations

main.py 2 locations

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