mirror of https://github.com/halo-dev/halo
Refactor sheet apis
parent
56ff28cbbf
commit
204bc8b4a4
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,15 +44,6 @@ public interface SheetService extends CrudService<Sheet, Integer> {
|
|||
@NonNull
|
||||
Page<Sheet> 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<Sheet, Integer> {
|
|||
@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<Sheet, Integer> {
|
|||
*/
|
||||
@NonNull
|
||||
Page<SheetListDTO> convertToListDto(@NonNull Page<Sheet> sheetPage);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -137,6 +137,7 @@ public class SheetServiceImpl extends AbstractCrudService<Sheet, Integer> implem
|
|||
// The sheet will be updated
|
||||
// Set edit time
|
||||
sheet.setEditTime(DateUtils.now());
|
||||
|
||||
// Update it
|
||||
return update(sheet);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue