Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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