Skip to content

Commit

Permalink
chore: add to parameter to specify tracking data time range
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomoaccursi committed Mar 13, 2023
1 parent bd39d96 commit 15861c5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
16 changes: 10 additions & 6 deletions src/main/kotlin/application/controller/StaffTrackingController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ class StaffTrackingController(private val dbManager: StaffTrackingDatabaseManage
override fun addTrackingData(trackingData: TrackingData) =
dbManager.addTrackingData(trackingData)

override fun getHealthProfessionalTrackingData(healthProfessionalId: HealthProfessionalId, from: Instant?) =
dbManager.getHealthProfessionalTrackingData(healthProfessionalId, from)
override fun getHealthProfessionalTrackingData(
healthProfessionalId: HealthProfessionalId,
from: Instant?,
to: Instant?
) =
dbManager.getHealthProfessionalTrackingData(healthProfessionalId, from, to)

override fun getRoomTrackingData(roomId: RoomId, from: Instant?) =
dbManager.getRoomTrackingData(roomId, from)
override fun getRoomTrackingData(roomId: RoomId, from: Instant?, to: Instant?) =
dbManager.getRoomTrackingData(roomId, from, to)

override fun getLatestTrackingData(from: Instant?): Set<TrackingData> =
dbManager.getLatestTrackingData(from)
override fun getLatestTrackingData(from: Instant?, to: Instant?): Set<TrackingData> =
dbManager.getLatestTrackingData(from, to)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ interface StaffTrackingDatabaseManager {
* @param healthProfessionalId the id of the health professional.
* @param from the instant from which retrieve tracking data.
*/
fun getHealthProfessionalTrackingData(healthProfessionalId: HealthProfessionalId, from: Instant?): Set<TrackingData>
fun getHealthProfessionalTrackingData(
healthProfessionalId: HealthProfessionalId,
from: Instant?,
to: Instant?
): Set<TrackingData>

/**
* Get the tracking data of a room.
* @param roomId the room in which retrieve tracking data.
* @param from the instant from which retrieve tracking data.
*/
fun getRoomTrackingData(roomId: RoomId, from: Instant?): Set<TrackingData>
fun getRoomTrackingData(roomId: RoomId, from: Instant?, to: Instant?): Set<TrackingData>

/**
* Get the latest tracking data starting from a given instant.
* @param from the instant from which retrieve tracking data.
*/
fun getLatestTrackingData(from: Instant?): Set<TrackingData>
fun getLatestTrackingData(from: Instant?, to: Instant? = Instant.now()): Set<TrackingData>
}
10 changes: 7 additions & 3 deletions src/main/kotlin/application/service/TrackingServices.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package application.service

import application.controller.manager.StaffTrackingDatabaseManager
import entity.HealthProfessionalId
import entity.RoomId
import entity.TrackingData
Expand All @@ -31,33 +32,36 @@ object TrackingServices {
class GetHealthProfessionalTrackingData(
private val healthProfessionalId: HealthProfessionalId,
private val from: Instant?,
private val to: Instant?,
private val trackingDataRepository: TrackingDataRepository
) : ApplicationService<Set<TrackingData>> {

override fun execute(): Set<TrackingData> =
trackingDataRepository.getHealthProfessionalTrackingData(healthProfessionalId, from)
trackingDataRepository.getHealthProfessionalTrackingData(healthProfessionalId, from, to)
}

/** The application service to get room tracking data
* given the [roomId], the [trackingDataRepository] and [from] a certain moment. */
class GetRoomTrackingData(
private val roomId: RoomId,
private val from: Instant?,
private val to: Instant?,
private val trackingDataRepository: TrackingDataRepository
) : ApplicationService<Set<TrackingData>> {

override fun execute(): Set<TrackingData> =
trackingDataRepository.getRoomTrackingData(roomId, from)
trackingDataRepository.getRoomTrackingData(roomId, from, to)
}

/** The application service to get the latest tracking data
* given the [trackingDataRepository] and [from] a certain moment. */
class GetLatestTrackingData(
private val from: Instant?,
private val to: Instant?,
private val trackingDataRepository: TrackingDataRepository
) : ApplicationService<Set<TrackingData>> {

override fun execute(): Set<TrackingData> =
trackingDataRepository.getLatestTrackingData(from)
trackingDataRepository.getLatestTrackingData(from, to)
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/infrastructure/api/routes/TrackingAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fun Route.trackingAPI(databaseManager: StaffTrackingDatabaseManager, apiPath: St
TrackingServices.GetHealthProfessionalTrackingData(
HealthProfessionalId(call.parameters["healthProfessionalId"].orEmpty()),
call.request.queryParameters["from"]?.let { from -> Instant.parse(from) },
call.request.queryParameters["to"]?.let { to -> Instant.parse(to) },
StaffTrackingController(databaseManager)
).execute().map { data ->
data.toTrackingDataApiDto()
Expand All @@ -43,6 +44,7 @@ fun Route.trackingAPI(databaseManager: StaffTrackingDatabaseManager, apiPath: St
TrackingServices.GetRoomTrackingData(
RoomId(call.parameters["roomId"].orEmpty()),
call.request.queryParameters["from"]?.let { from -> Instant.parse(from) },
call.request.queryParameters["to"]?.let { to -> Instant.parse(to) },
StaffTrackingController(databaseManager)
).execute().map { data ->
data.toTrackingDataApiDto()
Expand All @@ -54,6 +56,7 @@ fun Route.trackingAPI(databaseManager: StaffTrackingDatabaseManager, apiPath: St
call.respondWithList(
TrackingServices.GetLatestTrackingData(
call.request.queryParameters["from"]?.let { from -> Instant.parse(from) },
call.request.queryParameters["to"]?.let { to -> Instant.parse(to) },
StaffTrackingController(databaseManager)
).execute().map { data ->
data.toTrackingDataApiDto()
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/infrastructure/database/MongoClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ class MongoClient(

override fun getHealthProfessionalTrackingData(
healthProfessionalId: HealthProfessionalId,
from: Instant?
from: Instant?,
to: Instant?
): Set<TrackingData> =
trackingDataCollection.find().filter {
it.metadata.healthProfessionalId.equals(healthProfessionalId)
}.map {
it.toTrackingData()
}.toSet()

override fun getRoomTrackingData(roomId: RoomId, from: Instant?): Set<TrackingData> {
override fun getRoomTrackingData(roomId: RoomId, from: Instant?, to: Instant?): Set<TrackingData> {
TODO("Not yet implemented")
}

override fun getLatestTrackingData(from: Instant?): Set<TrackingData> {
override fun getLatestTrackingData(from: Instant?, to: Instant?): Set<TrackingData> {
TODO("Not yet implemented")
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/usecase/repository/TrackingDataRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ interface TrackingDataRepository {
*/
fun getHealthProfessionalTrackingData(
healthProfessionalId: HealthProfessionalId,
from: Instant?
from: Instant?,
to: Instant?
): Set<TrackingData>

/** Get the room tracking data given its [roomId].
* @param from the instant from which retrieve tracking data.
*/
fun getRoomTrackingData(roomId: RoomId, from: Instant?): Set<TrackingData>
fun getRoomTrackingData(roomId: RoomId, from: Instant?, to: Instant?): Set<TrackingData>

/** Get the latest tracking data.
* @param from the instant from which retrieve tracking data.
*/
fun getLatestTrackingData(from: Instant?): Set<TrackingData>
fun getLatestTrackingData(from: Instant?, to: Instant?): Set<TrackingData>
}

0 comments on commit 15861c5

Please sign in to comment.