Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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