Code Duplication    Length = 20-22 lines in 2 locations

main.py 2 locations

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