-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from vipulyaara/develop
Release 0.20.0
- Loading branch information
Showing
26 changed files
with
289 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
data/repo/src/main/java/com/kafka/data/feature/recommendation/RelatedContentRequestBody.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.kafka.data.feature.recommendation | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RelatedContentRequestBody( | ||
@SerialName("content_tagged_relationship_type") | ||
val contentTaggedRelationshipType: String, | ||
@SerialName("object") | ||
val objectX: Object, | ||
@SerialName("positive_rel") | ||
val primaryPositiveRelationshipType: String | ||
) { | ||
@Serializable | ||
data class Object( | ||
@SerialName("id") | ||
val id: String, | ||
@SerialName("type") | ||
val type: String | ||
) | ||
|
||
companion object { | ||
fun fromContent(contentId: String) = RelatedContentRequestBody( | ||
primaryPositiveRelationshipType = "viewed", | ||
contentTaggedRelationshipType = "taggedWith", | ||
objectX = Object(id = contentId, type = "content") | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
domain/src/main/java/org/kafka/domain/interactors/recommendation/GetRelatedContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.kafka.domain.interactors.recommendation | ||
|
||
import com.google.firebase.auth.FirebaseAuth | ||
import com.kafka.data.entities.Item | ||
import com.kafka.data.feature.item.ItemRepository | ||
import com.kafka.data.feature.recommendation.RecommendationRepository | ||
import com.kafka.data.model.ArchiveQuery | ||
import com.kafka.data.model.booksByIdentifiers | ||
import kotlinx.coroutines.withContext | ||
import org.kafka.base.CoroutineDispatchers | ||
import org.kafka.base.debug | ||
import org.kafka.base.domain.ResultInteractor | ||
import org.kafka.domain.interactors.query.BuildRemoteQuery | ||
import javax.inject.Inject | ||
|
||
class GetRelatedContent @Inject constructor( | ||
private val recommendationRepository: RecommendationRepository, | ||
private val itemRepository: ItemRepository, | ||
private val buildRemoteQuery: BuildRemoteQuery, | ||
private val firebaseAuth: FirebaseAuth, | ||
private val dispatchers: CoroutineDispatchers | ||
) : ResultInteractor<String, List<Item>>() { | ||
|
||
override suspend fun doWork(params: String): List<Item> = withContext(dispatchers.io) { | ||
if (firebaseAuth.currentUser != null) { | ||
val response = recommendationRepository.getRelatedContent(params) | ||
val itemIds = response.getOrThrow().items.map { it.objectX.id } | ||
|
||
val query = ArchiveQuery().booksByIdentifiers(itemIds) | ||
val items = itemRepository.updateQuery(buildRemoteQuery(query)) | ||
|
||
debug { "Recommended items: ${itemIds.size} $items" } | ||
|
||
items | ||
.filterNot { it.isInappropriate } // remove inappropriate items | ||
.distinctBy { it.itemId } | ||
} else { | ||
emptyList() | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.