Search in sources :

Example 1 with Play

use of li.naska.bgg.resource.v3.model.Play in project bgg-api by tnaskali.

the class PlaysService method getPagedPlays.

private Mono<Page<Play>> getPagedPlays(Supplier<BggPlaysQueryParams> queryParamsSupplier, PagingParams pagingParams) {
    PagingHelper helper = new PagingHelper(pagingParams.getSize(), pagingParams.getPage(), BGG_PLAYS_PAGE_SIZE);
    BggPlaysQueryParams firstPageQueryParams = queryParamsSupplier.get();
    firstPageQueryParams.setPage(helper.getBggStartPage());
    return getPlays(firstPageQueryParams).flatMap(plays -> helper.getBggPagesRange(plays.getNumplays()).flatMapSequential(page -> {
        if (page == helper.getBggStartPage()) {
            return Mono.just(plays);
        }
        BggPlaysQueryParams queryParams = queryParamsSupplier.get();
        queryParams.setPage(page);
        return getPlays(queryParams);
    }).flatMapIterable(Plays::getPlays).collect(Collectors.toList()).map(list -> helper.buildPage(list, plays.getNumplays())));
}
Also used : BggGeekplayRequestBody(li.naska.bgg.repository.model.BggGeekplayRequestBody) SneakyThrows(lombok.SneakyThrows) PagingHelper(li.naska.bgg.util.PagingHelper) GeekplayParamsMapper(li.naska.bgg.mapper.GeekplayParamsMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) PlaysParamsMapper(li.naska.bgg.mapper.PlaysParamsMapper) Page(li.naska.bgg.util.Page) Supplier(java.util.function.Supplier) Service(org.springframework.stereotype.Service) Play(li.naska.bgg.resource.v3.model.Play) XmlProcessor(li.naska.bgg.util.XmlProcessor) ItemPlaysParams(li.naska.bgg.resource.v3.model.ItemPlaysParams) BggGeekplayResponseBody(li.naska.bgg.repository.model.BggGeekplayResponseBody) ItemType(com.boardgamegeek.enums.ItemType) ResponseStatusException(org.springframework.web.server.ResponseStatusException) PlaysMapper(li.naska.bgg.mapper.PlaysMapper) BggPlaysQueryParams(li.naska.bgg.repository.model.BggPlaysQueryParams) BggGeekplaysRepository(li.naska.bgg.repository.BggGeekplaysRepository) Mono(reactor.core.publisher.Mono) Collectors(java.util.stream.Collectors) PagingParams(li.naska.bgg.util.PagingParams) Plays(li.naska.bgg.resource.v3.model.Plays) Objects(java.util.Objects) UserPlaysParams(li.naska.bgg.resource.v3.model.UserPlaysParams) HttpStatus(org.springframework.http.HttpStatus) Flux(reactor.core.publisher.Flux) List(java.util.List) BggPlaysRepository(li.naska.bgg.repository.BggPlaysRepository) PagingHelper(li.naska.bgg.util.PagingHelper) BggPlaysQueryParams(li.naska.bgg.repository.model.BggPlaysQueryParams)

Aggregations

ItemType (com.boardgamegeek.enums.ItemType)1 List (java.util.List)1 Objects (java.util.Objects)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 GeekplayParamsMapper (li.naska.bgg.mapper.GeekplayParamsMapper)1 PlaysMapper (li.naska.bgg.mapper.PlaysMapper)1 PlaysParamsMapper (li.naska.bgg.mapper.PlaysParamsMapper)1 BggGeekplaysRepository (li.naska.bgg.repository.BggGeekplaysRepository)1 BggPlaysRepository (li.naska.bgg.repository.BggPlaysRepository)1 BggGeekplayRequestBody (li.naska.bgg.repository.model.BggGeekplayRequestBody)1 BggGeekplayResponseBody (li.naska.bgg.repository.model.BggGeekplayResponseBody)1 BggPlaysQueryParams (li.naska.bgg.repository.model.BggPlaysQueryParams)1 ItemPlaysParams (li.naska.bgg.resource.v3.model.ItemPlaysParams)1 Play (li.naska.bgg.resource.v3.model.Play)1 Plays (li.naska.bgg.resource.v3.model.Plays)1 UserPlaysParams (li.naska.bgg.resource.v3.model.UserPlaysParams)1 Page (li.naska.bgg.util.Page)1 PagingHelper (li.naska.bgg.util.PagingHelper)1 PagingParams (li.naska.bgg.util.PagingParams)1