Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
Add recommendation feature to AyaneController
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Nov 22, 2023
1 parent 5cc1d27 commit 8b11f1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/kotlin/fr/ziedelth/controllers/AyaneController.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
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
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<AyaneDto>("/ayane") {
@Inject
private lateinit var animeRepository: AnimeRepository

@Inject
private lateinit var recommendationService: RecommendationService

@Path
@Post
@Authorized
Expand All @@ -21,6 +32,11 @@ class AyaneController : AbstractController<AyaneDto>("/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)
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/fr/ziedelth/events/RecommendationEvent.kt
Original file line number Diff line number Diff line change
@@ -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<Pair<Anime, Double>>) : Event

0 comments on commit 8b11f1e

Please sign in to comment.