Skip to content

Commit

Permalink
Rename to findByIds
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Oct 24, 2023
1 parent d7585d1 commit 840b656
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ datascience/docs/build

# Ignore Gradle project-specific cache directory
backend/.gradle
.gradle

# Ignore Gradle build output directory
backend/build
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface IMissionRepository {
pageable: Pageable,
): List<MissionDTO>

fun findAllIncludedIn(ids: List<Int>): List<MissionEntity>
fun findByIds(ids: List<Int>): List<MissionEntity>

fun findByControlUnitId(controlUnitId: Int): List<MissionEntity>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity
import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository

@UseCase
class GetMissionsIncludedIn(private val missionRepository: IMissionRepository) {
class GetMissionsByIds(private val missionRepository: IMissionRepository) {
fun execute(ids: List<Int>): List<MissionEntity> {
return missionRepository.findAllIncludedIn(ids)
return missionRepository.findByIds(ids)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ApiMissionsController(
private val getMissionById: GetMissionById,
private val deleteMission: DeleteMission,
private val getEngagedControlUnits: GetEngagedControlUnits,
private val getMissionsIncludedIn: GetMissionsIncludedIn
private val getMissionsByIds: GetMissionsByIds
) {

@GetMapping("")
Expand Down Expand Up @@ -75,7 +75,7 @@ class ApiMissionsController(
@RequestParam(name = "ids")
ids: List<Int>,
): List<MissionDataOutput> {
val missions = getMissionsIncludedIn.execute(ids)
val missions = getMissionsByIds.execute(ids)
return missions.map { MissionDataOutput.fromMissionEntity(it) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class JpaMissionRepository(
).map { it.toMissionDTO(mapper) }
}

override fun findAllIncludedIn(ids: List<Int>): List<MissionEntity> {
return dbMissionRepository.findAllIncludedIn(ids).map { it.toMissionEntity(mapper) }
override fun findByIds(ids: List<Int>): List<MissionEntity> {
return dbMissionRepository.findNotDeletedByIds(ids).map { it.toMissionEntity(mapper) }
}

override fun findByControlUnitId(controlUnitId: Int): List<MissionEntity> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ interface IDBMissionRepository : JpaRepository<MissionModel, Int> {
""",
nativeQuery = true,
)
fun findAllIncludedIn(ids: List<Int>): List<MissionModel>
fun findNotDeletedByIds(ids: List<Int>): List<MissionModel>

@Query("SELECT mm FROM MissionModel mm JOIN mm.controlUnits mmcu WHERE mmcu.unit.id = :controlUnitId")
fun findByControlUnitId(controlUnitId: Int): List<MissionModel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ApiMissionsControllerITests {
private lateinit var deleteMission: DeleteMission

@MockBean
private lateinit var getMissionsIncludedIn: GetMissionsIncludedIn
private lateinit var getMissionsByIds: GetMissionsByIds

@MockBean
private lateinit var getEngagedControlUnits: GetEngagedControlUnits
Expand Down Expand Up @@ -182,7 +182,7 @@ class ApiMissionsControllerITests {
isGeometryComputedFromControls = false,
)
given(
getMissionsIncludedIn.execute(any()),
getMissionsByIds.execute(any()),
).willReturn(listOf(expectedFirstMission))

// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,8 @@ class JpaMissionRepositoryITests : AbstractDBTests() {

@Test
@Transactional
fun `findAllIncludedIn() should find the matching missions`() {
val foundMissions = jpaMissionRepository.findAllIncludedIn(listOf(50, 51, 52))
fun `findByIds() should find the matching missions`() {
val foundMissions = jpaMissionRepository.findByIds(listOf(50, 51, 52))

assertThat(foundMissions).hasSize(3)
}
Expand Down

0 comments on commit 840b656

Please sign in to comment.