Skip to content

Commit

Permalink
shared: Expose methods to get individual room, tag and session type
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Gupta <[email protected]>
  • Loading branch information
theimpulson committed Oct 10, 2024
1 parent 3ecc61b commit bea1047
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ internal class OPassDatabaseHelper {
}
}

suspend fun getRooms(eventId: String): List<LocalizedObject> {
suspend fun getRoom(eventId: String, roomId: String): LocalizedObject? {
return withContext(Dispatchers.IO) {
dbQuery.selectRoom(eventId, roomId).executeAsOneOrNull()
?.toLocalizedObject()
}
}

private suspend fun getRooms(eventId: String): List<LocalizedObject> {
return withContext(Dispatchers.IO) {
dbQuery.selectAllRooms(eventId).executeAsList().map { it.toLocalizedObject()!! }
}
Expand All @@ -102,7 +109,14 @@ internal class OPassDatabaseHelper {
}
}

suspend fun getTags(eventId: String): List<LocalizedObject> {
suspend fun getTag(eventId: String, tagId: String): LocalizedObject? {
return withContext(Dispatchers.IO) {
dbQuery.selectTag(eventId, tagId).executeAsOneOrNull()
?.toLocalizedObject()
}
}

private suspend fun getTags(eventId: String): List<LocalizedObject> {
return withContext(Dispatchers.IO) {
dbQuery.selectAllTags(eventId).executeAsList().map { it.toLocalizedObject()!! }
}
Expand All @@ -124,7 +138,14 @@ internal class OPassDatabaseHelper {
}
}

suspend fun getSessionTypes(eventId: String): List<LocalizedObject> {
suspend fun getSessionType(eventId: String, sessionTypeId: String): LocalizedObject? {
return withContext(Dispatchers.IO) {
dbQuery.selectSessionType(eventId, sessionTypeId).executeAsOneOrNull()
?.toLocalizedObject()
}
}

private suspend fun getSessionTypes(eventId: String): List<LocalizedObject> {
return withContext(Dispatchers.IO) {
dbQuery.selectAllSessionTypes(eventId).executeAsList().map { it.toLocalizedObject()!! }
}
Expand Down Expand Up @@ -152,7 +173,7 @@ internal class OPassDatabaseHelper {
}
}

suspend fun getSpeakers(eventId: String): List<Speaker> {
private suspend fun getSpeakers(eventId: String): List<Speaker> {
return withContext(Dispatchers.IO) {
dbQuery.selectAllSpeakers(eventId).executeAsList().map { it.toSpeaker() }
}
Expand Down Expand Up @@ -185,7 +206,7 @@ internal class OPassDatabaseHelper {
}
}

suspend fun getSessions(eventId: String): List<Session> {
private suspend fun getSessions(eventId: String): List<Session> {
return withContext(Dispatchers.IO) {
dbQuery.selectAllSessions(eventId).executeAsList().map { it.toSession() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package app.opass.ccip.helpers

import app.opass.ccip.database.OPassDatabaseHelper
import app.opass.ccip.network.PortalClient
import app.opass.ccip.network.models.common.LocalizedObject
import app.opass.ccip.network.models.event.Event
import app.opass.ccip.network.models.eventconfig.EventConfig
import app.opass.ccip.network.models.eventconfig.FeatureType
Expand Down Expand Up @@ -88,7 +89,37 @@ class PortalHelper {
}

/**
* Fetches [Schedule] for specified id from Event's website
* Fetches [LocalizedObject] for specified event using given id
* @param eventId ID of the event
* @param roomId ID of the room
* @return null if schedule hasn't been cached yet; room otherwise
*/
suspend fun getRoom(eventId: String, roomId: String): LocalizedObject? {
return dbHelper.getRoom(eventId, roomId)
}

/**
* Fetches [LocalizedObject] for specified event using given id
* @param eventId ID of the event
* @param tagId ID of the speaker
* @return null if schedule hasn't been cached yet; tag otherwise
*/
suspend fun getTag(eventId: String, tagId: String): LocalizedObject? {
return dbHelper.getTag(eventId, tagId)
}

/**
* Fetches [LocalizedObject] for specified event using given id
* @param eventId ID of the event
* @param sessionTypeId ID of the session type
* @return null if schedule hasn't been cached yet; session's type otherwise
*/
suspend fun getSessionType(eventId: String, sessionTypeId: String): LocalizedObject? {
return dbHelper.getSessionType(eventId, sessionTypeId)
}

/**
* Fetches [Session] for specified event using given id
* @param eventId ID of the event
* @param sessionId ID of the session
* @return null if schedule hasn't been cached yet; session otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ VALUES (:id, :logoUrl, :nameEn, :nameZh, :eventStart, :eventEnd, :website, :feat

-- Named queries for room table

selectRoom:
SELECT * FROM RoomTable WHERE eventId = :eventId AND id = :id;

insertRoom:
INSERT INTO RoomTable (id, nameEn, nameZh, eventId) VALUES (:id, :nameEn, :nameZh, :eventId);

Expand All @@ -145,6 +148,9 @@ DELETE FROM RoomTable WHERE eventId = :eventId;

-- Named queries for tag table

selectTag:
SELECT * FROM TagTable WHERE eventId = :eventId AND id = :id;

insertTag:
INSERT INTO TagTable (id, nameEn, nameZh, eventId) VALUES (:id, :nameEn, :nameZh, :eventId);

Expand All @@ -156,6 +162,9 @@ DELETE FROM TagTable WHERE eventId = :eventId;

-- Named queries for session type table

selectSessionType:
SELECT * FROM SessionTypeTable WHERE eventId = :eventId AND id = :id;

insertSessionType:
INSERT INTO SessionTypeTable (id, nameEn, nameZh, eventId) VALUES (:id, :nameEn, :nameZh, :eventId);

Expand Down

0 comments on commit bea1047

Please sign in to comment.