Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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