From 8b11f1ecf9d5fcc6d0a543fbf0f285322bdbcb49 Mon Sep 17 00:00:00 2001 From: Ziedelth Date: Wed, 22 Nov 2023 22:10:28 +0100 Subject: [PATCH] Add recommendation feature to AyaneController --- .../fr/ziedelth/controllers/AyaneController.kt | 16 ++++++++++++++++ .../fr/ziedelth/events/RecommendationEvent.kt | 6 ++++++ 2 files changed, 22 insertions(+) create mode 100644 src/main/kotlin/fr/ziedelth/events/RecommendationEvent.kt diff --git a/src/main/kotlin/fr/ziedelth/controllers/AyaneController.kt b/src/main/kotlin/fr/ziedelth/controllers/AyaneController.kt index 28dd0d4..67a07e2 100644 --- a/src/main/kotlin/fr/ziedelth/controllers/AyaneController.kt +++ b/src/main/kotlin/fr/ziedelth/controllers/AyaneController.kt @@ -1,7 +1,11 @@ package fr.ziedelth.controllers +import com.google.inject.Inject import fr.ziedelth.dtos.AyaneDto import fr.ziedelth.events.AyaneReleaseEvent +import fr.ziedelth.events.RecommendationEvent +import fr.ziedelth.repositories.AnimeRepository +import fr.ziedelth.services.RecommendationService import fr.ziedelth.utils.plugins.PluginManager import fr.ziedelth.utils.routes.Authorized import fr.ziedelth.utils.routes.BodyParam @@ -9,8 +13,15 @@ import fr.ziedelth.utils.routes.Path import fr.ziedelth.utils.routes.Response import fr.ziedelth.utils.routes.method.Post import io.ktor.http.* +import java.time.Duration class AyaneController : AbstractController("/ayane") { + @Inject + private lateinit var animeRepository: AnimeRepository + + @Inject + private lateinit var recommendationService: RecommendationService + @Path @Post @Authorized @@ -21,6 +32,11 @@ class AyaneController : AbstractController("/ayane") { Thread { PluginManager.callEvent(AyaneReleaseEvent(ayaneDto)) + Thread.currentThread().join(Duration.ofHours(3).toMillis()) + + val randomAnime = animeRepository.getAll().random() + val recommendations = recommendationService.getRecommendations(listOf(randomAnime)) + PluginManager.callEvent(RecommendationEvent(randomAnime, recommendations)) }.start() return Response.created(ayaneDto) diff --git a/src/main/kotlin/fr/ziedelth/events/RecommendationEvent.kt b/src/main/kotlin/fr/ziedelth/events/RecommendationEvent.kt new file mode 100644 index 0000000..f5baa02 --- /dev/null +++ b/src/main/kotlin/fr/ziedelth/events/RecommendationEvent.kt @@ -0,0 +1,6 @@ +package fr.ziedelth.events + +import fr.ziedelth.entities.Anime +import fr.ziedelth.utils.plugins.events.Event + +data class RecommendationEvent(val anime: Anime, val recommendations: Set>) : Event \ No newline at end of file