Search in sources :

Example 1 with PagingHelper

use of li.naska.bgg.util.PagingHelper in project bgg-api by tnaskali.

the class ForumsService method getPagedThreads.

public Mono<Page<Thread>> getPagedThreads(Integer id, PagingParams pagingParams) {
    PagingHelper helper = new PagingHelper(pagingParams.getSize(), pagingParams.getPage(), BGG_FORUM_THREADS_PAGE_SIZE);
    BggForumQueryParams firstPageQueryParams = new BggForumQueryParams();
    firstPageQueryParams.setId(id);
    firstPageQueryParams.setPage(helper.getBggStartPage());
    return getForum(firstPageQueryParams).flatMap(forum -> helper.getBggPagesRange(forum.getNumthreads()).flatMapSequential(page -> {
        if (page == helper.getBggStartPage()) {
            return Mono.just(forum);
        }
        BggForumQueryParams queryParams = new BggForumQueryParams();
        queryParams.setId(id);
        queryParams.setPage(page);
        return getForum(queryParams);
    }).flatMapIterable(Forum::getThreads).collect(Collectors.toList()).map(list -> helper.buildPage(list, forum.getNumthreads())));
}
Also used : BggForumListsRepository(li.naska.bgg.repository.BggForumListsRepository) BggThreadsRepository(li.naska.bgg.repository.BggThreadsRepository) Thread(li.naska.bgg.resource.v3.model.Thread) BggForumsRepository(li.naska.bgg.repository.BggForumsRepository) BggForumsQueryParams(li.naska.bgg.repository.model.BggForumsQueryParams) ThreadParamsMapper(li.naska.bgg.mapper.ThreadParamsMapper) PagingHelper(li.naska.bgg.util.PagingHelper) Autowired(org.springframework.beans.factory.annotation.Autowired) Page(li.naska.bgg.util.Page) ThreadMapper(li.naska.bgg.mapper.ThreadMapper) Service(org.springframework.stereotype.Service) ForumMapper(li.naska.bgg.mapper.ForumMapper) BggThreadQueryParams(li.naska.bgg.repository.model.BggThreadQueryParams) ForumsParams(li.naska.bgg.resource.v3.model.ForumsParams) XmlProcessor(li.naska.bgg.util.XmlProcessor) ThreadParams(li.naska.bgg.resource.v3.model.ThreadParams) ItemType(com.boardgamegeek.enums.ItemType) BggForumQueryParams(li.naska.bgg.repository.model.BggForumQueryParams) Mono(reactor.core.publisher.Mono) Collectors(java.util.stream.Collectors) PagingParams(li.naska.bgg.util.PagingParams) Forum(li.naska.bgg.resource.v3.model.Forum) Flux(reactor.core.publisher.Flux) List(java.util.List) Forums(com.boardgamegeek.forumlist.Forums) ForumListsParamsMapper(li.naska.bgg.mapper.ForumListsParamsMapper) PagingHelper(li.naska.bgg.util.PagingHelper) BggForumQueryParams(li.naska.bgg.repository.model.BggForumQueryParams)

Example 2 with PagingHelper

use of li.naska.bgg.util.PagingHelper 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)

Example 3 with PagingHelper

use of li.naska.bgg.util.PagingHelper in project bgg-api by tnaskali.

the class ThingsService method getPagedComments.

public Mono<Page<Comment>> getPagedComments(Integer id, PagingParams pagingParams) {
    PagingHelper helper = new PagingHelper(pagingParams.getSize(), pagingParams.getPage(), BGG_THING_COMMENTS_PAGE_SIZE);
    BggThingsQueryParams firstPageQueryParams = new BggThingsQueryParams();
    firstPageQueryParams.setId(id.toString());
    firstPageQueryParams.setComments(1);
    firstPageQueryParams.setPage(helper.getBggStartPage());
    firstPageQueryParams.setPagesize(BGG_THING_COMMENTS_PAGE_SIZE);
    return getThing(firstPageQueryParams).flatMap(thing -> helper.getBggPagesRange(thing.getNumcomments()).flatMapSequential(page -> {
        BggThingsQueryParams queryParams = new BggThingsQueryParams();
        queryParams.setId(id.toString());
        queryParams.setComments(1);
        queryParams.setPage(page);
        queryParams.setPagesize(BGG_THING_COMMENTS_PAGE_SIZE);
        return getThing(queryParams);
    }).flatMapIterable(Thing::getComments).collect(Collectors.toList()).map(list -> helper.buildPage(list, thing.getNumcomments())));
}
Also used : ThingsParamsMapper(li.naska.bgg.mapper.ThingsParamsMapper) CollectionParams(li.naska.bgg.resource.v3.model.CollectionParams) Version(li.naska.bgg.resource.v3.model.Thing.Version) ThingsParams(li.naska.bgg.resource.v3.model.ThingsParams) PagingHelper(li.naska.bgg.util.PagingHelper) Autowired(org.springframework.beans.factory.annotation.Autowired) Page(li.naska.bgg.util.Page) CollectionMapper(li.naska.bgg.mapper.CollectionMapper) BggCollectionRepository(li.naska.bgg.repository.BggCollectionRepository) Service(org.springframework.stereotype.Service) Things(com.boardgamegeek.thing.Things) BggCollectionQueryParams(li.naska.bgg.repository.model.BggCollectionQueryParams) Thing(li.naska.bgg.resource.v3.model.Thing) XmlProcessor(li.naska.bgg.util.XmlProcessor) BggThingsRepository(li.naska.bgg.repository.BggThingsRepository) Video(li.naska.bgg.resource.v3.model.Thing.Video) ResponseStatusException(org.springframework.web.server.ResponseStatusException) BggThingsQueryParams(li.naska.bgg.repository.model.BggThingsQueryParams) CollectionItemSubtype(com.boardgamegeek.enums.CollectionItemSubtype) Mono(reactor.core.publisher.Mono) MarketplaceListing(li.naska.bgg.resource.v3.model.Thing.MarketplaceListing) Collectors(java.util.stream.Collectors) Comment(li.naska.bgg.resource.v3.model.Thing.Comment) PagingParams(li.naska.bgg.util.PagingParams) CollectionParamsMapper(li.naska.bgg.mapper.CollectionParamsMapper) ThingMapper(li.naska.bgg.mapper.ThingMapper) HttpStatus(org.springframework.http.HttpStatus) Flux(reactor.core.publisher.Flux) List(java.util.List) Collection(li.naska.bgg.resource.v3.model.Collection) PagingHelper(li.naska.bgg.util.PagingHelper) BggThingsQueryParams(li.naska.bgg.repository.model.BggThingsQueryParams)

Example 4 with PagingHelper

use of li.naska.bgg.util.PagingHelper in project bgg-api by tnaskali.

the class ThingsService method getPagedRatings.

public Mono<Page<Comment>> getPagedRatings(Integer id, PagingParams pagingParams) {
    PagingHelper helper = new PagingHelper(pagingParams.getSize(), pagingParams.getPage(), BGG_THING_COMMENTS_PAGE_SIZE);
    BggThingsQueryParams firstPageQueryParams = new BggThingsQueryParams();
    firstPageQueryParams.setId(id.toString());
    firstPageQueryParams.setRatingcomments(1);
    firstPageQueryParams.setPage(helper.getBggStartPage());
    firstPageQueryParams.setPagesize(BGG_THING_COMMENTS_PAGE_SIZE);
    return getThing(firstPageQueryParams).flatMap(thing -> helper.getBggPagesRange(thing.getNumcomments()).flatMapSequential(page -> {
        BggThingsQueryParams queryParams = new BggThingsQueryParams();
        queryParams.setId(id.toString());
        queryParams.setRatingcomments(1);
        queryParams.setPage(page);
        queryParams.setPagesize(BGG_THING_COMMENTS_PAGE_SIZE);
        return getThing(queryParams);
    }).flatMapIterable(Thing::getComments).collect(Collectors.toList()).map(list -> helper.buildPage(list, thing.getNumcomments())));
}
Also used : ThingsParamsMapper(li.naska.bgg.mapper.ThingsParamsMapper) CollectionParams(li.naska.bgg.resource.v3.model.CollectionParams) Version(li.naska.bgg.resource.v3.model.Thing.Version) ThingsParams(li.naska.bgg.resource.v3.model.ThingsParams) PagingHelper(li.naska.bgg.util.PagingHelper) Autowired(org.springframework.beans.factory.annotation.Autowired) Page(li.naska.bgg.util.Page) CollectionMapper(li.naska.bgg.mapper.CollectionMapper) BggCollectionRepository(li.naska.bgg.repository.BggCollectionRepository) Service(org.springframework.stereotype.Service) Things(com.boardgamegeek.thing.Things) BggCollectionQueryParams(li.naska.bgg.repository.model.BggCollectionQueryParams) Thing(li.naska.bgg.resource.v3.model.Thing) XmlProcessor(li.naska.bgg.util.XmlProcessor) BggThingsRepository(li.naska.bgg.repository.BggThingsRepository) Video(li.naska.bgg.resource.v3.model.Thing.Video) ResponseStatusException(org.springframework.web.server.ResponseStatusException) BggThingsQueryParams(li.naska.bgg.repository.model.BggThingsQueryParams) CollectionItemSubtype(com.boardgamegeek.enums.CollectionItemSubtype) Mono(reactor.core.publisher.Mono) MarketplaceListing(li.naska.bgg.resource.v3.model.Thing.MarketplaceListing) Collectors(java.util.stream.Collectors) Comment(li.naska.bgg.resource.v3.model.Thing.Comment) PagingParams(li.naska.bgg.util.PagingParams) CollectionParamsMapper(li.naska.bgg.mapper.CollectionParamsMapper) ThingMapper(li.naska.bgg.mapper.ThingMapper) HttpStatus(org.springframework.http.HttpStatus) Flux(reactor.core.publisher.Flux) List(java.util.List) Collection(li.naska.bgg.resource.v3.model.Collection) PagingHelper(li.naska.bgg.util.PagingHelper) BggThingsQueryParams(li.naska.bgg.repository.model.BggThingsQueryParams)

Example 5 with PagingHelper

use of li.naska.bgg.util.PagingHelper in project bgg-api by tnaskali.

the class UsersService method getPagedBuddies.

public Mono<Page<Buddy>> getPagedBuddies(String username, PagingParams pagingParams) {
    PagingHelper helper = new PagingHelper(pagingParams.getSize(), pagingParams.getPage(), BGG_USER_BUDDIES_PAGE_SIZE);
    BggUserQueryParams firstPageQueryParams = new BggUserQueryParams();
    firstPageQueryParams.setName(username);
    firstPageQueryParams.setBuddies(1);
    firstPageQueryParams.setPage(helper.getBggStartPage());
    return getUser(firstPageQueryParams).flatMap(user -> helper.getBggPagesRange(user.getNumbuddies()).flatMapSequential(page -> {
        if (page == helper.getBggStartPage()) {
            return Mono.just(user);
        }
        BggUserQueryParams queryParams = new BggUserQueryParams();
        queryParams.setName(username);
        queryParams.setBuddies(1);
        queryParams.setPage(page);
        return getUser(queryParams);
    }).flatMapIterable(User::getBuddies).collect(Collectors.toList()).map(list -> helper.buildPage(list, user.getNumbuddies())));
}
Also used : BggUserQueryParams(li.naska.bgg.repository.model.BggUserQueryParams) Guild(li.naska.bgg.resource.v3.model.Guild) UserParams(li.naska.bgg.resource.v3.model.UserParams) BggUsersRepository(li.naska.bgg.repository.BggUsersRepository) PagingHelper(li.naska.bgg.util.PagingHelper) Autowired(org.springframework.beans.factory.annotation.Autowired) Mono(reactor.core.publisher.Mono) UserParamsMapper(li.naska.bgg.mapper.UserParamsMapper) UserMapper(li.naska.bgg.mapper.UserMapper) Buddy(li.naska.bgg.resource.v3.model.User.Buddy) Page(li.naska.bgg.util.Page) Collectors(java.util.stream.Collectors) PagingParams(li.naska.bgg.util.PagingParams) Flux(reactor.core.publisher.Flux) List(java.util.List) Service(org.springframework.stereotype.Service) XmlProcessor(li.naska.bgg.util.XmlProcessor) User(li.naska.bgg.resource.v3.model.User) PagingHelper(li.naska.bgg.util.PagingHelper) BggUserQueryParams(li.naska.bgg.repository.model.BggUserQueryParams)

Aggregations

List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Page (li.naska.bgg.util.Page)7 PagingHelper (li.naska.bgg.util.PagingHelper)7 PagingParams (li.naska.bgg.util.PagingParams)7 XmlProcessor (li.naska.bgg.util.XmlProcessor)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 Service (org.springframework.stereotype.Service)7 Flux (reactor.core.publisher.Flux)7 Mono (reactor.core.publisher.Mono)7 HttpStatus (org.springframework.http.HttpStatus)3 ResponseStatusException (org.springframework.web.server.ResponseStatusException)3 CollectionItemSubtype (com.boardgamegeek.enums.CollectionItemSubtype)2 ItemType (com.boardgamegeek.enums.ItemType)2 Things (com.boardgamegeek.thing.Things)2 CollectionMapper (li.naska.bgg.mapper.CollectionMapper)2 CollectionParamsMapper (li.naska.bgg.mapper.CollectionParamsMapper)2 ThingMapper (li.naska.bgg.mapper.ThingMapper)2 ThingsParamsMapper (li.naska.bgg.mapper.ThingsParamsMapper)2 BggCollectionRepository (li.naska.bgg.repository.BggCollectionRepository)2