This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from javaBin/feat/load-workshop
Feat/load workshop
- Loading branch information
Showing
16 changed files
with
345 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package backend.dto | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SpeakerDTO( | ||
val name: String, | ||
val bio: String, | ||
val twitter: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
backend/app/src/main/kotlin/backend/dto/WorkshopListImportDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package backend.dto | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class WorkshopListImportDTO( | ||
val sessions: List<WorkshopImport>, | ||
) | ||
|
||
@Serializable | ||
data class WorkshopImport( | ||
val intendedAudience: String, | ||
val length: String, | ||
val format: String, | ||
val language: String, | ||
val abstract: String, | ||
val title: String, | ||
val room: String, | ||
val startTime: String, | ||
val endTime: String, | ||
val video: String? = "", | ||
val startTimeZulu: String, | ||
val endTimeZulu: String, | ||
val id: String, | ||
val sessionId: String, | ||
val conferenceId: String, | ||
val startSlot: String, | ||
val startSlotZulu: String, | ||
val speakers: List<Speaker>, | ||
val workshopPrerequisites: String? = "", | ||
val registerLoc: String? = "", | ||
) | ||
|
||
@Serializable | ||
data class Speaker( | ||
val name: String, | ||
val twitter: String? = "", | ||
val bio: String, | ||
) |
63 changes: 63 additions & 0 deletions
63
backend/app/src/main/kotlin/backend/repository/SpeakerRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package backend.repository | ||
|
||
import backend.dto.SpeakerDTO | ||
import com.inventy.plugins.DatabaseFactory.Companion.dbQuery | ||
import org.jetbrains.exposed.sql.* | ||
|
||
data class Speaker( | ||
val name: String, | ||
val bio: String, | ||
val twitter: String, | ||
val workshopId: String, | ||
val index: Int, | ||
) { | ||
fun toDTO() = SpeakerDTO(name, bio, twitter) | ||
} | ||
|
||
class SpeakerRepository { | ||
|
||
internal object SpeakerTable : Table() { | ||
val name = varchar("NAME", 256) | ||
val bio = varchar("bio", 2048) | ||
val twitter = varchar("twitter", 256) | ||
val workshopId = reference("workshop_id", WorkshopRepository.WorkshopTable.id) | ||
val index = integer("index"); | ||
|
||
override val primaryKey = PrimaryKey(arrayOf(workshopId, index), "id") | ||
|
||
fun toModel(it: ResultRow) = Speaker( | ||
name = it[name], | ||
bio = it[bio], | ||
twitter = it[twitter], | ||
workshopId = it[workshopId], | ||
index = it[index] | ||
) | ||
} | ||
|
||
suspend fun list(): List<Speaker> = dbQuery { | ||
SpeakerTable.selectAll() | ||
.map(SpeakerTable::toModel) | ||
} | ||
|
||
|
||
private suspend fun create(speakers: List<Speaker>) = dbQuery { | ||
SpeakerTable.batchInsert(speakers) { speaker -> | ||
this[SpeakerTable.name] = speaker.name | ||
this[SpeakerTable.bio] = speaker.bio | ||
this[SpeakerTable.twitter] = speaker.twitter | ||
this[SpeakerTable.workshopId] = speaker.workshopId | ||
this[SpeakerTable.index] = speaker.index | ||
} | ||
} | ||
|
||
|
||
|
||
suspend fun replace(speakers: List<Speaker>) { | ||
|
||
dbQuery { | ||
SpeakerTable.deleteAll() | ||
create(speakers) | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 74 additions & 16 deletions
90
backend/app/src/main/kotlin/backend/repository/WorkshopRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,101 @@ | ||
package backend.repository | ||
|
||
import backend.dto.SpeakerDTO | ||
import backend.dto.WorkshopDTO | ||
import backend.dto.WorkshopImport | ||
import backend.dto.WorkshopListImportDTO | ||
import com.inventy.plugins.DatabaseFactory.Companion.dbQuery | ||
import kotlinx.datetime.Instant | ||
import org.jetbrains.exposed.dao.id.IntIdTable | ||
import org.jetbrains.exposed.sql.ResultRow | ||
import org.jetbrains.exposed.sql.* | ||
import org.jetbrains.exposed.sql.kotlin.datetime.timestamp | ||
import org.jetbrains.exposed.sql.selectAll | ||
|
||
class Workshop( | ||
override val id: Int, | ||
data class Workshop( | ||
val id: String, | ||
val title: String, | ||
val description: String, | ||
val startTime: Instant, | ||
val endTime: Instant, | ||
val capacity: Int | ||
) : Model { | ||
fun toDTO() = WorkshopDTO(title, description, startTime, endTime, capacity) | ||
val capacity: Int, | ||
val active: Boolean | ||
) { | ||
fun toDTO(speakerDTOS: List<SpeakerDTO>?) = WorkshopDTO(title, description, startTime, endTime, capacity, active, speakerDTOS ?: listOf()) | ||
} | ||
|
||
class WorkshopRepository { | ||
internal object WorkshopTable : IntIdTable() { | ||
val title = varchar("title", 128) | ||
val description = varchar("description", 256) | ||
|
||
companion object { | ||
private const val WORKSHOP_CAPACITY = 30 | ||
} | ||
|
||
internal object WorkshopTable : Table() { | ||
|
||
val id = varchar("id", 64) | ||
val title = varchar("title", 256) | ||
val description = varchar("description", 2048) | ||
val startTime = timestamp("start_time") | ||
val endTime = timestamp("end_time") | ||
val capacity = integer("capacity") | ||
val active = bool("active") | ||
|
||
override val primaryKey = PrimaryKey(arrayOf(id), "id") | ||
|
||
fun toModel(it: ResultRow) = Workshop( | ||
it[id].value, | ||
it[title], | ||
it[description], | ||
it[startTime], | ||
it[endTime], | ||
it[capacity] | ||
id = it[id], | ||
title = it[title], | ||
description = it[description], | ||
startTime = it[startTime], | ||
endTime = it[endTime], | ||
capacity = it[capacity], | ||
active = it[active], | ||
) | ||
} | ||
|
||
suspend fun list(): List<Workshop> = dbQuery { | ||
WorkshopTable.selectAll() | ||
.map(WorkshopTable::toModel) | ||
} | ||
|
||
|
||
private suspend fun upsertActive(workshops: List<WorkshopImport>) = dbQuery { | ||
WorkshopTable.batchUpsert(workshops) { workshop -> | ||
this[WorkshopTable.id] = workshop.id | ||
this[WorkshopTable.title] = workshop.title | ||
this[WorkshopTable.description] = | ||
workshop.abstract.take(250) + if (workshop.abstract.length > 250) " ..." else "" | ||
this[WorkshopTable.startTime] = Instant.parse(workshop.startTimeZulu) | ||
this[WorkshopTable.endTime] = Instant.parse(workshop.endTimeZulu) | ||
this[WorkshopTable.capacity] = WORKSHOP_CAPACITY | ||
this[WorkshopTable.active] = true | ||
} | ||
} | ||
|
||
private suspend fun upsert(workshops: List<Workshop>) = dbQuery { | ||
WorkshopTable.batchUpsert(workshops) { workshop -> | ||
this[WorkshopTable.id] = workshop.id | ||
this[WorkshopTable.title] = workshop.title | ||
this[WorkshopTable.description] = workshop.description | ||
this[WorkshopTable.startTime] = workshop.startTime | ||
this[WorkshopTable.endTime] = workshop.endTime | ||
this[WorkshopTable.capacity] = WORKSHOP_CAPACITY | ||
this[WorkshopTable.active] = workshop.active | ||
} | ||
} | ||
|
||
private suspend fun setWorkshopsToDisabled(activeWorkshops: List<WorkshopImport>) { | ||
val activeWorkshopsIds = activeWorkshops.map { it.id } | ||
val allDisabledList = list() | ||
.filterNot { it.id in activeWorkshopsIds } | ||
.map { it.copy(active = false) } | ||
val t = upsert(allDisabledList) | ||
} | ||
|
||
suspend fun update(workshops: List<WorkshopImport>) { | ||
|
||
dbQuery { | ||
setWorkshopsToDisabled(workshops) | ||
upsertActive(workshops) | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.