Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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