Skip to content

Move multi-DB operations from WordService into WordRepository#4190

Merged
imnasnainaec merged 2 commits intomongo-transactionsfrom
copilot/sub-pr-4189
Mar 4, 2026
Merged

Move multi-DB operations from WordService into WordRepository#4190
imnasnainaec merged 2 commits intomongo-transactionsfrom
copilot/sub-pr-4189

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

Part of coordinating atomic updates to FrontierCollection and WordsCollection via transactions. Goal 2 of the PR: move all multi-collection database logic out of the service layer and into new WordRepository methods (which will be wrapped in transactions in Goal 4).

New IWordRepository / WordRepository methods

// Word replacement: insert newWord into Words+Frontier, delete oldWordId from Frontier
Task<Word> CreateAndDeleteFrontier(Word newWord, string oldWordId);

// Soft-delete: insert deletedWord into Words only, delete wordId from Frontier
Task<Word> AddAndDeleteFrontier(Word deletedWord, string wordId);

WordService refactors

  • Update: replaced Create(userId, word) + DeleteFrontier(oldWordId) with _wordRepo.CreateAndDeleteFrontier(PrepEditedData(userId, word), oldWordId)
  • DeleteFrontierWord: replaced Add(userId, word) + DeleteFrontier(wordId) with _wordRepo.AddAndDeleteFrontier(PrepEditedData(userId, word), wordId)
  • Removed now-unused private WordService.Add(string userId, Word word) helper

Scope

MergeService needs no direct changes — it delegates to the refactored WordService methods. WordRepositoryMock has mock implementations of both new methods. Wrapping the new WordRepository methods in transactions is deferred to Goal 4.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


This change is Reviewable

Copilot AI changed the title [WIP] Add transactions to coordinate updates to collections Plan: move multi-DB operations from MergeService/WordService into WordRepository Mar 3, 2026
@imnasnainaec
Copy link
Collaborator

@copilot Execute the plan.

Copy link
Contributor Author

Copilot AI commented Mar 4, 2026

@copilot Execute the plan.

Done in commit 0e7b6e0. Changes made:

  • IWordRepository: Added CreateAndDeleteFrontier(Word newWord, string oldWordId) and AddAndDeleteFrontier(Word deletedWord, string wordId)
  • WordRepository: Implemented both — each encapsulates the two DB ops that were previously split across the service layer (ready to be wrapped in a transaction in Goal 4)
  • WordService.Update: replaced Create(userId, word) + DeleteFrontier(...) with _wordRepo.CreateAndDeleteFrontier(PrepEditedData(userId, word), oldWordId)
  • WordService.DeleteFrontierWord: replaced Add(userId, word) + DeleteFrontier(...) with _wordRepo.AddAndDeleteFrontier(PrepEditedData(userId, word), wordId)
  • WordService: removed the now-unused private Add(string userId, Word word) helper
  • WordRepositoryMock: added mock implementations of both new methods

All 46 existing tests pass unchanged.

Copilot AI changed the title Plan: move multi-DB operations from MergeService/WordService into WordRepository Move multi-DB operations from WordService into WordRepository Mar 4, 2026
@imnasnainaec imnasnainaec marked this pull request as ready for review March 4, 2026 16:34
@imnasnainaec imnasnainaec merged commit e177525 into mongo-transactions Mar 4, 2026
1 check was pending
@imnasnainaec imnasnainaec deleted the copilot/sub-pr-4189 branch March 4, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants