Code Duplication    Length = 20-22 lines in 2 locations

main.py 2 locations

@@ 507-528 (lines=22) @@
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_metadata(
515
            circuit_ids, {key: ""}, "del"
516
        )
517
518
        fail_evcs = []
519
        for _id in circuit_ids:
520
            try:
521
                evc = self.circuits[_id]
522
                evc.remove_metadata(key)
523
            except KeyError:
524
                fail_evcs.append(_id)
525
526
        if fail_evcs:
527
            raise HTTPException(404, detail=fail_evcs)
528
        return JSONResponse("Operation successful")
529
530
    @rest("/v2/evc/{circuit_id}/metadata/{key}", methods=["DELETE"])
531
    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_metadata(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)