diff --git a/.gitignore b/.gitignore index 94b4cc6..6156d77 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ .output **/build/** -.gradle \ No newline at end of file +.gradle + +bot_postgres +api_mongo \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 0627fe2..dd955ce 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -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 diff --git a/talent-hub_api/src/main/kotlin/org/talenthub/presentation/resources/MissionResource.kt b/talent-hub_api/src/main/kotlin/org/talenthub/presentation/resources/MissionResource.kt index 0e71026..0a65500 100644 --- a/talent-hub_api/src/main/kotlin/org/talenthub/presentation/resources/MissionResource.kt +++ b/talent-hub_api/src/main/kotlin/org/talenthub/presentation/resources/MissionResource.kt @@ -6,9 +6,11 @@ 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( @@ -16,6 +18,9 @@ class MissionResource @Inject constructor( private val _logger: Logger ) { + @ConfigProperty(name = "discord.jobs.webhook") + lateinit var webhookUrl: String + @GET @Produces(MediaType.APPLICATION_JSON) fun getAllMissions(): Uni { @@ -58,6 +63,37 @@ class MissionResource @Inject constructor( fun createMission(mission: Mission): Uni { 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() diff --git a/talent-hub_api/src/main/resources/application.properties.example b/talent-hub_api/src/main/resources/application.properties.example new file mode 100644 index 0000000..eef19be --- /dev/null +++ b/talent-hub_api/src/main/resources/application.properties.example @@ -0,0 +1,4 @@ +quarkus.live-reload.instrumentation=true +quarkus.mongodb.database= +quarkus.mongodb.connection-string = +discord.jobs.webhook= \ No newline at end of file diff --git a/talent-hub_api/src/test/kotlin/org/talenthub/GreetingResourceTest.kt b/talent-hub_api/src/test/kotlin/org/talenthub/GreetingResourceTest.kt deleted file mode 100644 index 3389ce6..0000000 --- a/talent-hub_api/src/test/kotlin/org/talenthub/GreetingResourceTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.talenthub - -import io.quarkus.test.junit.QuarkusTest -import io.restassured.RestAssured.given -import org.hamcrest.CoreMatchers.`is` -import org.junit.jupiter.api.Test - -@QuarkusTest -class GreetingResourceTest { - - @Test - fun testHelloEndpoint() { - given() - .`when`().get("/hello") - .then() - .statusCode(200) - .body(`is`("Hello from RESTEasy Reactive")) - } - -} \ No newline at end of file