Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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