Code Duplication    Length = 20-22 lines in 2 locations

main.py 2 locations

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