Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

@@ 454-473 (lines=20) @@
451
        evc.sync()
452
        return JSONResponse("Operation successful", status_code=201)
453
454
    @rest("v2/evc/metadata/{key}", methods=["DELETE"])
455
    @validate_openapi(spec)
456
    def bulk_delete_metadata(self, request: Request) -> JSONResponse:
457
        """Delete metada from a bulk of EVCs"""
458
        data = get_json_or_400(request)
459
        key = request.path_params["key"]
460
        circuit_ids = data.pop("circuit_ids")
461
        self.mongo_controller.update_evcs(circuit_ids, {key: ""}, "del")
462
463
        fail_evcs = []
464
        for _id in circuit_ids:
465
            try:
466
                evc = self.circuits[_id]
467
                evc.remove_metadata(key)
468
            except KeyError:
469
                fail_evcs.append(_id)
470
471
        if fail_evcs:
472
            raise HTTPException(404, detail=fail_evcs)
473
        return JSONResponse("Operation successful")
474
475
    @rest("v2/evc/{circuit_id}/metadata/{key}", methods=["DELETE"])
476
    def delete_metadata(self, request: Request) -> JSONResponse:
@@ 413-432 (lines=20) @@
410
                detail=f"circuit_id {circuit_id} not found."
411
            ) from error
412
413
    @rest("v2/evc/metadata", methods=["POST"])
414
    @validate_openapi(spec)
415
    def bulk_add_metadata(self, request: Request) -> JSONResponse:
416
        """Add metadata to a bulk of EVCs."""
417
        data = get_json_or_400(request)
418
        circuit_ids = data.pop("circuit_ids")
419
420
        self.mongo_controller.update_evcs(circuit_ids, data, "add")
421
422
        fail_evcs = []
423
        for _id in circuit_ids:
424
            try:
425
                evc = self.circuits[_id]
426
                evc.extend_metadata(data)
427
            except KeyError:
428
                fail_evcs.append(_id)
429
430
        if fail_evcs:
431
            raise HTTPException(404, detail=fail_evcs)
432
        return JSONResponse("Operation successful", status_code=201)
433
434
    @rest("v2/evc/{circuit_id}/metadata", methods=["POST"])
435
    @validate_openapi(spec)