As we have now set up our necessary entities, we must create repositories which we will use to access data pertaining to our entities. Create a repositories package within the com.example.placereviewer package. We have two entities, and as such, we shall create two repositories (one to access data pertaining to each entity). The first of the repositories will be UserRepository and the second will be ReviewRepository. Create a UserRepository interface file within com.example.placereviewer.data.repository with the following content:
package com.example.placereviewer.data.repository
import com.example.placereviewer.data.model.User
import org.springframework.data.repository.CrudRepository
interface UserRepository : CrudRepository<User, Long> {
fun findByUsername(username: String): User?
}
The findByUsername(String) method retrieves a User from the database which has a username that corresponds to that passed as an argument to the function. The following is the ReviewRepository interface:
package com.example.placereviewer.data.repository
import com.example.placereviewer.data.model.Review
import org.springframework.data.repository.CrudRepository
interface ReviewRepository : CrudRepository<Review, Long> {
fun findByPlaceId(placeId: String)
}
Having set up our entities and repositories to query these entities, we can start work on implementing the core business logic of the Place Reviewer application in the form of services and service implementations.