Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
d297b635
Commit
d297b635
authored
Feb 02, 2020
by
胡学良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除评论
parent
f6eeb5d6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
3 deletions
+91
-3
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionReplyCommentApi.java
+26
-0
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionReplyCommentErrorCode.java
+12
-1
src/main/java/cn/meteor/beyondclouds/modules/question/service/IQuestionReplyCommentService.java
+8
-0
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionReplyCommentServiceImpl.java
+45
-2
No files found.
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionReplyCommentApi.java
View file @
d297b635
...
...
@@ -30,6 +30,14 @@ public class QuestionReplyCommentApi {
this
.
questionReplyCommentService
=
questionReplyCommentService
;
}
/**
* 发表评论
* @param questionReplyCommentForm 评论表单
* @param bindingResult 校验信息
* @param replyId 回复ID
* @param subject 访问者信息
* @return default
*/
@ApiOperation
(
"发表评论"
)
@PostMapping
(
"/question/reply/{replyId}/comment"
)
public
Response
publishReplyComment
(
@RequestBody
@Valid
QuestionReplyCommentForm
questionReplyCommentForm
,
BindingResult
bindingResult
,
...
...
@@ -47,4 +55,22 @@ public class QuestionReplyCommentApi {
return
Response
.
error
(
e
);
}
}
/**
* 删除评论
* @param commentId 评论ID
* @param subject 访问者信息
* @return default
*/
@ApiOperation
(
"删除评论"
)
@DeleteMapping
(
"/question/reply/comment/{commentId}"
)
public
Response
deleteReplyComment
(
@PathVariable
(
"commentId"
)
String
commentId
,
@CurrentSubject
Subject
subject
)
{
try
{
questionReplyCommentService
.
deleteReplyComment
((
String
)
subject
.
getId
(),
commentId
);
return
Response
.
success
();
}
catch
(
QuestionReplyCommentServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
}
}
}
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionReplyCommentErrorCode.java
View file @
d297b635
...
...
@@ -7,7 +7,18 @@ import cn.meteor.beyondclouds.core.IErrorCode;
* @since 2020/2/2
*/
public
enum
QuestionReplyCommentErrorCode
implements
IErrorCode
{
COMMENT_NOT_FOUND
(
5001
,
"父评论不存在"
);
/**
* 评论不存在
*/
COMMENT_NOT_FOUND
(
5002
,
"该评论不存在"
),
/**
* 父评论不存在
*/
PARENT_COMMENT_NOT_FOUND
(
5001
,
"父评论不存在"
),
/**
* 无权删除评论
*/
NO_DELETE_PRIVILEGES
(
5003
,
"无权删除该评论 "
);
private
long
code
;
private
String
msg
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/question/service/IQuestionReplyCommentService.java
View file @
d297b635
...
...
@@ -23,4 +23,12 @@ public interface IQuestionReplyCommentService extends IService<QuestionReplyComm
* @throws QuestionReplyCommentServiceException 问题回复评论业务异常
*/
void
publishReplyComment
(
String
userId
,
String
replyId
,
String
parentId
,
String
comment
)
throws
QuestionReplyCommentServiceException
;
/**
* 删除评论
* @param userId 用户ID
* @param commentId 评论ID
* @throws QuestionReplyCommentServiceException 问题回复评论业务异常
*/
void
deleteReplyComment
(
String
userId
,
String
commentId
)
throws
QuestionReplyCommentServiceException
;
}
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionReplyCommentServiceImpl.java
View file @
d297b635
package
cn
.
meteor
.
beyondclouds
.
modules
.
question
.
service
.
impl
;
import
cn.meteor.beyondclouds.modules.question.entity.Question
;
import
cn.meteor.beyondclouds.modules.question.entity.QuestionReply
;
import
cn.meteor.beyondclouds.modules.question.entity.QuestionReplyComment
;
import
cn.meteor.beyondclouds.modules.question.enums.QuestionReplyCommentErrorCode
;
...
...
@@ -8,6 +9,7 @@ import cn.meteor.beyondclouds.modules.question.exception.QuestionReplyCommentSer
import
cn.meteor.beyondclouds.modules.question.mapper.QuestionReplyCommentMapper
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionReplyCommentService
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionReplyService
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -26,6 +28,8 @@ import org.springframework.util.StringUtils;
@Service
public
class
QuestionReplyCommentServiceImpl
extends
ServiceImpl
<
QuestionReplyCommentMapper
,
QuestionReplyComment
>
implements
IQuestionReplyCommentService
{
private
IQuestionService
questionService
;
private
IQuestionReplyService
questionReplyService
;
@Autowired
...
...
@@ -33,9 +37,15 @@ public class QuestionReplyCommentServiceImpl extends ServiceImpl<QuestionReplyCo
this
.
questionReplyService
=
questionReplyService
;
}
@Autowired
public
void
setQuestionService
(
IQuestionService
questionService
)
{
this
.
questionService
=
questionService
;
}
@Override
public
void
publishReplyComment
(
String
userId
,
String
replyId
,
String
parentId
,
String
comment
)
throws
QuestionReplyCommentServiceException
{
Assert
.
hasText
(
replyId
,
"replyId must not be empty"
);
Assert
.
notNull
(
replyId
,
"replyId must not be null"
);
Assert
.
hasText
(
comment
,
"comment must not be empty"
);
//1.判断是否存在该回复
QuestionReply
questionReply
=
questionReplyService
.
getById
(
replyId
);
...
...
@@ -54,7 +64,7 @@ public class QuestionReplyCommentServiceImpl extends ServiceImpl<QuestionReplyCo
parentQuestionReplyComment
=
getOne
(
questionReplyCommentQueryWrapper
);
//若父评论为空,则抛出父评论不存在异常
if
(
null
==
parentQuestionReplyComment
)
{
throw
new
QuestionReplyCommentServiceException
(
QuestionReplyCommentErrorCode
.
COMMENT_NOT_FOUND
);
throw
new
QuestionReplyCommentServiceException
(
QuestionReplyCommentErrorCode
.
PARENT_
COMMENT_NOT_FOUND
);
}
}
...
...
@@ -78,4 +88,37 @@ public class QuestionReplyCommentServiceImpl extends ServiceImpl<QuestionReplyCo
}
updateById
(
questionReplyComment
);
}
@Override
public
void
deleteReplyComment
(
String
userId
,
String
commentId
)
throws
QuestionReplyCommentServiceException
{
Assert
.
notNull
(
commentId
,
"commentId must not be null"
);
Assert
.
notNull
(
userId
,
"userId must not be null"
);
//1.判断是否存在该评论
QuestionReplyComment
questionReplyComment
=
getById
(
commentId
);
if
(
null
==
questionReplyComment
)
{
throw
new
QuestionReplyCommentServiceException
(
QuestionReplyCommentErrorCode
.
COMMENT_NOT_FOUND
);
}
//2.判断用户是否有权限删除该评论
if
(!
questionReplyComment
.
getUserId
().
equals
(
userId
))
{
//用户未发表过该评论,判断用户是否为该回复或者该问题的发布者
//得到评论对应的回复对象
QuestionReply
questionReply
=
questionReplyService
.
getById
(
questionReplyComment
.
getReplyId
());
//得到回复对应的问题对象
Question
question
=
questionService
.
getById
(
questionReply
.
getQuestionId
());
//判断用户是否为该回复或该问题的发布者
if
(!
question
.
getUserId
().
equals
(
userId
)
&&
!
questionReply
.
getUserId
().
equals
(
userId
))
{
throw
new
QuestionReplyCommentServiceException
(
QuestionReplyCommentErrorCode
.
NO_DELETE_PRIVILEGES
);
}
}
//3.删除评论及其子评论
QueryWrapper
<
QuestionReplyComment
>
questionReplyCommentQueryWrapper
=
new
QueryWrapper
<>();
questionReplyCommentQueryWrapper
.
like
(
"thread"
,
questionReplyComment
.
getThread
());
remove
(
questionReplyCommentQueryWrapper
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment