Skip to content

Commit

Permalink
feat(backend): support png when we create a partner.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Oct 29, 2024
1 parent 040c674 commit 065e317
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.paligot.confily.backend.partners
import com.paligot.confily.backend.activities.ActivityModule.activityDao
import com.paligot.confily.backend.events.EventModule.eventDao
import com.paligot.confily.backend.internals.GoogleServicesModule.cloudFirestore
import com.paligot.confily.backend.internals.InternalModule.commonApi
import com.paligot.confily.backend.internals.InternalModule.storage
import com.paligot.confily.backend.internals.InternalModule.transcoder
import com.paligot.confily.backend.internals.SystemEnv.projectName
Expand All @@ -14,6 +15,7 @@ object PartnerModule {
val partnerRepository = lazy {
PartnerRepository(
geocodeApi.value,
commonApi.value,
eventDao.value,
partnerDao.value,
activityDao.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.paligot.confily.backend.NotFoundException
import com.paligot.confily.backend.activities.ActivityDao
import com.paligot.confily.backend.activities.convertToModel
import com.paligot.confily.backend.events.EventDao
import com.paligot.confily.backend.internals.CommonApi
import com.paligot.confily.backend.internals.helpers.image.Png
import com.paligot.confily.backend.internals.helpers.image.TranscoderImage
import com.paligot.confily.backend.jobs.JobDao
import com.paligot.confily.backend.third.parties.geocode.GeocodeApi
Expand All @@ -22,6 +24,7 @@ import kotlinx.coroutines.coroutineScope
@Suppress("LongParameterList")
class PartnerRepository(
private val geocodeApi: GeocodeApi,
private val commonApi: CommonApi,
private val eventDao: EventDao,
private val partnerDao: PartnerDao,
private val activityDao: ActivityDao,
Expand Down Expand Up @@ -77,11 +80,20 @@ class PartnerRepository(
?: throw NotAcceptableException("Your address information isn't found")
val partnerDb = partnerInput.convertToDb(addressDb = addressDb)
val id = partnerDao.createOrUpdate(eventId, partnerDb)
val pngs = listOf(
async { imageTranscoder.convertSvgToPng(partnerInput.logoUrl, SIZE_250) },
async { imageTranscoder.convertSvgToPng(partnerInput.logoUrl, SIZE_500) },
async { imageTranscoder.convertSvgToPng(partnerInput.logoUrl, SIZE_1000) }
).awaitAll()
val pngs = if (partnerInput.logoUrl.endsWith(".png")) {
val content = commonApi.fetchByteArray(partnerInput.logoUrl)
listOf(
Png(content = content, size = 250),
Png(content = content, size = 500),
Png(content = content, size = 1000)
)
} else {
listOf(
async { imageTranscoder.convertSvgToPng(partnerInput.logoUrl, SIZE_250) },
async { imageTranscoder.convertSvgToPng(partnerInput.logoUrl, SIZE_500) },
async { imageTranscoder.convertSvgToPng(partnerInput.logoUrl, SIZE_1000) }
).awaitAll()
}
val uploads = partnerDao.uploadPartnerLogos(eventId, id, pngs)
partnerDao.createOrUpdate(
eventId,
Expand Down

0 comments on commit 065e317

Please sign in to comment.