Skip to content

Commit 58786ae

Browse files
committed
feat: implement dual-write synchronization for team creation invite codes and update watchlist collection naming
1 parent aba75f3 commit 58786ae

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

todo/repositories/team_creation_invite_code_repository.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@ def validate_and_consume_code(cls, code: str, used_by: str) -> Optional[dict]:
3333
{"$set": {"is_used": True, "used_by": used_by, "used_at": current_time.isoformat()}},
3434
return_document=True,
3535
)
36+
37+
if result:
38+
# Sync the update to PostgreSQL
39+
dual_write_service = EnhancedDualWriteService()
40+
invite_code_data = {
41+
"code": result["code"],
42+
"description": result.get("description"),
43+
"is_used": True,
44+
"created_by": str(result["created_by"]),
45+
"used_by": str(used_by),
46+
"created_at": result.get("created_at"),
47+
"used_at": current_time,
48+
}
49+
50+
dual_write_success = dual_write_service.update_document(
51+
collection_name="team_creation_invite_codes",
52+
data=invite_code_data,
53+
mongo_id=str(result["_id"])
54+
)
55+
56+
if not dual_write_success:
57+
import logging
58+
logger = logging.getLogger(__name__)
59+
logger.warning(f"Failed to sync team creation invite code update {result['_id']} to Postgres")
60+
3661
return result
3762
except Exception as e:
3863
raise Exception(f"Error validating and consuming code: {e}")

todo/repositories/watchlist_repository.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def create(cls, watchlist_model: WatchlistModel) -> WatchlistModel:
5353
}
5454

5555
dual_write_success = dual_write_service.create_document(
56-
collection_name="watchlist", data=watchlist_data, mongo_id=str(watchlist_model.id)
56+
collection_name="watchlists", data=watchlist_data, mongo_id=str(watchlist_model.id)
5757
)
5858

5959
if not dual_write_success:
@@ -337,7 +337,7 @@ def update(cls, taskId: ObjectId, isActive: bool, userId: ObjectId) -> dict:
337337
}
338338

339339
dual_write_success = dual_write_service.update_document(
340-
collection_name="watchlist", data=watchlist_data, mongo_id=str(current_watchlist.id)
340+
collection_name="watchlists", data=watchlist_data, mongo_id=str(current_watchlist.id)
341341
)
342342

343343
if not dual_write_success:

0 commit comments

Comments
 (0)