Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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