Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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