Commit e849afc0 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Add model for getting project events.

parent 8ae70e72
......@@ -124,6 +124,19 @@ interface GitlabApi {
@Query("per_page") pageSize: Int
): Single<List<Event>>
@GET("$API_PATH/projects/{project_id}/events")
fun getProjectEvents(
@Path("project_id") projectId: Long,
@Query("action") action: EventAction?,
@Query("target_type") targetType: EventTarget?,
@Query("before") beforeDay: String?,
@Query("after") afterDay: String?,
@Query("sort") sort: Sort?,
@Query("order_by") orderBy: OrderBy?,
@Query("page") page: Int,
@Query("per_page") pageSize: Int
): Single<List<Event>>
@GET("$API_PATH/merge_requests")
fun getMyMergeRequests(
@Query("state") state: MergeRequestState?,
......
......@@ -9,5 +9,9 @@ import javax.inject.Inject
class EventInteractor @Inject constructor(
private val eventRepository: EventRepository
) {
fun getEvents(page: Int) = eventRepository.getEvents(page = page)
fun getEvents(page: Int) =
eventRepository.getEvents(page = page)
fun getProjectEvents(projectId: Long, page: Int) =
eventRepository.getProjectEvents(projectId = projectId, page = page)
}
\ No newline at end of file
......@@ -14,8 +14,8 @@ import ru.terrakok.gitlabclient.entity.event.EventAction
import ru.terrakok.gitlabclient.entity.event.EventTarget
import ru.terrakok.gitlabclient.entity.event.EventTargetType
import ru.terrakok.gitlabclient.model.data.server.GitlabApi
import ru.terrakok.gitlabclient.model.system.SchedulersProvider
import ru.terrakok.gitlabclient.model.data.server.MarkDownUrlResolver
import ru.terrakok.gitlabclient.model.system.SchedulersProvider
import ru.terrakok.gitlabclient.toothpick.PrimitiveWrapper
import ru.terrakok.gitlabclient.toothpick.qualifier.DefaultPageSize
import javax.inject.Inject
......@@ -63,6 +63,40 @@ class EventRepository @Inject constructor(
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
fun getProjectEvents(
projectId: Long,
action: EventAction? = null,
targetType: EventTarget? = null,
beforeDay: LocalDateTime? = null,
afterDay: LocalDateTime? = null,
sort: Sort? = Sort.DESC,
orderBy: OrderBy = OrderBy.UPDATED_AT,
page: Int,
pageSize: Int = defaultPageSize
): Single<List<TargetHeader>> = api
.getProjectEvents(
projectId,
action,
targetType,
beforeDay?.run { this.toLocalDate().toString() },
afterDay?.run { this.toLocalDate().toString() },
sort,
orderBy,
page,
pageSize
)
.flatMap { events ->
Single.zip(
Single.just(events),
getDistinctProjects(events),
BiFunction<List<Event>, Map<Long, Project>, List<TargetHeader>> { sourceEvents, projects ->
sourceEvents.map { getTargetHeader(it, projects[it.projectId]) }
}
)
}
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
private fun getDistinctProjects(events: List<Event>): Single<Map<Long, Project>> {
return Observable.fromIterable(events)
.distinct { it.projectId }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment