mirror of https://github.com/halo-dev/halo
Create api for update comment.
parent
e3b17ddcb4
commit
912427d159
|
@ -1,5 +1,5 @@
|
|||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.3.RELEASE'
|
||||
id 'org.springframework.boot' version '2.1.7.RELEASE'
|
||||
id "io.freefair.lombok" version "3.6.6"
|
||||
// id 'war'
|
||||
id 'java'
|
||||
|
|
|
@ -13,6 +13,7 @@ import run.halo.app.model.params.PostCommentParam;
|
|||
import run.halo.app.model.vo.PostCommentWithPostVO;
|
||||
import run.halo.app.service.PostCommentService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
@ -21,6 +22,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
|
|||
* Post comment controller.
|
||||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @date 3/19/19
|
||||
*/
|
||||
@RestController
|
||||
|
@ -74,4 +76,21 @@ public class PostCommentController {
|
|||
PostComment deletedPostComment = postCommentService.removeById(commentId);
|
||||
return postCommentService.convertTo(deletedPostComment);
|
||||
}
|
||||
|
||||
@GetMapping("{commentId:\\d+}")
|
||||
@ApiOperation("Gets a post comment by comment id")
|
||||
public PostCommentWithPostVO getBy(@PathVariable("commentId") Long commentId) {
|
||||
PostComment comment = postCommentService.getById(commentId);
|
||||
return postCommentService.convertToWithPostVo(comment);
|
||||
}
|
||||
|
||||
@PutMapping("{commentId:\\d+}")
|
||||
public BaseCommentDTO updateBy(@Valid @RequestBody PostCommentParam commentParam,
|
||||
@PathVariable("commentId") Long commentId) {
|
||||
PostComment commentToUpdate = postCommentService.getById(commentId);
|
||||
|
||||
commentParam.update(commentToUpdate);
|
||||
|
||||
return postCommentService.convertTo(postCommentService.update(commentToUpdate));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import run.halo.app.model.params.SheetCommentParam;
|
|||
import run.halo.app.model.vo.SheetCommentWithSheetVO;
|
||||
import run.halo.app.service.SheetCommentService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
@ -21,6 +22,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
|
|||
* Sheet comment controller.
|
||||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @date 19-4-25
|
||||
*/
|
||||
@RestController
|
||||
|
@ -37,14 +39,14 @@ public class SheetCommentController {
|
|||
public Page<SheetCommentWithSheetVO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable,
|
||||
CommentQuery commentQuery) {
|
||||
Page<SheetComment> sheetCommentPage = sheetCommentService.pageBy(commentQuery, pageable);
|
||||
return sheetCommentService.convertToWithPostVo(sheetCommentPage);
|
||||
return sheetCommentService.convertToWithSheetVo(sheetCommentPage);
|
||||
}
|
||||
|
||||
@GetMapping("latest")
|
||||
public List<SheetCommentWithSheetVO> listLatest(@RequestParam(name = "top", defaultValue = "10") int top,
|
||||
@RequestParam(name = "status", required = false) CommentStatus status) {
|
||||
Page<SheetComment> sheetCommentPage = sheetCommentService.pageLatest(top, status);
|
||||
return sheetCommentService.convertToWithPostVo(sheetCommentPage.getContent());
|
||||
return sheetCommentService.convertToWithSheetVo(sheetCommentPage.getContent());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
|
@ -69,4 +71,21 @@ public class SheetCommentController {
|
|||
SheetComment deletedSheetComment = sheetCommentService.removeById(commentId);
|
||||
return sheetCommentService.convertTo(deletedSheetComment);
|
||||
}
|
||||
|
||||
@GetMapping("{commentId:\\d+}")
|
||||
@ApiOperation("Gets a post comment by comment id")
|
||||
public SheetCommentWithSheetVO getBy(@PathVariable("commentId") Long commentId) {
|
||||
SheetComment comment = sheetCommentService.getById(commentId);
|
||||
return sheetCommentService.convertToWithSheetVo(comment);
|
||||
}
|
||||
|
||||
@PutMapping("{commentId:\\d+}")
|
||||
public BaseCommentDTO updateBy(@Valid @RequestBody SheetCommentParam commentParam,
|
||||
@PathVariable("commentId") Long commentId) {
|
||||
SheetComment commentToUpdate = sheetCommentService.getById(commentId);
|
||||
|
||||
commentParam.update(commentToUpdate);
|
||||
|
||||
return sheetCommentService.convertTo(sheetCommentService.update(commentToUpdate));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.util.List;
|
|||
* Post comment service interface.
|
||||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @date 2019-03-14
|
||||
*/
|
||||
public interface PostCommentService extends BaseCommentService<PostComment> {
|
||||
|
@ -28,6 +29,15 @@ public interface PostCommentService extends BaseCommentService<PostComment> {
|
|||
@NonNull
|
||||
Page<PostCommentWithPostVO> convertToWithPostVo(@NonNull Page<PostComment> commentPage);
|
||||
|
||||
/**
|
||||
* Converts to with post vo
|
||||
*
|
||||
* @param comment comment
|
||||
* @return a comment with post vo
|
||||
*/
|
||||
@NonNull
|
||||
PostCommentWithPostVO convertToWithPostVo(@NonNull PostComment comment);
|
||||
|
||||
/**
|
||||
* Converts to with post vo
|
||||
*
|
||||
|
|
|
@ -13,13 +13,35 @@ import java.util.List;
|
|||
* Sheet comment service interface.
|
||||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @date 2019-04-24
|
||||
*/
|
||||
public interface SheetCommentService extends BaseCommentService<SheetComment> {
|
||||
|
||||
/**
|
||||
* Converts to with sheet vo
|
||||
*
|
||||
* @param comment comment
|
||||
* @return a comment with sheet vo
|
||||
*/
|
||||
@NonNull
|
||||
List<SheetCommentWithSheetVO> convertToWithPostVo(@Nullable List<SheetComment> sheetComments);
|
||||
SheetCommentWithSheetVO convertToWithSheetVo(@NonNull SheetComment comment);
|
||||
|
||||
/**
|
||||
* Converts to with sheet vo
|
||||
*
|
||||
* @param sheetComments sheet comments
|
||||
* @return a sheet comments with sheet vo
|
||||
*/
|
||||
@NonNull
|
||||
Page<SheetCommentWithSheetVO> convertToWithPostVo(@NonNull Page<SheetComment> sheetCommentPage);
|
||||
List<SheetCommentWithSheetVO> convertToWithSheetVo(@Nullable List<SheetComment> sheetComments);
|
||||
|
||||
/**
|
||||
* Converts to with sheet vo
|
||||
*
|
||||
* @param sheetCommentPage sheet comments
|
||||
* @return a page of sheet comments with sheet vo
|
||||
*/
|
||||
@NonNull
|
||||
Page<SheetCommentWithSheetVO> convertToWithSheetVo(@NonNull Page<SheetComment> sheetCommentPage);
|
||||
}
|
||||
|
|
|
@ -61,6 +61,14 @@ public class PostCommentServiceImpl extends BaseCommentServiceImpl<PostComment>
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PostCommentWithPostVO convertToWithPostVo(PostComment comment) {
|
||||
Assert.notNull(comment, "PostComment must not be null");
|
||||
PostCommentWithPostVO postCommentWithPostVO = new PostCommentWithPostVO().convertFrom(comment);
|
||||
postCommentWithPostVO.setPost(new BasePostMinimalDTO().convertFrom(postRepository.getOne(comment.getPostId())));
|
||||
return postCommentWithPostVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PostCommentWithPostVO> convertToWithPostVo(List<PostComment> postComments) {
|
||||
if (CollectionUtils.isEmpty(postComments)) {
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.stream.Collectors;
|
|||
* Sheet comment service implementation.
|
||||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @date 2019-04-24
|
||||
*/
|
||||
@Service
|
||||
|
@ -59,7 +60,15 @@ public class SheetCommentServiceImpl extends BaseCommentServiceImpl<SheetComment
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<SheetCommentWithSheetVO> convertToWithPostVo(List<SheetComment> sheetComments) {
|
||||
public SheetCommentWithSheetVO convertToWithSheetVo(SheetComment comment) {
|
||||
Assert.notNull(comment, "SheetComment must not be null");
|
||||
SheetCommentWithSheetVO sheetCommentWithSheetVO = new SheetCommentWithSheetVO().convertFrom(comment);
|
||||
sheetCommentWithSheetVO.setSheet(new BasePostMinimalDTO().convertFrom(sheetRepository.getOne(comment.getPostId())));
|
||||
return sheetCommentWithSheetVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SheetCommentWithSheetVO> convertToWithSheetVo(List<SheetComment> sheetComments) {
|
||||
if (CollectionUtils.isEmpty(sheetComments)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -79,10 +88,10 @@ public class SheetCommentServiceImpl extends BaseCommentServiceImpl<SheetComment
|
|||
}
|
||||
|
||||
@Override
|
||||
public Page<SheetCommentWithSheetVO> convertToWithPostVo(Page<SheetComment> sheetCommentPage) {
|
||||
public Page<SheetCommentWithSheetVO> convertToWithSheetVo(Page<SheetComment> sheetCommentPage) {
|
||||
Assert.notNull(sheetCommentPage, "Sheet comment page must not be null");
|
||||
|
||||
return new PageImpl<>(convertToWithPostVo(sheetCommentPage.getContent()), sheetCommentPage.getPageable(), sheetCommentPage.getTotalElements());
|
||||
return new PageImpl<>(convertToWithSheetVo(sheetCommentPage.getContent()), sheetCommentPage.getPageable(), sheetCommentPage.getTotalElements());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue