Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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