Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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