mirror of https://github.com/halo-dev/halo
Merge remote-tracking branch 'origin/v1' into v1
commit
6e56732cf4
|
@ -7,6 +7,7 @@ import org.springframework.data.web.PageableDefault;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import run.halo.app.model.dto.BaseCommentDTO;
|
import run.halo.app.model.dto.BaseCommentDTO;
|
||||||
import run.halo.app.model.entity.JournalComment;
|
import run.halo.app.model.entity.JournalComment;
|
||||||
|
import run.halo.app.model.enums.CommentStatus;
|
||||||
import run.halo.app.model.params.CommentQuery;
|
import run.halo.app.model.params.CommentQuery;
|
||||||
import run.halo.app.model.params.JournalCommentParam;
|
import run.halo.app.model.params.JournalCommentParam;
|
||||||
import run.halo.app.model.vo.JournalCommentWithJournalVO;
|
import run.halo.app.model.vo.JournalCommentWithJournalVO;
|
||||||
|
@ -53,4 +54,19 @@ public class JournalCommentController {
|
||||||
return journalCommentService.convertTo(journalComment);
|
return journalCommentService.convertTo(journalComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("{commentId:\\d+}/status/{status}")
|
||||||
|
@ApiOperation("Updates comment status")
|
||||||
|
public BaseCommentDTO updateStatusBy(@PathVariable("commentId") Long commentId,
|
||||||
|
@PathVariable("status") CommentStatus status) {
|
||||||
|
// Update comment status
|
||||||
|
JournalComment updatedJournalComment = journalCommentService.updateStatus(commentId, status);
|
||||||
|
return journalCommentService.convertTo(updatedJournalComment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("{commentId:\\d+}")
|
||||||
|
@ApiOperation("Deletes comment permanently and recursively")
|
||||||
|
public BaseCommentDTO deleteBy(@PathVariable("commentId") Long commentId) {
|
||||||
|
JournalComment deletedJournalComment = journalCommentService.removeById(commentId);
|
||||||
|
return journalCommentService.convertTo(deletedJournalComment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import run.halo.app.model.dto.BaseCommentDTO;
|
import run.halo.app.model.dto.BaseCommentDTO;
|
||||||
import run.halo.app.model.entity.PostComment;
|
import run.halo.app.model.entity.PostComment;
|
||||||
import run.halo.app.model.enums.CommentStatus;
|
import run.halo.app.model.enums.CommentStatus;
|
||||||
import run.halo.app.model.params.CommentParam;
|
import run.halo.app.model.params.PostCommentParam;
|
||||||
import run.halo.app.model.params.CommentQuery;
|
import run.halo.app.model.params.CommentQuery;
|
||||||
import run.halo.app.model.vo.PostCommentWithPostVO;
|
import run.halo.app.model.vo.PostCommentWithPostVO;
|
||||||
import run.halo.app.service.PostCommentService;
|
import run.halo.app.service.PostCommentService;
|
||||||
|
@ -50,8 +50,8 @@ public class PostCommentController {
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation("Creates a comment (new or reply)")
|
@ApiOperation("Creates a comment (new or reply)")
|
||||||
public BaseCommentDTO createBy(@RequestBody CommentParam commentParam) {
|
public BaseCommentDTO createBy(@RequestBody PostCommentParam postCommentParam) {
|
||||||
PostComment createdPostComment = postCommentService.createBy(commentParam);
|
PostComment createdPostComment = postCommentService.createBy(postCommentParam);
|
||||||
return postCommentService.convertTo(createdPostComment);
|
return postCommentService.convertTo(createdPostComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,6 @@ public class PostCommentController {
|
||||||
@PathVariable("status") CommentStatus status) {
|
@PathVariable("status") CommentStatus status) {
|
||||||
// Update comment status
|
// Update comment status
|
||||||
PostComment updatedPostComment = postCommentService.updateStatus(commentId, status);
|
PostComment updatedPostComment = postCommentService.updateStatus(commentId, status);
|
||||||
|
|
||||||
return postCommentService.convertTo(updatedPostComment);
|
return postCommentService.convertTo(updatedPostComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +68,6 @@ public class PostCommentController {
|
||||||
@ApiOperation("Deletes comment permanently and recursively")
|
@ApiOperation("Deletes comment permanently and recursively")
|
||||||
public BaseCommentDTO deleteBy(@PathVariable("commentId") Long commentId) {
|
public BaseCommentDTO deleteBy(@PathVariable("commentId") Long commentId) {
|
||||||
PostComment deletedPostComment = postCommentService.removeById(commentId);
|
PostComment deletedPostComment = postCommentService.removeById(commentId);
|
||||||
|
|
||||||
return postCommentService.convertTo(deletedPostComment);
|
return postCommentService.convertTo(deletedPostComment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
package run.halo.app.controller.admin.api;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
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.BaseCommentDTO;
|
||||||
|
import run.halo.app.model.entity.SheetComment;
|
||||||
|
import run.halo.app.model.enums.CommentStatus;
|
||||||
|
import run.halo.app.model.params.CommentQuery;
|
||||||
|
import run.halo.app.model.params.SheetCommentParam;
|
||||||
|
import run.halo.app.model.vo.SheetCommentWithSheetVO;
|
||||||
|
import run.halo.app.service.SheetCommentService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sheet comment controller.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
* @date 19-4-25
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/admin/sheets/comments")
|
||||||
|
public class SheetCommentController {
|
||||||
|
|
||||||
|
private final SheetCommentService sheetCommentService;
|
||||||
|
|
||||||
|
public SheetCommentController(SheetCommentService sheetCommentService) {
|
||||||
|
this.sheetCommentService = sheetCommentService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public Page<SheetCommentWithSheetVO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable,
|
||||||
|
CommentQuery commentQuery) {
|
||||||
|
Page<SheetComment> sheetCommentPage = sheetCommentService.pageBy(commentQuery, pageable);
|
||||||
|
return sheetCommentService.convertToWithPostVo(sheetCommentPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("latest")
|
||||||
|
public List<SheetCommentWithSheetVO> listLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||||
|
Page<SheetComment> sheetCommentPage = sheetCommentService.pageLatest(top);
|
||||||
|
return sheetCommentService.convertToWithPostVo(sheetCommentPage.getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
@ApiOperation("Creates a comment (new or reply)")
|
||||||
|
public BaseCommentDTO createBy(@RequestBody SheetCommentParam commentParam) {
|
||||||
|
SheetComment createdComment = sheetCommentService.createBy(commentParam);
|
||||||
|
return sheetCommentService.convertTo(createdComment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("{commentId:\\d+}/status/{status}")
|
||||||
|
@ApiOperation("Updates comment status")
|
||||||
|
public BaseCommentDTO updateStatusBy(@PathVariable("commentId") Long commentId,
|
||||||
|
@PathVariable("status") CommentStatus status) {
|
||||||
|
// Update comment status
|
||||||
|
SheetComment updatedSheetComment = sheetCommentService.updateStatus(commentId, status);
|
||||||
|
return sheetCommentService.convertTo(updatedSheetComment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("{commentId:\\d+}")
|
||||||
|
@ApiOperation("Deletes comment permanently and recursively")
|
||||||
|
public BaseCommentDTO deleteBy(@PathVariable("commentId") Long commentId) {
|
||||||
|
SheetComment deletedSheetComment = sheetCommentService.removeById(commentId);
|
||||||
|
return sheetCommentService.convertTo(deletedSheetComment);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import run.halo.app.model.dto.BaseCommentDTO;
|
import run.halo.app.model.dto.BaseCommentDTO;
|
||||||
import run.halo.app.model.params.CommentParam;
|
import run.halo.app.model.params.PostCommentParam;
|
||||||
import run.halo.app.service.PostCommentService;
|
import run.halo.app.service.PostCommentService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,7 +27,7 @@ public class CommentController {
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation("Comments a post")
|
@ApiOperation("Comments a post")
|
||||||
public BaseCommentDTO comment(@RequestBody CommentParam commentParam) {
|
public BaseCommentDTO comment(@RequestBody PostCommentParam postCommentParam) {
|
||||||
return postCommentService.convertTo(postCommentService.createBy(commentParam));
|
return postCommentService.convertTo(postCommentService.createBy(postCommentParam));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,6 @@ import run.halo.app.model.entity.PostComment;
|
||||||
@Data
|
@Data
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class CommentParam extends BaseCommentParam<PostComment> {
|
public class PostCommentParam extends BaseCommentParam<PostComment> {
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package run.halo.app.model.params;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import run.halo.app.model.entity.SheetComment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sheet comment param.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
* @date 19-4-25
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class SheetCommentParam extends BaseCommentParam<SheetComment> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package run.halo.app.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import run.halo.app.model.dto.BaseCommentDTO;
|
||||||
|
import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PostComment list with post vo.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class SheetCommentWithSheetVO extends BaseCommentDTO {
|
||||||
|
|
||||||
|
private BasePostMinimalDTO sheet;
|
||||||
|
}
|
|
@ -1,8 +1,14 @@
|
||||||
package run.halo.app.service;
|
package run.halo.app.service;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import run.halo.app.model.entity.SheetComment;
|
import run.halo.app.model.entity.SheetComment;
|
||||||
|
import run.halo.app.model.vo.SheetCommentWithSheetVO;
|
||||||
import run.halo.app.service.base.BaseCommentService;
|
import run.halo.app.service.base.BaseCommentService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sheet comment service interface.
|
* Sheet comment service interface.
|
||||||
*
|
*
|
||||||
|
@ -11,4 +17,9 @@ import run.halo.app.service.base.BaseCommentService;
|
||||||
*/
|
*/
|
||||||
public interface SheetCommentService extends BaseCommentService<SheetComment> {
|
public interface SheetCommentService extends BaseCommentService<SheetComment> {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
List<SheetCommentWithSheetVO> convertToWithPostVo(@Nullable List<SheetComment> sheetComments);
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
Page<SheetCommentWithSheetVO> convertToWithPostVo(@NonNull Page<SheetComment> sheetCommentPage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,27 @@
|
||||||
package run.halo.app.service.impl;
|
package run.halo.app.service.impl;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import run.halo.app.exception.NotFoundException;
|
import run.halo.app.exception.NotFoundException;
|
||||||
|
import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
||||||
|
import run.halo.app.model.entity.Sheet;
|
||||||
import run.halo.app.model.entity.SheetComment;
|
import run.halo.app.model.entity.SheetComment;
|
||||||
|
import run.halo.app.model.vo.SheetCommentWithSheetVO;
|
||||||
import run.halo.app.repository.SheetCommentRepository;
|
import run.halo.app.repository.SheetCommentRepository;
|
||||||
import run.halo.app.repository.SheetRepository;
|
import run.halo.app.repository.SheetRepository;
|
||||||
import run.halo.app.service.OptionService;
|
import run.halo.app.service.OptionService;
|
||||||
import run.halo.app.service.SheetCommentService;
|
import run.halo.app.service.SheetCommentService;
|
||||||
|
import run.halo.app.utils.ServiceUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sheet comment service implementation.
|
* Sheet comment service implementation.
|
||||||
|
@ -37,4 +51,32 @@ public class SheetCommentServiceImpl extends BaseCommentServiceImpl<SheetComment
|
||||||
throw new NotFoundException("The sheet with id " + sheetId + " was not found");
|
throw new NotFoundException("The sheet with id " + sheetId + " was not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SheetCommentWithSheetVO> convertToWithPostVo(List<SheetComment> sheetComments) {
|
||||||
|
if (CollectionUtils.isEmpty(sheetComments)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Integer> sheetIds = ServiceUtils.fetchProperty(sheetComments, SheetComment::getPostId);
|
||||||
|
|
||||||
|
Map<Integer, Sheet> sheetMap = ServiceUtils.convertToMap(sheetRepository.findAllById(sheetIds), Sheet::getId);
|
||||||
|
|
||||||
|
return sheetComments.stream()
|
||||||
|
.filter(comment -> sheetMap.containsKey(comment.getPostId()))
|
||||||
|
.map(comment -> {
|
||||||
|
SheetCommentWithSheetVO sheetCmtWithPostVO = new SheetCommentWithSheetVO().convertFrom(comment);
|
||||||
|
sheetCmtWithPostVO.setSheet(new BasePostMinimalDTO().convertFrom(sheetMap.get(comment.getPostId())));
|
||||||
|
return sheetCmtWithPostVO;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<SheetCommentWithSheetVO> convertToWithPostVo(Page<SheetComment> sheetCommentPage) {
|
||||||
|
Assert.notNull(sheetCommentPage, "Sheet comment page must not be null");
|
||||||
|
|
||||||
|
return new PageImpl<>(convertToWithPostVo(sheetCommentPage.getContent()), sheetCommentPage.getPageable(), sheetCommentPage.getTotalElements());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue