From 7c9f8b01f3fe1b4c9a69a28d82673099a251d49a Mon Sep 17 00:00:00 2001 From: ruibaby Date: Sat, 25 May 2019 14:08:22 +0800 Subject: [PATCH] Support internal sheet list api. --- .../controller/admin/api/SheetController.java | 9 ++++ .../halo/app/model/dto/InternalSheetDTO.java | 21 +++++++++ .../run/halo/app/service/SheetService.java | 12 ++++++ .../app/service/impl/SheetServiceImpl.java | 43 ++++++++++++++++++- 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/main/java/run/halo/app/model/dto/InternalSheetDTO.java diff --git a/src/main/java/run/halo/app/controller/admin/api/SheetController.java b/src/main/java/run/halo/app/controller/admin/api/SheetController.java index 35ecf6834..36c2333f2 100644 --- a/src/main/java/run/halo/app/controller/admin/api/SheetController.java +++ b/src/main/java/run/halo/app/controller/admin/api/SheetController.java @@ -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 internalSheets() { + return sheetService.listInternal(); + } + @PostMapping @ApiOperation("Creates a sheet") public BasePostDetailDTO createBy(@RequestBody @Valid SheetParam sheetParam, diff --git a/src/main/java/run/halo/app/model/dto/InternalSheetDTO.java b/src/main/java/run/halo/app/model/dto/InternalSheetDTO.java new file mode 100644 index 000000000..377027e5d --- /dev/null +++ b/src/main/java/run/halo/app/model/dto/InternalSheetDTO.java @@ -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; +} diff --git a/src/main/java/run/halo/app/service/SheetService.java b/src/main/java/run/halo/app/service/SheetService.java index d5d8428a8..5e0b206d0 100644 --- a/src/main/java/run/halo/app/service/SheetService.java +++ b/src/main/java/run/halo/app/service/SheetService.java @@ -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 { @@ -72,6 +76,14 @@ public interface SheetService extends BasePostService { @NonNull String exportMarkdown(@NonNull Sheet sheet); + /** + * List internal sheets. + * + * @return list of internal sheets + */ + @NonNull + List listInternal(); + /** * Converts to list dto page. * diff --git a/src/main/java/run/halo/app/service/impl/SheetServiceImpl.java b/src/main/java/run/halo/app/service/impl/SheetServiceImpl.java index ad4f5be66..15b11fc41 100644 --- a/src/main/java/run/halo/app/service/impl/SheetServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/SheetServiceImpl.java @@ -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 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 implements Shee return content.toString(); } + @Override + public List listInternal() { + + List 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);