Search in sources :

Example 1 with ShortUrl

use of com.github.lybgeek.shorturl.model.ShortUrl in project springboot-learning by lyb-geek.

the class ShortUrlDao method pageShortUrls.

public PageResult<ShortUrl> pageShortUrls(PageQuery<ShortUrl> pageQuery) {
    Sort sort = new Sort(Direction.DESC, "id");
    Pageable pageable = PageRequest.of(pageQuery.getPageNo() - 1, pageQuery.getPageSize(), sort);
    Specification<ShortUrl> specification = (Specification<ShortUrl>) (root, criteriaQuery, criteriaBuilder) -> {
        ShortUrl queryParams = pageQuery.getQueryParams();
        if (queryParams != null) {
            List<Predicate> predicates = getPredicates(root, criteriaBuilder, queryParams);
            if (CollectionUtils.isNotEmpty(predicates)) {
                return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
            }
        }
        return null;
    };
    Page<ShortUrl> shortUrlPage = shortUrlRepository.findAll(specification, pageable);
    if (ObjectUtils.isNotEmpty(shortUrlPage)) {
        return PageUtil.INSTANCE.getPage(shortUrlPage);
    }
    return null;
}
Also used : Pageable(org.springframework.data.domain.Pageable) ShortUrl(com.github.lybgeek.shorturl.model.ShortUrl) Sort(org.springframework.data.domain.Sort) Specification(org.springframework.data.jpa.domain.Specification) Predicate(javax.persistence.criteria.Predicate)

Example 2 with ShortUrl

use of com.github.lybgeek.shorturl.model.ShortUrl in project springboot-learning by lyb-geek.

the class ShortUrlServiceImpl method listShortUrls.

@Override
@EsOperate(type = OperateType.QUERY, indexName = ElasticsearchConstant.SHORT_URL_INDEX)
public List<ShortUrlDTO> listShortUrls(ShortUrlDTO shortUrlDTO) {
    ShortUrl shortUrl = BeanMapperUtil.map(shortUrlDTO, ShortUrl.class);
    List<ShortUrl> shortUrls = shortUrlDao.listShortUrls(shortUrl);
    return BeanMapperUtil.mapList(shortUrls, ShortUrlDTO.class);
}
Also used : ShortUrl(com.github.lybgeek.shorturl.model.ShortUrl) EsOperate(com.github.lybgeek.elasticsearch.annotation.EsOperate)

Example 3 with ShortUrl

use of com.github.lybgeek.shorturl.model.ShortUrl in project springboot-learning by lyb-geek.

the class ShortUrlServiceImpl method getShortUrlPageQuery.

private PageQuery<ShortUrl> getShortUrlPageQuery(PageQuery<ShortUrlDTO> pageQuery) {
    PageQuery<ShortUrl> query = new PageQuery<>();
    BeanUtils.copyProperties(pageQuery, query);
    ShortUrl shortUrl = BeanMapperUtil.map(pageQuery.getQueryParams(), ShortUrl.class);
    query.setQueryParams(shortUrl);
    return query;
}
Also used : ShortUrl(com.github.lybgeek.shorturl.model.ShortUrl) PageQuery(com.github.lybgeek.common.model.PageQuery)

Example 4 with ShortUrl

use of com.github.lybgeek.shorturl.model.ShortUrl in project springboot-learning by lyb-geek.

the class ShortUrlServiceImpl method saveShortUrl.

@Override
@EsOperate(type = OperateType.ADD, indexName = ElasticsearchConstant.SHORT_URL_INDEX)
public ShortUrlDTO saveShortUrl(ShortUrlDTO shortUrlDTO) {
    ShortUrl shortUrl = BeanMapperUtil.map(shortUrlDTO, ShortUrl.class);
    ShortUrl dbShortUrl = shortUrlDao.save(shortUrl);
    return BeanMapperUtil.map(dbShortUrl, ShortUrlDTO.class);
}
Also used : ShortUrl(com.github.lybgeek.shorturl.model.ShortUrl) EsOperate(com.github.lybgeek.elasticsearch.annotation.EsOperate)

Example 5 with ShortUrl

use of com.github.lybgeek.shorturl.model.ShortUrl in project springboot-learning by lyb-geek.

the class ShortUrlServiceImpl method saveAndReturnShortUrl.

@Override
public String saveAndReturnShortUrl(ShortUrlDTO shortUrlDTO) {
    ShortUrl shortUrl = BeanMapperUtil.map(shortUrlDTO, ShortUrl.class);
    ShortUrl dbShortUrl = shortUrlDao.save(shortUrl);
    applicationEventPublisher.publishEvent(dbShortUrl);
    return ShortUrlUtil.getShortUrl(dbShortUrl.getId());
}
Also used : ShortUrl(com.github.lybgeek.shorturl.model.ShortUrl)

Aggregations

ShortUrl (com.github.lybgeek.shorturl.model.ShortUrl)5 EsOperate (com.github.lybgeek.elasticsearch.annotation.EsOperate)2 PageQuery (com.github.lybgeek.common.model.PageQuery)1 Predicate (javax.persistence.criteria.Predicate)1 Pageable (org.springframework.data.domain.Pageable)1 Sort (org.springframework.data.domain.Sort)1 Specification (org.springframework.data.jpa.domain.Specification)1