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

Feature: Booking: implement get all bookings from all workplaces

владелец c07acb2b
......@@ -11,8 +11,8 @@ import java.util.*
* @property count The quantity of this utility
*/
data class Utility(
var id: UUID,
var name: String,
var iconUrl: String,
var count: Int
val id: UUID,
val name: String,
val iconUrl: String,
val count: Int
)
\ Нет новой строки в конце файла
......@@ -12,9 +12,9 @@ import java.util.UUID
* @property zone The zone where the workspace is located
*/
data class Workspace(
var id: UUID,
var name: String,
var tag: String,
var utilities: List<Utility>,
var zone: WorkspaceZone? = null
val id: UUID,
val name: String,
val tag: String,
val utilities: List<Utility>,
val zone: WorkspaceZone? = null
)
\ Нет новой строки в конце файла
......@@ -9,6 +9,6 @@ import java.util.*
* @property name The name of the workspace zone
*/
data class WorkspaceZone(
var id: UUID,
var name: String
val id: UUID,
val name: String
)
\ Нет новой строки в конце файла
......@@ -101,4 +101,17 @@ class DummyCalendarProvider : CalendarProvider {
// For simplicity in this dummy implementation, we'll just search all bookings
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(
@Value("\${calendar.credentials.file}")
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.
......@@ -58,7 +58,7 @@ class GoogleCalendarConfig(
@Bean
fun calendar(httpTransport: HttpTransport, googleCredentials: GoogleCredentials): Calendar {
return Calendar.Builder(httpTransport, JSON_FACTORY, HttpCredentialsAdapter(googleCredentials))
return Calendar.Builder(httpTransport, jsonFactory, HttpCredentialsAdapter(googleCredentials))
.setApplicationName(applicationName)
.build()
}
......
......@@ -177,6 +177,31 @@ class GoogleCalendarProvider(
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
private fun getCalendarIdByWorkspace(workspaceId: UUID): String {
......
......@@ -83,6 +83,6 @@ class WorkspaceCalendarIdProvider(
}
}
return calendarIds.values.toList() + defaultCalendar
return calendarIds.values.toList()
}
}
......@@ -118,9 +118,7 @@ class BookingController(
}
else -> {
// TODO In a real implementation, we would need a method to get all bookings
// For now, we'll return an empty list
emptyList()
bookingService.getAllBookings(from, to)
}
}
......
......@@ -59,4 +59,13 @@ interface CalendarProvider {
* @return The booking if found, null otherwise
*/
fun findEventById(id: UUID): Booking?
}
\ Нет новой строки в конце файла
/**
* 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(
return calendarProvider.findEventsByUser(userId, from, to)
.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.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать