Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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