Skip to content

Commit

Permalink
refactor(backend): don't update category if not exist from OpenPlanner
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Apr 2, 2024
1 parent aa84455 commit 6dfd464
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,21 @@ class CategoryDao(private val database: Database) {
item = item
)
}

suspend fun createIfNotExist(eventId: String, item: CategoryDb) {
if (item.id == null) {
database.insert(
eventId = eventId,
collectionName = CollectionName
) { item.copy(id = it) }
} else {
val existing = get(eventId, item.id)
if (existing == null) {
database.insert(
eventId = eventId,
collectionName = CollectionName
) { item.copy(id = it) }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class EventRepository(
?: throw NotAcceptableException("OpenPlanner config not initialized")
val openPlanner = openPlannerApi.fetchPrivateJson(config.eventId, config.privateId)
openPlanner.event.categories
.map { async { categoryDao.createOrUpdate(eventId, it.convertToDb()) } }
.map { async { categoryDao.createIfNotExist(eventId, it.convertToDb()) } }
.awaitAll()
openPlanner.event.formats
.map { async { formatDao.createOrUpdate(eventId, it.convertToDb()) } }
Expand Down

0 comments on commit 6dfd464

Please sign in to comment.