mirror of https://github.com/halo-dev/halo
Create ContentJournalController.java.
parent
2a503d8550
commit
b2415d33ce
|
@ -0,0 +1,90 @@
|
||||||
|
package run.halo.app.controller.content;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.PageUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.web.SortDefault;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import run.halo.app.model.entity.Journal;
|
||||||
|
import run.halo.app.service.JournalCommentService;
|
||||||
|
import run.halo.app.service.JournalService;
|
||||||
|
import run.halo.app.service.OptionService;
|
||||||
|
import run.halo.app.service.ThemeService;
|
||||||
|
|
||||||
|
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blog journal page controller
|
||||||
|
*
|
||||||
|
* @author ryanwang
|
||||||
|
* @date : 2019-05-04
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Controller
|
||||||
|
@RequestMapping(value = "/journal")
|
||||||
|
public class ContentJournalController {
|
||||||
|
|
||||||
|
private final JournalService journalService;
|
||||||
|
|
||||||
|
private final JournalCommentService journalCommentService;
|
||||||
|
|
||||||
|
private final OptionService optionService;
|
||||||
|
|
||||||
|
private final ThemeService themeService;
|
||||||
|
|
||||||
|
public ContentJournalController(JournalService journalService,
|
||||||
|
JournalCommentService journalCommentService,
|
||||||
|
OptionService optionService,
|
||||||
|
ThemeService themeService) {
|
||||||
|
this.journalService = journalService;
|
||||||
|
this.journalCommentService = journalCommentService;
|
||||||
|
this.optionService = optionService;
|
||||||
|
this.themeService = themeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render journal page.
|
||||||
|
*
|
||||||
|
* @param model model
|
||||||
|
* @return template path: theme/{theme}/journal.ftl
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
public String journal(Model model) {
|
||||||
|
return this.journal(model, 1, Sort.by(DESC, "createTime"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render journal page.
|
||||||
|
*
|
||||||
|
* @param model model
|
||||||
|
* @param page current page number
|
||||||
|
* @return template path: theme/{theme}/journal.ftl
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "page/{page}")
|
||||||
|
public String journal(Model model,
|
||||||
|
@PathVariable(value = "page") Integer page,
|
||||||
|
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
||||||
|
log.debug("Requested journal page, sort info: [{}]", sort);
|
||||||
|
|
||||||
|
int pageSize = optionService.getPostPageSize();
|
||||||
|
|
||||||
|
Pageable pageable = PageRequest.of(page >= 1 ? page - 1 : page, pageSize, sort);
|
||||||
|
|
||||||
|
Page<Journal> journals = journalService.listAll(pageable);
|
||||||
|
|
||||||
|
int[] rainbow = PageUtil.rainbow(page, journals.getTotalPages(), 3);
|
||||||
|
|
||||||
|
model.addAttribute("is_journal", true);
|
||||||
|
model.addAttribute("journals", journals);
|
||||||
|
model.addAttribute("rainbow", rainbow);
|
||||||
|
return themeService.render("journal");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package run.halo.app.model.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Theme controller.
|
||||||
|
*
|
||||||
|
* @author ryanwang
|
||||||
|
* @date : 2019/5/4
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class EnvironmentDTO {
|
||||||
|
|
||||||
|
private String database;
|
||||||
|
|
||||||
|
private long startTime;
|
||||||
|
}
|
|
@ -44,7 +44,7 @@ public interface JournalService extends CrudService<Journal, Integer> {
|
||||||
*
|
*
|
||||||
* @param journalQuery journal query must not be null
|
* @param journalQuery journal query must not be null
|
||||||
* @param pageable page info must not be null
|
* @param pageable page info must not be null
|
||||||
* @return a page of post
|
* @return a page of journal
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Page<Journal> pageBy(@NonNull JournalQuery journalQuery, @NonNull Pageable pageable);
|
Page<Journal> pageBy(@NonNull JournalQuery journalQuery, @NonNull Pageable pageable);
|
||||||
|
|
Loading…
Reference in New Issue