Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

@@ 474-493 (lines=20) @@
471
        evc.sync()
472
        return JSONResponse("Operation successful", status_code=201)
473
474
    @rest("v2/evc/metadata/{key}", methods=["DELETE"])
475
    @validate_openapi(spec)
476
    def bulk_delete_metadata(self, request: Request) -> JSONResponse:
477
        """Delete metada from a bulk of EVCs"""
478
        data = get_json_or_400(request, self.controller.loop)
479
        key = request.path_params["key"]
480
        circuit_ids = data.pop("circuit_ids")
481
        self.mongo_controller.update_evcs(circuit_ids, {key: ""}, "del")
482
483
        fail_evcs = []
484
        for _id in circuit_ids:
485
            try:
486
                evc = self.circuits[_id]
487
                evc.remove_metadata(key)
488
            except KeyError:
489
                fail_evcs.append(_id)
490
491
        if fail_evcs:
492
            raise HTTPException(404, detail=fail_evcs)
493
        return JSONResponse("Operation successful")
494
495
    @rest("v2/evc/{circuit_id}/metadata/{key}", methods=["DELETE"])
496
    def delete_metadata(self, request: Request) -> JSONResponse:
@@ 433-452 (lines=20) @@
430
                detail=f"circuit_id {circuit_id} not found."
431
            ) from error
432
433
    @rest("v2/evc/metadata", methods=["POST"])
434
    @validate_openapi(spec)
435
    def bulk_add_metadata(self, request: Request) -> JSONResponse:
436
        """Add metadata to a bulk of EVCs."""
437
        data = get_json_or_400(request, self.controller.loop)
438
        circuit_ids = data.pop("circuit_ids")
439
440
        self.mongo_controller.update_evcs(circuit_ids, data, "add")
441
442
        fail_evcs = []
443
        for _id in circuit_ids:
444
            try:
445
                evc = self.circuits[_id]
446
                evc.extend_metadata(data)
447
            except KeyError:
448
                fail_evcs.append(_id)
449
450
        if fail_evcs:
451
            raise HTTPException(404, detail=fail_evcs)
452
        return JSONResponse("Operation successful", status_code=201)
453
454
    @rest("v2/evc/{circuit_id}/metadata", methods=["POST"])
455
    @validate_openapi(spec)