-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): add webhook for cms4partners project.
- Loading branch information
1 parent
6705cdf
commit 99bb766
Showing
5 changed files
with
111 additions
and
0 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
22 changes: 22 additions & 0 deletions
22
.../main/java/org/gdglille/devfest/backend/third/parties/cms4partners/Cms4PartnersMappers.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,22 @@ | ||
package org.gdglille.devfest.backend.third.parties.cms4partners | ||
|
||
import org.gdglille.devfest.models.inputs.PartnerInput | ||
|
||
fun WebhookInput.mapToPartnerInput(): PartnerInput { | ||
val hasTwitter = data.twitterAccount == "" || data.twitterAccount != null | ||
val hasLinkedIn = data.linkedinAccount == "" || data.linkedinAccount != null | ||
val hasSchemaSiteUrl = data.siteUrl?.startsWith("https://") ?: false | ||
return PartnerInput( | ||
name = data.name, | ||
description = data.description ?: "", | ||
logoUrl = data.logoUrl!!, | ||
siteUrl = if (hasSchemaSiteUrl) data.siteUrl!! else "https://${data.siteUrl}", | ||
twitterUrl = if (hasTwitter) data.twitterAccount else null, | ||
twitterMessage = data.twitter ?: "", | ||
linkedinUrl = if (hasLinkedIn) data.linkedinAccount else null, | ||
linkedinMessage = data.linkedin ?: "", | ||
address = data.address ?: "", | ||
sponsoring = data.sponsoring!!, | ||
wldId = data.wldId | ||
) | ||
} |
52 changes: 52 additions & 0 deletions
52
.../src/main/java/org/gdglille/devfest/backend/third/parties/cms4partners/Cms4PartnersNet.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,52 @@ | ||
package org.gdglille.devfest.backend.third.parties.cms4partners | ||
|
||
import kotlinx.serialization.Serializable | ||
import org.gdglille.devfest.models.inputs.Validator | ||
|
||
@Serializable | ||
data class WebhookInput( | ||
val id: String, | ||
val data: PartnerInput | ||
) : Validator { | ||
override fun validate(): List<String> { | ||
return mutableListOf<String>().apply { | ||
if (data.public == false) { | ||
add("The partner isn't public") | ||
} | ||
if (data.status.paid != "done") { | ||
add("Partner didn't paid yet.") | ||
} | ||
if (data.logoUrl == null || data.logoUrl == "") { | ||
add("Partner doesn't have a logo.") | ||
} | ||
if (data.siteUrl == null || data.siteUrl == "") { | ||
add("Partner doesn't have a website.") | ||
} | ||
if (data.sponsoring == null) { | ||
add("Partner doesn't have a sponsoring.") | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Serializable | ||
data class PartnerInput( | ||
val name: String, | ||
val public: Boolean? = null, | ||
val description: String? = null, | ||
val logoUrl: String? = null, | ||
val siteUrl: String? = null, | ||
val twitterAccount: String? = null, | ||
val twitter: String? = null, | ||
val linkedinAccount: String? = null, | ||
val linkedin: String? = null, | ||
val address: String? = null, | ||
val sponsoring: String? = null, | ||
val status: StatusInput, | ||
val wldId: String? = null | ||
) | ||
|
||
@Serializable | ||
data class StatusInput( | ||
val paid: String? = null | ||
) |
34 changes: 34 additions & 0 deletions
34
.../main/java/org/gdglille/devfest/backend/third/parties/cms4partners/Cms4PartnersRouting.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,34 @@ | ||
package org.gdglille.devfest.backend.third.parties.cms4partners | ||
|
||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.application.call | ||
import io.ktor.server.response.respond | ||
import io.ktor.server.routing.Route | ||
import io.ktor.server.routing.post | ||
import org.gdglille.devfest.backend.events.EventDao | ||
import org.gdglille.devfest.backend.internals.helpers.image.TranscoderImage | ||
import org.gdglille.devfest.backend.jobs.JobDao | ||
import org.gdglille.devfest.backend.partners.PartnerDao | ||
import org.gdglille.devfest.backend.partners.PartnerRepository | ||
import org.gdglille.devfest.backend.receiveValidated | ||
import org.gdglille.devfest.backend.third.parties.geocode.GeocodeApi | ||
|
||
fun Route.registerCms4PartnersRoutes( | ||
geocodeApi: GeocodeApi, | ||
eventDao: EventDao, | ||
partnerDao: PartnerDao, | ||
jobDao: JobDao, | ||
imageTranscoder: TranscoderImage | ||
) { | ||
val repository = PartnerRepository(geocodeApi, eventDao, partnerDao, jobDao, imageTranscoder) | ||
|
||
post("cms4partners/webhook") { | ||
val eventId = call.parameters["eventId"]!! | ||
val apiKey = call.parameters["api_key"]!! | ||
val input = call.receiveValidated<WebhookInput>() | ||
call.respond( | ||
HttpStatusCode.Created, | ||
repository.update(eventId, apiKey, input.id, input.mapToPartnerInput()) | ||
) | ||
} | ||
} |