diff --git a/src/main/kotlin/fr/dcproject/component/article/ArticleViewManager.kt b/src/main/kotlin/fr/dcproject/component/article/database/ArticleViewRepository.kt
similarity index 88%
rename from src/main/kotlin/fr/dcproject/component/article/ArticleViewManager.kt
rename to src/main/kotlin/fr/dcproject/component/article/database/ArticleViewRepository.kt
index 757a47a..23d1686 100644
--- a/src/main/kotlin/fr/dcproject/component/article/ArticleViewManager.kt
+++ b/src/main/kotlin/fr/dcproject/component/article/database/ArticleViewRepository.kt
@@ -1,15 +1,13 @@
-package fr.dcproject.component.article
+package fr.dcproject.component.article.database
import fr.dcproject.common.entity.VersionableId
import fr.dcproject.common.utils.contentToString
import fr.dcproject.common.utils.getJsonField
import fr.dcproject.common.utils.toIso
-import fr.dcproject.component.article.database.ArticleI
import fr.dcproject.component.citizen.database.CitizenI
-import fr.dcproject.component.views.ViewManager
+import fr.dcproject.component.views.ViewRepository
import fr.dcproject.component.views.entity.ViewAggregation
import org.elasticsearch.client.Request
-import org.elasticsearch.client.Response
import org.elasticsearch.client.RestClient
import org.joda.time.DateTime
import java.util.UUID
@@ -17,11 +15,11 @@ import java.util.UUID
/**
* Wrapper for manage views with elasticsearch
*/
-class ArticleViewManager (private val restClient: RestClient) : ViewManager where A : VersionableId, A : ArticleI {
+class ArticleViewRepository (private val restClient: RestClient) : ViewRepository where A : VersionableId, A : ArticleI {
/**
* Add view on article to elasticsearch
*/
- override fun addView(ip: String, entity: A, citizen: CitizenI?, dateTime: DateTime): Response? {
+ override fun addView(ip: String, entity: A, citizen: CitizenI?, dateTime: DateTime) {
val isLogged = (citizen != null).toString()
val ref = citizen?.id ?: UUID.nameUUIDFromBytes(ip.toByteArray())!!
val request = Request(
@@ -45,7 +43,7 @@ class ArticleViewManager (private val restClient: RestClient) : ViewManager<
)
}
- return restClient.performRequest(request)
+ restClient.performRequest(request)
}
/**
diff --git a/src/main/kotlin/fr/dcproject/component/article/routes/GetOneArticle.kt b/src/main/kotlin/fr/dcproject/component/article/routes/GetOneArticle.kt
index 41b4e58..50e1e04 100644
--- a/src/main/kotlin/fr/dcproject/component/article/routes/GetOneArticle.kt
+++ b/src/main/kotlin/fr/dcproject/component/article/routes/GetOneArticle.kt
@@ -2,10 +2,10 @@ package fr.dcproject.component.article.routes
import fr.dcproject.common.security.assert
import fr.dcproject.component.article.ArticleAccessControl
-import fr.dcproject.component.article.ArticleViewManager
import fr.dcproject.component.article.database.ArticleForView
import fr.dcproject.component.article.database.ArticleRef
import fr.dcproject.component.article.database.ArticleRepository
+import fr.dcproject.component.article.database.ArticleViewRepository
import fr.dcproject.component.auth.citizenOrNull
import io.ktor.application.call
import io.ktor.features.NotFoundException
@@ -24,7 +24,7 @@ object GetOneArticle {
val article = ArticleRef(article)
}
- fun Route.getOneArticle(viewManager: ArticleViewManager, ac: ArticleAccessControl, repo: ArticleRepository) {
+ fun Route.getOneArticle(viewRepository: ArticleViewRepository, ac: ArticleAccessControl, repo: ArticleRepository) {
get {
val article: ArticleForView = repo.findById(it.article.id) ?: throw NotFoundException("Article ${it.article.id} not found")
ac.assert { canView(article, citizenOrNull) }
@@ -64,7 +64,7 @@ object GetOneArticle {
val total: Int = a.votes.total
val score: Int = a.votes.score
}
- val views: Any = viewManager.getViewsCount(article).let { v ->
+ val views: Any = viewRepository.getViewsCount(article).let { v ->
object {
val total = v.total
val unique = v.unique
@@ -76,7 +76,7 @@ object GetOneArticle {
)
launch {
- viewManager.addView(call.request.local.remoteHost, article, citizenOrNull)
+ viewRepository.addView(call.request.local.remoteHost, article, citizenOrNull)
}
}
}
diff --git a/src/main/kotlin/fr/dcproject/component/views/KoinModule.kt b/src/main/kotlin/fr/dcproject/component/views/KoinModule.kt
index dfc83fa..4f2e85f 100644
--- a/src/main/kotlin/fr/dcproject/component/views/KoinModule.kt
+++ b/src/main/kotlin/fr/dcproject/component/views/KoinModule.kt
@@ -1,8 +1,8 @@
package fr.dcproject.component.views
import fr.dcproject.application.Configuration
-import fr.dcproject.component.article.ArticleViewManager
import fr.dcproject.component.article.database.ArticleForView
+import fr.dcproject.component.article.database.ArticleViewRepository
import org.apache.http.HttpHost
import org.elasticsearch.client.RestClient
import org.koin.dsl.module
@@ -17,6 +17,6 @@ val viewKoinModule = module {
).build().apply {
createEsIndexForViews()
}
- ArticleViewManager(esClient)
+ ArticleViewRepository(esClient)
}
}
diff --git a/src/main/kotlin/fr/dcproject/component/views/ViewManager.kt b/src/main/kotlin/fr/dcproject/component/views/ViewRepository.kt
similarity index 76%
rename from src/main/kotlin/fr/dcproject/component/views/ViewManager.kt
rename to src/main/kotlin/fr/dcproject/component/views/ViewRepository.kt
index dd89700..5cfac02 100644
--- a/src/main/kotlin/fr/dcproject/component/views/ViewManager.kt
+++ b/src/main/kotlin/fr/dcproject/component/views/ViewRepository.kt
@@ -2,14 +2,13 @@ package fr.dcproject.component.views
import fr.dcproject.component.citizen.database.CitizenI
import fr.dcproject.component.views.entity.ViewAggregation
-import org.elasticsearch.client.Response
import org.joda.time.DateTime
-interface ViewManager {
+interface ViewRepository {
/**
* Add view to one entity
*/
- fun addView(ip: String, entity: T, citizen: CitizenI? = null, dateTime: DateTime = DateTime.now()): Response?
+ fun addView(ip: String, entity: T, citizen: CitizenI? = null, dateTime: DateTime = DateTime.now())
/**
* Get Views aggregations
diff --git a/src/test/kotlin/functional/ViewTest.kt b/src/test/kotlin/functional/ViewTest.kt
index d7252db..2d0de49 100644
--- a/src/test/kotlin/functional/ViewTest.kt
+++ b/src/test/kotlin/functional/ViewTest.kt
@@ -2,8 +2,8 @@ package functional
import fr.dcproject.application.Env.TEST
import fr.dcproject.application.module
-import fr.dcproject.component.article.ArticleViewManager
import fr.dcproject.component.article.database.ArticleForView
+import fr.dcproject.component.article.database.ArticleViewRepository
import fr.dcproject.component.auth.database.UserCreator
import fr.dcproject.component.citizen.database.CitizenCreator
import fr.dcproject.component.citizen.database.CitizenI
@@ -44,33 +44,33 @@ class ViewTest {
val citizenRef = CitizenRef()
withTestApplication({ module(TEST) }) {
- val viewManager: ArticleViewManager = application.get()
+ val viewRepository: ArticleViewRepository = application.get()
/* Get view before */
- val startView = viewManager.getViewsCount(article)
+ val startView = viewRepository.getViewsCount(article)
/* Add View */
- viewManager.addView(
+ viewRepository.addView(
"1.2.3.4",
article,
citizenRef
)
/* Add View */
- viewManager.addView(
+ viewRepository.addView(
"10.10.10.10",
article,
citizenRef
)
/* Add View */
- viewManager.addView(
+ viewRepository.addView(
"8.8.8.8",
article
)
/* Add View */
- viewManager.addView(
+ viewRepository.addView(
"1.1.1.1",
article
)
@@ -79,7 +79,7 @@ class ViewTest {
Thread.sleep(1000)
/* Get view */
- val afterView = viewManager.getViewsCount(article)
+ val afterView = viewRepository.getViewsCount(article)
/* Check if view has increment */
afterView.total `should be equal to` startView.total + 4