Where should I put this?

Published 2 years ago by Mithridates

I have 3 repositories: UserRepository, ReviewRepository, VenueRepository I have a specif method which gets a user's latest review for a venue. The problem is this!
in which repository should I put this method?!
Or should I keep it in user model?

RomainLanz

which gets a user's latest review for a venue.

You should place this method in the VenueRepository.
Note that it would be great to also create this method in the UserRepository.

// VenueRepository

public function getLatestReview(Venue $venue)
{
    // ...
}

public function getLatestReviewForUser(Venue $venue, User $user)
{
    // ...
}

/* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */

// UserRepository

public function getLatestReview(User $user)
{
    // ...
}

public function getLatestReviewForVenue(User $user, Venue $venue)
{
    // ...
}

BTW, it doesn't really matter. Do what you think is the most logic to you.

Please sign in or create an account to participate in this conversation.