Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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