Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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