Code Duplication    Length = 20-20 lines in 2 locations

main.py 2 locations

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