Code Duplication    Length = 20-22 lines in 2 locations

main.py 2 locations

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