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;
}
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);
}
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;
}
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);
}
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());
}
Aggregations