Code Duplication    Length = 20-22 lines in 2 locations

main.py 2 locations

@@ 524-545 (lines=22) @@
521
        evc.sync()
522
        return JSONResponse("Operation successful", status_code=201)
523
524
    @rest("/v2/evc/metadata/{key}", methods=["DELETE"])
525
    @validate_openapi(spec)
526
    def bulk_delete_metadata(self, request: Request) -> JSONResponse:
527
        """Delete metada from a bulk of EVCs"""
528
        data = get_json_or_400(request, self.controller.loop)
529
        key = request.path_params["key"]
530
        circuit_ids = data.pop("circuit_ids")
531
        self.mongo_controller.update_evcs_metadata(
532
            circuit_ids, {key: ""}, "del"
533
        )
534
535
        fail_evcs = []
536
        for _id in circuit_ids:
537
            try:
538
                evc = self.circuits[_id]
539
                evc.remove_metadata(key)
540
            except KeyError:
541
                fail_evcs.append(_id)
542
543
        if fail_evcs:
544
            raise HTTPException(404, detail=fail_evcs)
545
        return JSONResponse("Operation successful")
546
547
    @rest("/v2/evc/{circuit_id}/metadata/{key}", methods=["DELETE"])
548
    def delete_metadata(self, request: Request) -> JSONResponse:
@@ 483-502 (lines=20) @@
480
                detail=f"circuit_id {circuit_id} not found."
481
            ) from error
482
483
    @rest("/v2/evc/metadata", methods=["POST"])
484
    @validate_openapi(spec)
485
    def bulk_add_metadata(self, request: Request) -> JSONResponse:
486
        """Add metadata to a bulk of EVCs."""
487
        data = get_json_or_400(request, self.controller.loop)
488
        circuit_ids = data.pop("circuit_ids")
489
490
        self.mongo_controller.update_evcs_metadata(circuit_ids, data, "add")
491
492
        fail_evcs = []
493
        for _id in circuit_ids:
494
            try:
495
                evc = self.circuits[_id]
496
                evc.extend_metadata(data)
497
            except KeyError:
498
                fail_evcs.append(_id)
499
500
        if fail_evcs:
501
            raise HTTPException(404, detail=fail_evcs)
502
        return JSONResponse("Operation successful", status_code=201)
503
504
    @rest("/v2/evc/{circuit_id}/metadata", methods=["POST"])
505
    @validate_openapi(spec)