Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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