I have two aggregate roots: User and Sketches.
In my application, users can clap for a Sketch. In the service layer, it looks as so:
class SketchService { constructor ({ SketchRepository }) { this.sketchRepository = SketchRepository } async addClaps ({ sketchID, author, count }) { const sketch = await this.sketchRepository.findById(sketchID) sketch.addClaps(author, count) await this.sketchRepository.update(sketch) } // other use cases // ... This works great. But what if every User has a karma and every time a user claps for a sketch, the author should receive +1 karma?
Now the issue is that SketchService would have to now contain UserRepository; I am not really sure if that's a good thing.
Then it would look like this:
class SketchService { constructor ({ SketchRepository, UserRepository }) { this.sketchRepository = SketchRepository this.userRepository = UserRepository } async addClaps ({ sketchID, author, count }) { const sketch = await this.sketchRepository.findById(sketchID) const sketchAuthor = await this.userRepository.findByUsername(sketch.author) sketch.addClaps(author, count) sketchAuthor.addKarma(count) await this.sketchRepository.update(sketch) await this.userRepository.update(sketchAuthor) } I am new to DDD so I am not sure if this would be the best approach. Should I use domain events? Is using two repositories like in this situation a good approach?
Thank you.