Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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