Skip to content

Commit

Permalink
feat(api): on job offer created, send it to discord
Browse files Browse the repository at this point in the history
  • Loading branch information
Inerska committed Mar 8, 2024
1 parent cb7b109 commit b9fd2a1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 24 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
.output

**/build/**
.gradle
.gradle

bot_postgres
api_mongo
24 changes: 21 additions & 3 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,32 @@ name: th-monolith_dev

services:
api:
build:
context: talent-hub_api
dockerfile: src/main/docker/Dockerfile.dev
image: quarkus/talent-hub_api-jvm
ports:
- "8080:8080"
restart: unless-stopped
volumes:
- ./talent-hub_api:/app
depends_on:
- api_mongo
- api_rabbitmq
networks:
- th-dev_net

api_mongo:
image: "mongo:4.4"
ports:
- "27017:27017"
volumes:
- ./api_mongo:/data/db
networks:
- th-dev_net

api_rabbitmq:
image: "rabbitmq:3.8-management"
ports:
- "5672:5672"
- "15672:15672"
networks:
- th-dev_net

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import jakarta.ws.rs.*
import jakarta.ws.rs.core.MediaType
import jakarta.ws.rs.core.Response
import org.bson.types.ObjectId
import org.eclipse.microprofile.config.inject.ConfigProperty
import org.jboss.logging.Logger
import org.talenthub.infrastructure.persistence.entity.Mission
import org.talenthub.infrastructure.persistence.repository.MissionRepository
import java.net.http.HttpClient

@Path("/missions")
class MissionResource @Inject constructor(
private val _missionRepository: MissionRepository,
private val _logger: Logger
) {

@ConfigProperty(name = "discord.jobs.webhook")
lateinit var webhookUrl: String

@GET
@Produces(MediaType.APPLICATION_JSON)
fun getAllMissions(): Uni<Response> {
Expand Down Expand Up @@ -58,6 +63,37 @@ class MissionResource @Inject constructor(
fun createMission(mission: Mission): Uni<Response> {
return _missionRepository.persist(mission)
.map { createdMission ->

_logger.info("Webhook : $webhookUrl")

val payload = """
{
"content": "New mission created",
"embeds": [
{
"title": "New mission created",
"description": "A new mission has been created with the following details: ${createdMission.name}, ${createdMission.description}"
}
]
}
""".trimIndent()

try {
HttpClient.newHttpClient()
.sendAsync(
java.net.http.HttpRequest.newBuilder()
.uri(java.net.URI.create(webhookUrl))
.header("Content-Type", "application/json")
.POST(java.net.http.HttpRequest.BodyPublishers.ofString(payload))
.build(),
java.net.http.HttpResponse.BodyHandlers.ofString()
)
.join()

} catch (e: Exception) {
_logger.error("Failed to send webhook", e)
}

Response.status(Response.Status.CREATED)
.entity(createdMission)
.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
quarkus.live-reload.instrumentation=true
quarkus.mongodb.database=
quarkus.mongodb.connection-string =
discord.jobs.webhook=

This file was deleted.

0 comments on commit b9fd2a1

Please sign in to comment.