Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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