mirror of https://github.com/halo-dev/halo
Log sheet control.
parent
19f8b588fa
commit
5cf659501c
|
@ -48,8 +48,9 @@ public class SheetController {
|
|||
|
||||
@PostMapping
|
||||
@ApiOperation("Creates a sheet")
|
||||
public BasePostDetailDTO createBy(@RequestBody @Valid SheetParam sheetParam) {
|
||||
Sheet sheet = sheetService.createBy(sheetParam.convertTo());
|
||||
public BasePostDetailDTO createBy(@RequestBody @Valid SheetParam sheetParam,
|
||||
@RequestParam(value = "autoSave", required = false, defaultValue = "false") Boolean autoSave) {
|
||||
Sheet sheet = sheetService.createBy(sheetParam.convertTo(), autoSave);
|
||||
return sheetService.convertToDetail(sheet);
|
||||
}
|
||||
|
||||
|
@ -57,12 +58,13 @@ public class SheetController {
|
|||
@ApiOperation("Updates a sheet")
|
||||
public BasePostDetailDTO updateBy(
|
||||
@PathVariable("sheetId") Integer sheetId,
|
||||
@RequestBody @Valid SheetParam sheetParam) {
|
||||
@RequestBody @Valid SheetParam sheetParam,
|
||||
@RequestParam(value = "autoSave", required = false, defaultValue = "false") Boolean autoSave) {
|
||||
Sheet sheetToUpdate = sheetService.getById(sheetId);
|
||||
|
||||
sheetParam.update(sheetToUpdate);
|
||||
|
||||
Sheet sheet = sheetService.updateBy(sheetToUpdate);
|
||||
Sheet sheet = sheetService.updateBy(sheetToUpdate, autoSave);
|
||||
|
||||
return sheetService.convertToDetail(sheet);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,10 @@ public enum LogType implements ValueEnum<Integer> {
|
|||
LOGGED_OUT(30),
|
||||
LOGIN_FAILED(35),
|
||||
PASSWORD_UPDATED(40),
|
||||
PROFILE_UPDATED(45);
|
||||
PROFILE_UPDATED(45),
|
||||
SHEET_PUBLISHED(50),
|
||||
SHEET_EDITED(55),
|
||||
SHEET_DELETED(60);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
|
|
|
@ -18,21 +18,30 @@ public interface SheetService extends BasePostService<Sheet> {
|
|||
/**
|
||||
* Creates a sheet.
|
||||
*
|
||||
* @param sheet sheet must not be null
|
||||
* @param sheet sheet must not be null
|
||||
* @param autoSave autoSave
|
||||
* @return created sheet
|
||||
*/
|
||||
@NonNull
|
||||
Sheet createBy(@NonNull Sheet sheet);
|
||||
Sheet createBy(@NonNull Sheet sheet, boolean autoSave);
|
||||
|
||||
/**
|
||||
* Updates a sheet.
|
||||
*
|
||||
* @param sheet sheet must not be null
|
||||
* @param sheet sheet must not be null
|
||||
* @param autoSave autoSave
|
||||
* @return updated sheet
|
||||
*/
|
||||
@NonNull
|
||||
Sheet updateBy(@NonNull Sheet sheet);
|
||||
Sheet updateBy(@NonNull Sheet sheet, boolean autoSave);
|
||||
|
||||
/**
|
||||
* Gets by url
|
||||
*
|
||||
* @param status post status must not be null
|
||||
* @param url post url must not be blank
|
||||
* @return sheet
|
||||
*/
|
||||
@Override
|
||||
Sheet getBy(PostStatus status, String url);
|
||||
|
||||
|
|
|
@ -5,8 +5,10 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.Pageable;
|
||||
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.entity.Sheet;
|
||||
import run.halo.app.model.enums.LogType;
|
||||
import run.halo.app.model.enums.PostStatus;
|
||||
import run.halo.app.model.vo.SheetListVO;
|
||||
import run.halo.app.repository.SheetRepository;
|
||||
|
@ -45,13 +47,25 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
|||
}
|
||||
|
||||
@Override
|
||||
public Sheet createBy(Sheet sheet) {
|
||||
return createOrUpdateBy(sheet);
|
||||
public Sheet createBy(Sheet sheet, boolean autoSave) {
|
||||
Sheet createdSheet = createOrUpdateBy(sheet);
|
||||
if (!autoSave) {
|
||||
// Log the creation
|
||||
LogEvent logEvent = new LogEvent(this, createdSheet.getId().toString(), LogType.SHEET_PUBLISHED, createdSheet.getTitle());
|
||||
eventPublisher.publishEvent(logEvent);
|
||||
}
|
||||
return createdSheet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sheet updateBy(Sheet sheet) {
|
||||
return createOrUpdateBy(sheet);
|
||||
public Sheet updateBy(Sheet sheet, boolean autoSave) {
|
||||
Sheet updatedSheet = createOrUpdateBy(sheet);
|
||||
if (!autoSave) {
|
||||
// Log the creation
|
||||
LogEvent logEvent = new LogEvent(this, updatedSheet.getId().toString(), LogType.SHEET_EDITED, updatedSheet.getTitle());
|
||||
eventPublisher.publishEvent(logEvent);
|
||||
}
|
||||
return updatedSheet;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,6 +94,15 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
|||
return sheet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sheet removeById(Integer id) {
|
||||
Sheet sheet = super.removeById(id);
|
||||
// Log it
|
||||
eventPublisher.publishEvent(new LogEvent(this, id.toString(), LogType.SHEET_DELETED, sheet.getTitle()));
|
||||
|
||||
return sheet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SheetListVO> convertToListVo(Page<Sheet> sheetPage) {
|
||||
Assert.notNull(sheetPage, "Sheet page must not be null");
|
||||
|
|
Loading…
Reference in New Issue