Коммит 50e4db41 создал по автору Radch-enko's avatar Radch-enko
Просмотр файлов

Feature: Booking: implement get all bookings from all workplaces

владелец c07acb2b
...@@ -11,8 +11,8 @@ import java.util.* ...@@ -11,8 +11,8 @@ import java.util.*
* @property count The quantity of this utility * @property count The quantity of this utility
*/ */
data class Utility( data class Utility(
var id: UUID, val id: UUID,
var name: String, val name: String,
var iconUrl: String, val iconUrl: String,
var count: Int val count: Int
) )
\ No newline at end of file
...@@ -12,9 +12,9 @@ import java.util.UUID ...@@ -12,9 +12,9 @@ import java.util.UUID
* @property zone The zone where the workspace is located * @property zone The zone where the workspace is located
*/ */
data class Workspace( data class Workspace(
var id: UUID, val id: UUID,
var name: String, val name: String,
var tag: String, val tag: String,
var utilities: List<Utility>, val utilities: List<Utility>,
var zone: WorkspaceZone? = null val zone: WorkspaceZone? = null
) )
\ No newline at end of file
...@@ -9,6 +9,6 @@ import java.util.* ...@@ -9,6 +9,6 @@ import java.util.*
* @property name The name of the workspace zone * @property name The name of the workspace zone
*/ */
data class WorkspaceZone( data class WorkspaceZone(
var id: UUID, val id: UUID,
var name: String val name: String
) )
\ No newline at end of file
...@@ -101,4 +101,17 @@ class DummyCalendarProvider : CalendarProvider { ...@@ -101,4 +101,17 @@ class DummyCalendarProvider : CalendarProvider {
// For simplicity in this dummy implementation, we'll just search all bookings // For simplicity in this dummy implementation, we'll just search all bookings
return bookings.values.find { it.id == id } return bookings.values.find { it.id == id }
} }
override fun findAllEvents(from: Instant, to: Instant?): List<Booking> {
logger.debug(
"Finding all dummy events from {} to {}",
from,
to ?: "infinity"
)
return bookings.values.filter { booking ->
booking.beginBooking >= from &&
(to == null || booking.endBooking <= to)
}
}
} }
...@@ -33,7 +33,7 @@ class GoogleCalendarConfig( ...@@ -33,7 +33,7 @@ class GoogleCalendarConfig(
@Value("\${calendar.credentials.file}") @Value("\${calendar.credentials.file}")
private lateinit var credentialsFile: String private lateinit var credentialsFile: String
private val JSON_FACTORY: JsonFactory = GsonFactory.getDefaultInstance() private val jsonFactory: JsonFactory = GsonFactory.getDefaultInstance()
/** /**
* Creates a Google Calendar API client with OAuth2 credentials. * Creates a Google Calendar API client with OAuth2 credentials.
...@@ -58,7 +58,7 @@ class GoogleCalendarConfig( ...@@ -58,7 +58,7 @@ class GoogleCalendarConfig(
@Bean @Bean
fun calendar(httpTransport: HttpTransport, googleCredentials: GoogleCredentials): Calendar { fun calendar(httpTransport: HttpTransport, googleCredentials: GoogleCredentials): Calendar {
return Calendar.Builder(httpTransport, JSON_FACTORY, HttpCredentialsAdapter(googleCredentials)) return Calendar.Builder(httpTransport, jsonFactory, HttpCredentialsAdapter(googleCredentials))
.setApplicationName(applicationName) .setApplicationName(applicationName)
.build() .build()
} }
......
...@@ -177,6 +177,31 @@ class GoogleCalendarProvider( ...@@ -177,6 +177,31 @@ class GoogleCalendarProvider(
return null return null
} }
override fun findAllEvents(from: Instant, to: Instant?): List<Booking> {
logger.debug(
"Finding all events from {} to {}",
from,
to ?: "infinity"
)
// Get all calendar IDs
val calendarIds = calendarIdProvider.getAllCalendarIds()
// Query all calendars for events within the time range
val bookings = mutableListOf<Booking>()
for (calendarId in calendarIds) {
try {
val events = listEvents(calendarId, from, to)
logger.debug("findAllEvents -> events: {}", events.map { it.id.toString() })
bookings.addAll(events.map { convertToBooking(it, calendarId) })
} catch (e: Exception) {
logger.warn("Failed to search for events in calendar {}: {}", calendarId, e.message)
}
}
return bookings
}
// Helper methods // Helper methods
private fun getCalendarIdByWorkspace(workspaceId: UUID): String { private fun getCalendarIdByWorkspace(workspaceId: UUID): String {
......
...@@ -83,6 +83,6 @@ class WorkspaceCalendarIdProvider( ...@@ -83,6 +83,6 @@ class WorkspaceCalendarIdProvider(
} }
} }
return calendarIds.values.toList() + defaultCalendar return calendarIds.values.toList()
} }
} }
...@@ -118,9 +118,7 @@ class BookingController( ...@@ -118,9 +118,7 @@ class BookingController(
} }
else -> { else -> {
// TODO In a real implementation, we would need a method to get all bookings bookingService.getAllBookings(from, to)
// For now, we'll return an empty list
emptyList()
} }
} }
......
...@@ -59,4 +59,13 @@ interface CalendarProvider { ...@@ -59,4 +59,13 @@ interface CalendarProvider {
* @return The booking if found, null otherwise * @return The booking if found, null otherwise
*/ */
fun findEventById(id: UUID): Booking? fun findEventById(id: UUID): Booking?
}
\ No newline at end of file /**
* Finds all events across all workspaces within a time range.
*
* @param from The start of the time range
* @param to The end of the time range (optional)
* @return A list of all bookings within the time range
*/
fun findAllEvents(from: Instant, to: Instant? = null): List<Booking>
}
...@@ -108,4 +108,15 @@ class BookingService( ...@@ -108,4 +108,15 @@ class BookingService(
return calendarProvider.findEventsByUser(userId, from, to) return calendarProvider.findEventsByUser(userId, from, to)
.filter { it.workspace.id == workspaceId } .filter { it.workspace.id == workspaceId }
} }
/**
* Gets all bookings within a time range.
*
* @param from The start of the time range
* @param to The end of the time range (optional)
* @return A list of all bookings within the time range
*/
fun getAllBookings(from: Instant, to: Instant? = null): List<Booking> {
return calendarProvider.findAllEvents(from, to)
}
} }
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать