Support internal sheet list api.

pull/172/head
ruibaby 2019-05-25 14:08:22 +08:00
parent 373c4ce285
commit 7c9f8b01f3
4 changed files with 84 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;
import run.halo.app.model.dto.InternalSheetDTO;
import run.halo.app.model.dto.post.BasePostDetailDTO;
import run.halo.app.model.entity.Sheet;
import run.halo.app.model.enums.PostStatus;
@ -13,6 +14,7 @@ import run.halo.app.model.vo.SheetListVO;
import run.halo.app.service.SheetService;
import javax.validation.Valid;
import java.util.List;
import static org.springframework.data.domain.Sort.Direction.DESC;
@ -20,6 +22,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
* Sheet controller.
*
* @author johnniang
* @author ryanwang
* @date 19-4-24
*/
@RestController
@ -46,6 +49,12 @@ public class SheetController {
return sheetService.convertToListVo(sheetPage);
}
@GetMapping("internal")
@ApiOperation("Lists internal sheets")
public List<InternalSheetDTO> internalSheets() {
return sheetService.listInternal();
}
@PostMapping
@ApiOperation("Creates a sheet")
public BasePostDetailDTO createBy(@RequestBody @Valid SheetParam sheetParam,

View File

@ -0,0 +1,21 @@
package run.halo.app.model.dto;
import lombok.Data;
/**
* Theme controller.
*
* @author ryanwang
* @date : 2019/5/4
*/
@Data
public class InternalSheetDTO {
private Integer id;
private String title;
private String url;
private boolean status;
}

View File

@ -2,15 +2,19 @@ package run.halo.app.service;
import org.springframework.data.domain.Page;
import org.springframework.lang.NonNull;
import run.halo.app.model.dto.InternalSheetDTO;
import run.halo.app.model.entity.Sheet;
import run.halo.app.model.enums.PostStatus;
import run.halo.app.model.vo.SheetListVO;
import run.halo.app.service.base.BasePostService;
import java.util.List;
/**
* Sheet service interface.
*
* @author johnniang
* @author ryanwang
* @date 19-4-24
*/
public interface SheetService extends BasePostService<Sheet> {
@ -72,6 +76,14 @@ public interface SheetService extends BasePostService<Sheet> {
@NonNull
String exportMarkdown(@NonNull Sheet sheet);
/**
* List internal sheets.
*
* @return list of internal sheets
*/
@NonNull
List<InternalSheetDTO> listInternal();
/**
* Converts to list dto page.
*

View File

@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import run.halo.app.event.logger.LogEvent;
import run.halo.app.event.post.SheetVisitEvent;
import run.halo.app.model.dto.InternalSheetDTO;
import run.halo.app.model.entity.Sheet;
import run.halo.app.model.enums.LogType;
import run.halo.app.model.enums.PostStatus;
@ -16,9 +17,11 @@ import run.halo.app.repository.SheetRepository;
import run.halo.app.service.OptionService;
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.ServiceUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -27,6 +30,7 @@ import java.util.Set;
* Sheet service implementation.
*
* @author johnniang
* @author ryanwang
* @date 19-4-24
*/
@Service
@ -38,14 +42,18 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
private final SheetCommentService sheetCommentService;
private final ThemeService themeService;
public SheetServiceImpl(SheetRepository sheetRepository,
ApplicationEventPublisher eventPublisher,
SheetCommentService sheetCommentService,
OptionService optionService) {
OptionService optionService,
ThemeService themeService) {
super(sheetRepository, optionService);
this.sheetRepository = sheetRepository;
this.eventPublisher = eventPublisher;
this.sheetCommentService = sheetCommentService;
this.themeService = themeService;
}
@Override
@ -136,6 +144,39 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
return content.toString();
}
@Override
public List<InternalSheetDTO> listInternal() {
List<InternalSheetDTO> internalSheetDTOS = new ArrayList<>();
// links sheet
InternalSheetDTO linkSheet = new InternalSheetDTO();
linkSheet.setId(1);
linkSheet.setTitle("友情链接");
linkSheet.setUrl("/links");
linkSheet.setStatus(themeService.templateExists("links.ftl"));
// photos sheet
InternalSheetDTO photoSheet = new InternalSheetDTO();
photoSheet.setId(2);
photoSheet.setTitle("图库页面");
photoSheet.setUrl("/photos");
photoSheet.setStatus(themeService.templateExists("photos.ftl"));
// journals sheet
InternalSheetDTO journalSheet = new InternalSheetDTO();
journalSheet.setId(3);
journalSheet.setTitle("日志页面");
journalSheet.setUrl("/journals");
journalSheet.setStatus(themeService.templateExists("journals.ftl"));
internalSheetDTOS.add(linkSheet);
internalSheetDTOS.add(photoSheet);
internalSheetDTOS.add(journalSheet);
return internalSheetDTOS;
}
@Override
public Sheet removeById(Integer id) {
Sheet sheet = super.removeById(id);