mirror of https://github.com/halo-dev/halo
solved #361
parent
9015f30c51
commit
54e17acfc0
|
@ -2,6 +2,7 @@ package run.halo.app.controller.content;
|
||||||
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.web.SortDefault;
|
import org.springframework.data.web.SortDefault;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
@ -11,14 +12,12 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import run.halo.app.cache.StringCacheStore;
|
import run.halo.app.cache.StringCacheStore;
|
||||||
import run.halo.app.exception.ForbiddenException;
|
import run.halo.app.exception.ForbiddenException;
|
||||||
|
import run.halo.app.model.dto.PhotoDTO;
|
||||||
import run.halo.app.model.entity.Sheet;
|
import run.halo.app.model.entity.Sheet;
|
||||||
import run.halo.app.model.enums.PostStatus;
|
import run.halo.app.model.enums.PostStatus;
|
||||||
import run.halo.app.model.support.HaloConst;
|
import run.halo.app.model.support.HaloConst;
|
||||||
import run.halo.app.model.vo.BaseCommentVO;
|
import run.halo.app.model.vo.BaseCommentVO;
|
||||||
import run.halo.app.service.OptionService;
|
import run.halo.app.service.*;
|
||||||
import run.halo.app.service.SheetCommentService;
|
|
||||||
import run.halo.app.service.SheetService;
|
|
||||||
import run.halo.app.service.ThemeService;
|
|
||||||
import run.halo.app.utils.MarkdownUtils;
|
import run.halo.app.utils.MarkdownUtils;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -41,6 +40,8 @@ public class ContentSheetController {
|
||||||
|
|
||||||
private final SheetCommentService sheetCommentService;
|
private final SheetCommentService sheetCommentService;
|
||||||
|
|
||||||
|
private final PhotoService photoService;
|
||||||
|
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
private final StringCacheStore cacheStore;
|
private final StringCacheStore cacheStore;
|
||||||
|
@ -48,11 +49,13 @@ public class ContentSheetController {
|
||||||
public ContentSheetController(SheetService sheetService,
|
public ContentSheetController(SheetService sheetService,
|
||||||
ThemeService themeService,
|
ThemeService themeService,
|
||||||
SheetCommentService sheetCommentService,
|
SheetCommentService sheetCommentService,
|
||||||
|
PhotoService photoService,
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
StringCacheStore cacheStore) {
|
StringCacheStore cacheStore) {
|
||||||
this.sheetService = sheetService;
|
this.sheetService = sheetService;
|
||||||
this.themeService = themeService;
|
this.themeService = themeService;
|
||||||
this.sheetCommentService = sheetCommentService;
|
this.sheetCommentService = sheetCommentService;
|
||||||
|
this.photoService = photoService;
|
||||||
this.optionService = optionService;
|
this.optionService = optionService;
|
||||||
this.cacheStore = cacheStore;
|
this.cacheStore = cacheStore;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +66,26 @@ public class ContentSheetController {
|
||||||
* @return template path: themes/{theme}/photos.ftl
|
* @return template path: themes/{theme}/photos.ftl
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/photos")
|
@GetMapping(value = "/photos")
|
||||||
public String photos() {
|
public String photos(Model model,
|
||||||
|
@RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
|
||||||
|
return photos(model, 1, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render photo page
|
||||||
|
*
|
||||||
|
* @param model model
|
||||||
|
* @param page current page
|
||||||
|
* @param size current page size
|
||||||
|
* @return template path: themes/{theme}/photos.ftl
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/photos/page/{page}")
|
||||||
|
public String photos(Model model,
|
||||||
|
@PathVariable(value = "page") Integer page,
|
||||||
|
@RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
|
||||||
|
Pageable pageable = PageRequest.of(page >= 1 ? page - 1 : page, size, Sort.by(DESC, "createTime"));
|
||||||
|
Page<PhotoDTO> photos = photoService.pageBy(pageable);
|
||||||
|
model.addAttribute("photos", photos);
|
||||||
return themeService.render("photos");
|
return themeService.render("photos");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.util.List;
|
||||||
* Photo service interface.
|
* Photo service interface.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
|
* @author ryanwang
|
||||||
* @date 2019-03-14
|
* @date 2019-03-14
|
||||||
*/
|
*/
|
||||||
public interface PhotoService extends CrudService<Photo, Integer> {
|
public interface PhotoService extends CrudService<Photo, Integer> {
|
||||||
|
@ -46,6 +47,14 @@ public interface PhotoService extends CrudService<Photo, Integer> {
|
||||||
*/
|
*/
|
||||||
List<PhotoDTO> listByTeam(@NonNull String team, Sort sort);
|
List<PhotoDTO> listByTeam(@NonNull String team, Sort sort);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pages photo output dtos.
|
||||||
|
*
|
||||||
|
* @param pageable page info must not be null
|
||||||
|
* @return a page of photo output dto
|
||||||
|
*/
|
||||||
|
Page<PhotoDTO> pageBy(@NonNull Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pages photo output dtos.
|
* Pages photo output dtos.
|
||||||
*
|
*
|
||||||
|
|
|
@ -82,6 +82,15 @@ public class PhotoServiceImpl extends AbstractCrudService<Photo, Integer> implem
|
||||||
return photos.stream().map(photo -> (PhotoDTO) new PhotoDTO().convertFrom(photo)).collect(Collectors.toList());
|
return photos.stream().map(photo -> (PhotoDTO) new PhotoDTO().convertFrom(photo)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<PhotoDTO> pageBy(Pageable pageable) {
|
||||||
|
Assert.notNull(pageable, "Page info must not be null");
|
||||||
|
|
||||||
|
Page<Photo> photos = photoRepository.findAll(pageable);
|
||||||
|
|
||||||
|
return photos.map(photo -> new PhotoDTO().convertFrom(photo));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<PhotoDTO> pageDtosBy(Pageable pageable, PhotoQuery photoQuery) {
|
public Page<PhotoDTO> pageDtosBy(Pageable pageable, PhotoQuery photoQuery) {
|
||||||
Assert.notNull(pageable, "Page info must not be null");
|
Assert.notNull(pageable, "Page info must not be null");
|
||||||
|
|
Loading…
Reference in New Issue