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 53318261279436f7f88de3a97ef9667f0c30b184..4bd45c34bf247c2c99b7dc92f39e7367126cea48 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.post.SheetDetailDTO; import run.halo.app.model.dto.post.SheetListDTO; import run.halo.app.model.entity.Sheet; import run.halo.app.model.enums.PostStatus; @@ -33,8 +34,9 @@ public class SheetController { @GetMapping("{sheetId:\\d+}") @ApiOperation("Gets a sheet") - public Sheet getBy(@PathVariable("sheetId") Integer sheetId) { - return sheetService.getById(sheetId); + public SheetDetailDTO getBy(@PathVariable("sheetId") Integer sheetId) { + Sheet sheet = sheetService.getById(sheetId); + return sheetService.convertToDetailDto(sheet); } @GetMapping @@ -46,20 +48,22 @@ public class SheetController { @PostMapping @ApiOperation("Creates a sheet") - public Sheet createBy(@RequestBody @Valid SheetParam sheetParam) { - return sheetService.createBy(sheetParam.convertTo()); + public SheetDetailDTO createBy(@RequestBody @Valid SheetParam sheetParam) { + Sheet sheet = sheetService.createBy(sheetParam.convertTo()); + return sheetService.convertToDetailDto(sheet); } @PutMapping("{sheetId:\\d+}") @ApiOperation("Updates a sheet") - public Sheet updateBy( + public SheetDetailDTO updateBy( @PathVariable("sheetId") Integer sheetId, @RequestBody @Valid SheetParam sheetParam) { - return sheetService.updateBy(sheetParam.convertTo()); + Sheet sheet = sheetService.updateBy(sheetParam.convertTo()); + return sheetService.convertToDetailDto(sheet); } @PutMapping("{sheetId:\\d+}/{status}") - public Sheet updateStatusBy( + public void updateStatusBy( @PathVariable("sheetId") Integer sheetId, @PathVariable("status") PostStatus status) { Sheet sheet = sheetService.getById(sheetId); @@ -67,13 +71,14 @@ public class SheetController { // Set status sheet.setStatus(status); - // Update and return - return sheetService.update(sheet); + // Update + sheetService.update(sheet); } @DeleteMapping("{sheetId:\\d+}") @ApiOperation("Deletes a sheet") - public Sheet deleteBy(@PathVariable("sheetId") Integer sheetId) { - return sheetService.removeById(sheetId); + public SheetDetailDTO deleteBy(@PathVariable("sheetId") Integer sheetId) { + Sheet sheet = sheetService.removeById(sheetId); + return sheetService.convertToDetailDto(sheet); } } diff --git a/src/main/java/run/halo/app/service/SheetService.java b/src/main/java/run/halo/app/service/SheetService.java index bd4f510f3efe51a31ecbe36d881c132167b0c2fd..50c2301bbfde05b84fd5883fe754524db972a761 100644 --- a/src/main/java/run/halo/app/service/SheetService.java +++ b/src/main/java/run/halo/app/service/SheetService.java @@ -44,15 +44,6 @@ public interface SheetService extends CrudService { @NonNull Page pageBy(@NonNull Pageable pageable); - /** - * Converts to detail dto. - * - * @param sheet sheet must not be null - * @return sheet detail dto - */ - @NonNull - SheetDetailDTO convertToDetailDto(@NonNull Sheet sheet); - /** * Gets sheet by post status and url. * @@ -63,6 +54,17 @@ public interface SheetService extends CrudService { @NonNull Sheet getBy(@NonNull PostStatus status, @NonNull String url); + + /** + * Converts to detail dto. + * + * @param sheet sheet must not be null + * @return sheet detail dto + */ + @NonNull + SheetDetailDTO convertToDetailDto(@NonNull Sheet sheet); + + /** * Converts to list dto page. * @@ -71,4 +73,6 @@ public interface SheetService extends CrudService { */ @NonNull Page convertToListDto(@NonNull Page sheetPage); + + } 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 5cfae8ce35466e132fc7eafab155bf77ac42f4ef..c795ca6f7174c0241069ebb66f655a50b60a457d 100644 --- a/src/main/java/run/halo/app/service/impl/SheetServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/SheetServiceImpl.java @@ -137,6 +137,7 @@ public class SheetServiceImpl extends AbstractCrudService implem // The sheet will be updated // Set edit time sheet.setEditTime(DateUtils.now()); + // Update it return update(sheet); }