Skip to content

Commit

Permalink
feat(backend): add webhook for cms4partners project.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Feb 20, 2024
1 parent 6705cdf commit 99bb766
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AppEngine.

* Create the agenda of your conference, optionally from [Conference Hall](https://github.com/bpetetot/conference-hall)
* Create your feedback forms from [OpenFeedback.io](https://github.com/HugoGresse/open-feedback)
* Create your partners from [Cms4Partners](https://github.com/GDG-Lille/cms4partners)
* Import a participant ticket from [BilletWeb](https://www.billetweb.fr/)
* Import partner jobs from [WeLoveDevs](https://welovedevs.com/)

Expand Down
2 changes: 2 additions & 0 deletions backend/src/main/java/org/gdglille/devfest/backend/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import org.gdglille.devfest.backend.speakers.registerSpeakersRoutes
import org.gdglille.devfest.backend.talks.TalkDao
import org.gdglille.devfest.backend.talks.registerTalksRoutes
import org.gdglille.devfest.backend.third.parties.billetweb.registerBilletWebRoutes
import org.gdglille.devfest.backend.third.parties.cms4partners.registerCms4PartnersRoutes
import org.gdglille.devfest.backend.third.parties.conferencehall.ConferenceHallApi
import org.gdglille.devfest.backend.third.parties.conferencehall.registerConferenceHallRoutes
import org.gdglille.devfest.backend.third.parties.geocode.GeocodeApi
Expand Down Expand Up @@ -167,6 +168,7 @@ fun main() {
registerPartnersRoutes(geocodeApi, eventDao, partnerDao, jobDao, imageTranscoder)
// Third parties
registerBilletWebRoutes(eventDao)
registerCms4PartnersRoutes(geocodeApi, eventDao, partnerDao, jobDao, imageTranscoder)
registerConferenceHallRoutes(
conferenceHallApi,
eventDao,
Expand Down
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
)
}
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
)
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())
)
}
}

0 comments on commit 99bb766

Please sign in to comment.