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
7300d045
Commit
7300d045
authored
Feb 20, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
博客点赞完成
parent
f79e7403
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
156 additions
and
97 deletions
+156
-97
src/main/java/cn/meteor/beyondclouds/modules/blog/api/BlogPraiseApi.java
+35
-40
src/main/java/cn/meteor/beyondclouds/modules/blog/enums/BlogPraiseErrorCode.java
+1
-1
src/main/java/cn/meteor/beyondclouds/modules/blog/enums/BlogPraiseType.java
+26
-0
src/main/java/cn/meteor/beyondclouds/modules/blog/service/IBlogPraiseService.java
+19
-6
src/main/java/cn/meteor/beyondclouds/modules/blog/service/impl/BlogPraiseServiceImpl.java
+75
-50
No files found.
src/main/java/cn/meteor/beyondclouds/modules/blog/api/BlogPraiseApi.java
View file @
7300d045
package
cn
.
meteor
.
beyondclouds
.
modules
.
blog
.
api
;
package
cn
.
meteor
.
beyondclouds
.
modules
.
blog
.
api
;
import
cn.meteor.beyondclouds.common.dto.PageDTO
;
import
cn.meteor.beyondclouds.common.form.PageForm
;
import
cn.meteor.beyondclouds.core.annotation.Anonymous
;
import
cn.meteor.beyondclouds.core.annotation.CurrentSubject
;
import
cn.meteor.beyondclouds.core.annotation.PreventDuplicate
;
import
cn.meteor.beyondclouds.core.annotation.ReplaceWithRemarks
;
import
cn.meteor.beyondclouds.core.api.Response
;
import
cn.meteor.beyondclouds.core.api.Response
;
import
cn.meteor.beyondclouds.core.authentication.Subject
;
import
cn.meteor.beyondclouds.core.authentication.Subject
;
import
cn.meteor.beyondclouds.core.exception.ServiceException
;
import
cn.meteor.beyondclouds.core.exception.ServiceException
;
import
cn.meteor.beyondclouds.core.flow.AccessInfo
;
import
cn.meteor.beyondclouds.core.flow.CollectAccessInfo
;
import
cn.meteor.beyondclouds.core.flow.ParamType
;
import
cn.meteor.beyondclouds.core.validation.groups.InsertGroup
;
import
cn.meteor.beyondclouds.core.validation.groups.UpdateGroup
;
import
cn.meteor.beyondclouds.modules.blog.dto.BlogDetailDTO
;
import
cn.meteor.beyondclouds.modules.blog.entity.Blog
;
import
cn.meteor.beyondclouds.modules.blog.exception.BlogCategoryServiceException
;
import
cn.meteor.beyondclouds.modules.blog.exception.BlogCommentServiceException
;
import
cn.meteor.beyondclouds.modules.blog.exception.BlogPraiseServiceException
;
import
cn.meteor.beyondclouds.modules.blog.exception.BlogPraiseServiceException
;
import
cn.meteor.beyondclouds.modules.blog.exception.BlogServiceException
;
import
cn.meteor.beyondclouds.modules.blog.form.BlogForm
;
import
cn.meteor.beyondclouds.modules.blog.service.IBlogPraiseService
;
import
cn.meteor.beyondclouds.modules.blog.service.IBlogPraiseService
;
import
cn.meteor.beyondclouds.modules.blog.service.IBlogService
;
import
cn.meteor.beyondclouds.util.AccessInfoUtils
;
import
cn.meteor.beyondclouds.util.SubjectUtils
;
import
cn.meteor.beyondclouds.util.SubjectUtils
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.validation.Valid
;
/**
/**
* @author gaoTong
* @author gaoTong
* @date 2020/1/31 9:27
* @date 2020/1/31 9:27
...
@@ -54,33 +28,54 @@ public class BlogPraiseApi {
...
@@ -54,33 +28,54 @@ public class BlogPraiseApi {
this
.
blogPraiseService
=
blogPraiseService
;
this
.
blogPraiseService
=
blogPraiseService
;
}
}
@ApiOperation
(
"点赞"
)
@ApiOperation
(
"博客点赞"
)
@PostMapping
(
"/blog/{targetId}/praise"
)
@PostMapping
(
"/blog/{blogId}/praise"
)
public
Response
praise
(
@PathVariable
(
"targetId"
)
String
targetId
,
public
Response
bogPraise
(
@PathVariable
(
"blogId"
)
String
blogId
)
{
@RequestParam
(
"targetType"
)
Integer
targetType
)
{
Subject
subject
=
SubjectUtils
.
getSubject
();
String
currentUserId
=
(
String
)
subject
.
getId
();
try
{
blogPraiseService
.
praiseBlog
(
currentUserId
,
blogId
);
return
Response
.
success
();
}
catch
(
BlogPraiseServiceException
e
)
{
return
Response
.
error
(
e
);
}
}
@ApiOperation
(
"取消博客点赞"
)
@DeleteMapping
(
"/blog/{blogId}/praise"
)
public
Response
deleteBlogPraise
(
@PathVariable
(
"blogId"
)
String
blogId
)
{
Subject
subject
=
SubjectUtils
.
getSubject
();
Subject
subject
=
SubjectUtils
.
getSubject
();
String
currentUserId
=
(
String
)
subject
.
getId
();
String
currentUserId
=
(
String
)
subject
.
getId
();
try
{
try
{
blogPraiseService
.
praise
(
currentUserId
,
targetId
,
targetType
);
blogPraiseService
.
deleteBlogPraise
(
currentUserId
,
blogId
);
return
Response
.
success
();
return
Response
.
success
();
}
catch
(
ServiceException
e
)
{
}
catch
(
BlogPraiseServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
return
Response
.
error
(
e
);
}
}
}
}
@ApiOperation
(
"
取消
点赞"
)
@ApiOperation
(
"
博客评论
点赞"
)
@
DeleteMapping
(
"/blog/{targe
tId}/praise"
)
@
PostMapping
(
"/blog/comment{commen
tId}/praise"
)
public
Response
deletePraise
(
@PathVariable
(
"targetId"
)
String
targe
tId
)
{
public
Response
blogCommentPraise
(
@PathVariable
(
"commentId"
)
String
commen
tId
)
{
Subject
subject
=
SubjectUtils
.
getSubject
();
Subject
subject
=
SubjectUtils
.
getSubject
();
String
currentUserId
=
(
String
)
subject
.
getId
();
String
currentUserId
=
(
String
)
subject
.
getId
();
try
{
blogPraiseService
.
praiseBlogComment
(
currentUserId
,
commentId
);
return
Response
.
success
();
}
catch
(
BlogPraiseServiceException
e
)
{
return
Response
.
error
(
e
);
}
}
// TODO 实现取消点赞功能,包括博客,评论的取消点赞
@ApiOperation
(
"取消博客评论点赞"
)
@DeleteMapping
(
"/blog/comment{commentId}/praise"
)
public
Response
deleteBlogCommentPraise
(
@PathVariable
(
"commentId"
)
String
commentId
)
{
Subject
subject
=
SubjectUtils
.
getSubject
();
String
currentUserId
=
(
String
)
subject
.
getId
();
try
{
try
{
blogPraiseService
.
delete
Praise
(
currentUserId
,
targe
tId
);
blogPraiseService
.
delete
BlogCommentPraise
(
currentUserId
,
commen
tId
);
return
Response
.
success
();
return
Response
.
success
();
}
catch
(
ServiceException
e
)
{
}
catch
(
BlogPraiseServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
return
Response
.
error
(
e
);
}
}
}
}
...
...
src/main/java/cn/meteor/beyondclouds/modules/blog/enums/BlogPraiseErrorCode.java
View file @
7300d045
...
@@ -8,7 +8,7 @@ import cn.meteor.beyondclouds.core.IErrorCode;
...
@@ -8,7 +8,7 @@ import cn.meteor.beyondclouds.core.IErrorCode;
*/
*/
public
enum
BlogPraiseErrorCode
implements
IErrorCode
{
public
enum
BlogPraiseErrorCode
implements
IErrorCode
{
BLOG_PRAISE_EXIST
(
8008
,
"您已经点过赞了"
),
BLOG_PRAISE_EXIST
(
8008
,
"您已经点过赞了"
),
NO_
DELETE_PRIVILEGES
(
8009
,
"没有权限取消
赞"
)
NO_
PRAISE_FOUND
(
8009
,
"您没有点过
赞"
)
;
;
private
long
code
;
private
long
code
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/blog/enums/BlogPraiseType.java
0 → 100644
View file @
7300d045
package
cn
.
meteor
.
beyondclouds
.
modules
.
blog
.
enums
;
import
lombok.Getter
;
/**
* @author meteor
*/
@Getter
public
enum
BlogPraiseType
{
/**
* 博客点赞
*/
BLOG_PRAISE
(
1
),
/**
* 博客评论点赞
*/
BLOG_COMMENT_PRAISE
(
2
),
;
private
Integer
praiseType
;
BlogPraiseType
(
Integer
praiseType
)
{
this
.
praiseType
=
praiseType
;
}
}
src/main/java/cn/meteor/beyondclouds/modules/blog/service/IBlogPraiseService.java
View file @
7300d045
...
@@ -17,17 +17,30 @@ import com.baomidou.mybatisplus.extension.service.IService;
...
@@ -17,17 +17,30 @@ import com.baomidou.mybatisplus.extension.service.IService;
public
interface
IBlogPraiseService
extends
IService
<
BlogPraise
>
{
public
interface
IBlogPraiseService
extends
IService
<
BlogPraise
>
{
/**
/**
* 点赞
*
博客
点赞
* @param userId
* @param userId
* @param targetId
* @param targetId
* @param targetType
*/
*/
void
praise
(
String
userId
,
String
targetId
,
Integer
targetType
)
throws
BlogServiceException
,
BlogPraiseServiceException
,
BlogComment
ServiceException
;
void
praise
Blog
(
String
userId
,
String
targetId
)
throws
BlogPraise
ServiceException
;
/**
/**
* 取消点赞
* 取消
博客
点赞
* @param userId
* @param userId
* @param targetId
* @param blogId
*/
void
deleteBlogPraise
(
String
userId
,
String
blogId
)
throws
BlogPraiseServiceException
;
/**
* 博客评论点赞
* @param currentUserId
* @param commentId
*/
void
praiseBlogComment
(
String
currentUserId
,
String
commentId
)
throws
BlogPraiseServiceException
;
/**
* 删除博客评论点赞
* @param currentUserId
* @param commentId
*/
*/
void
delete
Praise
(
String
userId
,
String
targe
tId
)
throws
BlogPraiseServiceException
;
void
delete
BlogCommentPraise
(
String
currentUserId
,
String
commen
tId
)
throws
BlogPraiseServiceException
;
}
}
src/main/java/cn/meteor/beyondclouds/modules/blog/service/impl/BlogPraiseServiceImpl.java
View file @
7300d045
...
@@ -6,6 +6,7 @@ import cn.meteor.beyondclouds.modules.blog.entity.BlogPraise;
...
@@ -6,6 +6,7 @@ import cn.meteor.beyondclouds.modules.blog.entity.BlogPraise;
import
cn.meteor.beyondclouds.modules.blog.enums.BlogCommentErrorCode
;
import
cn.meteor.beyondclouds.modules.blog.enums.BlogCommentErrorCode
;
import
cn.meteor.beyondclouds.modules.blog.enums.BlogErrorCode
;
import
cn.meteor.beyondclouds.modules.blog.enums.BlogErrorCode
;
import
cn.meteor.beyondclouds.modules.blog.enums.BlogPraiseErrorCode
;
import
cn.meteor.beyondclouds.modules.blog.enums.BlogPraiseErrorCode
;
import
cn.meteor.beyondclouds.modules.blog.enums.BlogPraiseType
;
import
cn.meteor.beyondclouds.modules.blog.exception.BlogCommentServiceException
;
import
cn.meteor.beyondclouds.modules.blog.exception.BlogCommentServiceException
;
import
cn.meteor.beyondclouds.modules.blog.exception.BlogPraiseServiceException
;
import
cn.meteor.beyondclouds.modules.blog.exception.BlogPraiseServiceException
;
import
cn.meteor.beyondclouds.modules.blog.exception.BlogServiceException
;
import
cn.meteor.beyondclouds.modules.blog.exception.BlogServiceException
;
...
@@ -17,7 +18,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
...
@@ -17,7 +18,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
/**
/**
* <p>
* <p>
...
@@ -45,66 +45,91 @@ public class BlogPraiseServiceImpl extends ServiceImpl<BlogPraiseMapper, BlogPra
...
@@ -45,66 +45,91 @@ public class BlogPraiseServiceImpl extends ServiceImpl<BlogPraiseMapper, BlogPra
}
}
@Override
@Override
public
void
praise
(
String
userId
,
String
targetId
,
Integer
targetType
)
throws
BlogServiceException
,
BlogPraiseServiceException
,
BlogCommentServiceException
{
public
void
praiseBlog
(
String
userId
,
String
blogId
)
throws
BlogPraiseServiceException
{
//判断是博客内容点赞还是博客评论
// 1.判断博客是否存在
if
(
1
==
targetType
)
{
Blog
blog
=
blogService
.
getById
(
blogId
);
//判断当前博客是否存在
if
(
null
==
blog
)
{
Blog
blog
=
blogService
.
getById
(
targetId
);
throw
new
BlogPraiseServiceException
(
BlogErrorCode
.
BLOG_NOT_FOUND
);
if
(
null
!=
blog
)
{
//判断该用户是否已经点过赞
QueryWrapper
<
BlogPraise
>
blogExtqueryWrapper
=
new
QueryWrapper
<>();
blogExtqueryWrapper
.
eq
(
"user_id"
,
userId
);
blogExtqueryWrapper
.
eq
(
"target_id"
,
targetId
);
BlogPraise
blogExtPraise
=
getOne
(
blogExtqueryWrapper
);
//如果没有点过赞则进行点赞
if
(
null
==
blogExtPraise
)
{
BlogPraise
blogPraise
=
new
BlogPraise
();
blogPraise
.
setUserId
(
userId
);
blogPraise
.
setTargetType
(
targetType
);
blogPraise
.
setTargetId
(
targetId
);
save
(
blogPraise
);
}
else
{
throw
new
BlogPraiseServiceException
(
BlogPraiseErrorCode
.
BLOG_PRAISE_EXIST
);
}
}
else
{
throw
new
BlogServiceException
(
BlogErrorCode
.
BLOG_NOT_FOUND
);
}
}
else
if
(
2
==
targetType
){
//判断当前评论是否存在
BlogComment
blogComment
=
blogCommentService
.
getById
(
targetId
);
if
(
null
!=
blogComment
)
{
//判断该用户是否已经对此评论点过赞了
QueryWrapper
<
BlogPraise
>
blogCommentQueryWrapper
=
new
QueryWrapper
<>();
blogCommentQueryWrapper
.
eq
(
"user_id"
,
userId
);
blogCommentQueryWrapper
.
eq
(
"target_id"
,
targetId
);
BlogPraise
blogCommentPraise
=
getOne
(
blogCommentQueryWrapper
);
if
(
null
==
blogCommentPraise
)
{
BlogPraise
blogPraise
=
new
BlogPraise
();
blogPraise
.
setUserId
(
userId
);
blogPraise
.
setTargetType
(
targetType
);
blogPraise
.
setTargetId
(
targetId
);
save
(
blogPraise
);
}
else
{
throw
new
BlogPraiseServiceException
(
BlogPraiseErrorCode
.
BLOG_PRAISE_EXIST
);
}
}
else
{
throw
new
BlogCommentServiceException
(
BlogCommentErrorCode
.
COMMENT_NOT_FOUND
);
}
}
}
// 2.判断该用户是否已经点过赞
QueryWrapper
<
BlogPraise
>
blogPraiseQueryWrapper
=
new
QueryWrapper
<>();
blogPraiseQueryWrapper
.
eq
(
"user_id"
,
userId
);
blogPraiseQueryWrapper
.
eq
(
"target_id"
,
blogId
);
blogPraiseQueryWrapper
.
eq
(
"target_type"
,
BlogPraiseType
.
BLOG_PRAISE
.
getPraiseType
());
BlogPraise
blogPraise
=
getOne
(
blogPraiseQueryWrapper
);
if
(
null
!=
blogPraise
)
{
throw
new
BlogPraiseServiceException
(
BlogPraiseErrorCode
.
BLOG_PRAISE_EXIST
);
}
// 3.保存点赞
blogPraise
=
new
BlogPraise
();
blogPraise
.
setTargetId
(
blogId
);
blogPraise
.
setTargetType
(
BlogPraiseType
.
BLOG_PRAISE
.
getPraiseType
());
blogPraise
.
setUserId
(
userId
);
save
(
blogPraise
);
}
}
@Override
@Override
public
void
delete
Praise
(
String
userId
,
String
target
Id
)
throws
BlogPraiseServiceException
{
public
void
delete
BlogPraise
(
String
userId
,
String
blog
Id
)
throws
BlogPraiseServiceException
{
//
判断是否是该用户点的
赞
//
1.判断是否点过
赞
QueryWrapper
<
BlogPraise
>
queryWrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
BlogPraise
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"user_id"
,
userId
);
queryWrapper
.
eq
(
"user_id"
,
userId
);
queryWrapper
.
eq
(
"target_id"
,
targetId
);
queryWrapper
.
eq
(
"target_id"
,
blogId
);
queryWrapper
.
eq
(
"target_type"
,
BlogPraiseType
.
BLOG_PRAISE
.
getPraiseType
());
BlogPraise
blogPraise
=
getOne
(
queryWrapper
);
BlogPraise
blogPraise
=
getOne
(
queryWrapper
);
if
(
null
==
blogPraise
)
{
if
(
null
==
blogPraise
)
{
throw
new
BlogPraiseServiceException
(
BlogPraiseErrorCode
.
NO_
DELETE_PRIVILEGES
);
throw
new
BlogPraiseServiceException
(
BlogPraiseErrorCode
.
NO_
PRAISE_FOUND
);
}
}
// 2.取消点赞
remove
(
queryWrapper
);
remove
(
queryWrapper
);
}
@Override
public
void
praiseBlogComment
(
String
currentUserId
,
String
commentId
)
throws
BlogPraiseServiceException
{
// 1.判断评论是否存在
BlogComment
blogComment
=
blogCommentService
.
getById
(
commentId
);
if
(
null
==
blogComment
)
{
throw
new
BlogPraiseServiceException
(
BlogCommentErrorCode
.
COMMENT_NOT_FOUND
);
}
// 2.判断该用户是否已经点过赞
QueryWrapper
<
BlogPraise
>
blogPraiseQueryWrapper
=
new
QueryWrapper
<>();
blogPraiseQueryWrapper
.
eq
(
"user_id"
,
currentUserId
);
blogPraiseQueryWrapper
.
eq
(
"target_id"
,
commentId
);
blogPraiseQueryWrapper
.
eq
(
"target_type"
,
BlogPraiseType
.
BLOG_COMMENT_PRAISE
.
getPraiseType
());
BlogPraise
blogPraise
=
getOne
(
blogPraiseQueryWrapper
);
if
(
null
!=
blogPraise
)
{
throw
new
BlogPraiseServiceException
(
BlogPraiseErrorCode
.
BLOG_PRAISE_EXIST
);
}
// 3.保存点赞
blogPraise
=
new
BlogPraise
();
blogPraise
.
setTargetId
(
commentId
);
blogPraise
.
setTargetType
(
BlogPraiseType
.
BLOG_COMMENT_PRAISE
.
getPraiseType
());
blogPraise
.
setUserId
(
currentUserId
);
save
(
blogPraise
);
}
@Override
public
void
deleteBlogCommentPraise
(
String
currentUserId
,
String
commentId
)
throws
BlogPraiseServiceException
{
// 1.判断是否点过赞
QueryWrapper
<
BlogPraise
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"user_id"
,
currentUserId
);
queryWrapper
.
eq
(
"target_id"
,
commentId
);
queryWrapper
.
eq
(
"target_type"
,
BlogPraiseType
.
BLOG_COMMENT_PRAISE
.
getPraiseType
());
BlogPraise
blogPraise
=
getOne
(
queryWrapper
);
if
(
null
==
blogPraise
)
{
throw
new
BlogPraiseServiceException
(
BlogPraiseErrorCode
.
NO_PRAISE_FOUND
);
}
// 2.取消点赞
remove
(
queryWrapper
);
}
}
}
}
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