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
808953cc
Commit
808953cc
authored
Feb 20, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
动态点赞完成
parent
2bb8e4ad
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
42 deletions
+57
-42
src/main/java/cn/meteor/beyondclouds/modules/post/api/PostPraiseApi.java
+7
-11
src/main/java/cn/meteor/beyondclouds/modules/post/enums/PostPraiseType.java
+26
-0
src/main/java/cn/meteor/beyondclouds/modules/post/service/IPostPraiseService.java
+4
-6
src/main/java/cn/meteor/beyondclouds/modules/post/service/impl/PostPraiseServiceImpl.java
+20
-25
No files found.
src/main/java/cn/meteor/beyondclouds/modules/post/api/PostPraiseApi.java
View file @
808953cc
...
...
@@ -27,35 +27,31 @@ public class PostPraiseApi {
this
.
postPraiseService
=
postPraiseService
;
}
@ApiOperation
(
"点赞"
)
@PostMapping
(
"/post/{targetId}/praise"
)
public
Response
praise
(
@PathVariable
(
"targetId"
)
String
targetId
,
@RequestParam
(
"targetType"
)
Integer
targetType
)
{
@ApiOperation
(
"动态点赞"
)
@PostMapping
(
"/post/{postId}/praise"
)
public
Response
praise
(
@PathVariable
(
"postId"
)
String
postId
)
{
Subject
subject
=
SubjectUtils
.
getSubject
();
String
currentUserId
=
(
String
)
subject
.
getId
();
try
{
postPraiseService
.
postPraise
(
currentUserId
,
targetId
,
targetType
);
postPraiseService
.
postPraise
(
currentUserId
,
postId
);
return
Response
.
success
();
}
catch
(
PostServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
}
}
@ApiOperation
(
"取消点赞"
)
@DeleteMapping
(
"/post/{targetId}/praise"
)
public
Response
deletePraise
(
@PathVariable
(
"targetId"
)
String
targetId
,
@RequestParam
(
"targetType"
)
Integer
targetType
)
{
@DeleteMapping
(
"/post/{postId}/praise"
)
public
Response
deletePraise
(
@PathVariable
(
"postId"
)
String
postId
)
{
Subject
subject
=
SubjectUtils
.
getSubject
();
String
currentUserId
=
(
String
)
subject
.
getId
();
try
{
postPraiseService
.
delPostPraise
(
currentUserId
,
targetId
,
targetType
);
postPraiseService
.
delPostPraise
(
currentUserId
,
postId
);
return
Response
.
success
();
}
catch
(
PostServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
}
}
...
...
src/main/java/cn/meteor/beyondclouds/modules/post/enums/PostPraiseType.java
0 → 100644
View file @
808953cc
package
cn
.
meteor
.
beyondclouds
.
modules
.
post
.
enums
;
import
lombok.Getter
;
/**
* @author meteor
*/
@Getter
public
enum
PostPraiseType
{
/**
* 动态点赞
*/
POST_PRAISE
(
1
),
/**
* 给动态评论点赞
*/
POST_COMMENT_PRAISE
(
2
)
;
private
Integer
praiseType
;
PostPraiseType
(
Integer
praiseType
)
{
this
.
praiseType
=
praiseType
;
}
}
src/main/java/cn/meteor/beyondclouds/modules/post/service/IPostPraiseService.java
View file @
808953cc
...
...
@@ -17,18 +17,16 @@ public interface IPostPraiseService extends IService<PostPraise> {
/**
* 动态以及动态评论的点赞
* @param currentUserId
* @param targetId
* @param targetType
* @param postId
* @throws PostServiceException
*/
void
postPraise
(
String
currentUserId
,
String
targetId
,
Integer
targetType
)
throws
PostServiceException
;
void
postPraise
(
String
currentUserId
,
String
postId
)
throws
PostServiceException
;
/**
* 取消动态以及动态评论的点赞
* @param currentUserId
* @param targetId
* @param targetType
* @param postId
* @throws PostServiceException
*/
void
delPostPraise
(
String
currentUserId
,
String
targetId
,
Integer
targetType
)
throws
PostServiceException
;
void
delPostPraise
(
String
currentUserId
,
String
postId
)
throws
PostServiceException
;
}
src/main/java/cn/meteor/beyondclouds/modules/post/service/impl/PostPraiseServiceImpl.java
View file @
808953cc
package
cn
.
meteor
.
beyondclouds
.
modules
.
post
.
service
.
impl
;
import
cn.meteor.beyondclouds.modules.post.entity.Post
;
import
cn.meteor.beyondclouds.modules.post.entity.PostPraise
;
import
cn.meteor.beyondclouds.modules.post.enums.PostCommentErrorCode
;
import
cn.meteor.beyondclouds.modules.post.enums.PostErrorCode
;
import
cn.meteor.beyondclouds.modules.post.enums.PostPraiseType
;
import
cn.meteor.beyondclouds.modules.post.exception.PostServiceException
;
import
cn.meteor.beyondclouds.modules.post.mapper.PostPraiseMapper
;
import
cn.meteor.beyondclouds.modules.post.service.IPostCommentService
;
...
...
@@ -13,11 +14,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* <p>
*
服务实现类
* 服务实现类
* </p>
*
* @author 段启岩
...
...
@@ -40,49 +39,45 @@ public class PostPraiseServiceImpl extends ServiceImpl<PostPraiseMapper, PostPra
}
@Override
public
void
postPraise
(
String
currentUserId
,
String
targetId
,
Integer
targetType
)
throws
PostServiceException
{
public
void
postPraise
(
String
currentUserId
,
String
postId
)
throws
PostServiceException
{
//1. 判断目标类型是否正确
if
(!
List
.
of
(
1
,
2
).
contains
(
targetType
))
{
throw
new
PostServiceException
(
PostErrorCode
.
POST_PRAISE_TYPE_ERROR
);
// 1.判断动态是否存在
Post
post
=
postService
.
getById
(
postId
);
if
(
null
==
post
)
{
throw
new
PostServiceException
(
PostErrorCode
.
POST_NOT_FOUND
);
}
//
2. 判断用户是否给目标动态或动态评论
点过赞
//
2. 判断用户是否给目标动态
点过赞
QueryWrapper
<
PostPraise
>
postPraiseQueryWrapper
=
new
QueryWrapper
<>();
postPraiseQueryWrapper
.
eq
(
"target_id"
,
targetId
)
.
eq
(
"user_id"
,
currentUserId
);
.
eq
(
"target_id"
,
postId
)
.
eq
(
"user_id"
,
currentUserId
)
.
eq
(
"target_type"
,
PostPraiseType
.
POST_PRAISE
.
getPraiseType
());
PostPraise
postPraise
=
getOne
(
postPraiseQueryWrapper
);
if
(
null
!=
postPraise
)
{
throw
new
PostServiceException
(
PostErrorCode
.
POST_PRAISE_EXIST
);
}
//3. 判断对应的动态或评论是否存在
if
((
targetType
==
1
)
&&
(
null
==
postService
.
getById
(
targetId
)))
{
throw
new
PostServiceException
(
PostErrorCode
.
POST_NOT_FOUND
);
}
if
((
targetType
==
2
)
&&
(
null
==
postCommentService
.
getById
(
targetId
)))
{
throw
new
PostServiceException
(
PostCommentErrorCode
.
COMMENT_NOT_FOUND
);
}
//4. 点赞
postPraise
=
new
PostPraise
();
postPraise
.
setUserId
(
currentUserId
);
postPraise
.
setTargetId
(
targe
tId
);
postPraise
.
setTargetType
(
targetType
);
postPraise
.
setTargetId
(
pos
tId
);
postPraise
.
setTargetType
(
PostPraiseType
.
POST_PRAISE
.
getPraiseType
()
);
save
(
postPraise
);
}
@Override
public
void
delPostPraise
(
String
currentUserId
,
String
targetId
,
Integer
targetType
)
throws
PostServiceException
{
public
void
delPostPraise
(
String
currentUserId
,
String
postId
)
throws
PostServiceException
{
//1. 判断用户是否给目标动态或动态评论点过赞
QueryWrapper
<
PostPraise
>
postPraiseQueryWrapper
=
new
QueryWrapper
<>();
postPraiseQueryWrapper
.
eq
(
"target_id"
,
targetId
)
.
eq
(
"user_id"
,
currentUserId
);
.
eq
(
"target_id"
,
postId
)
.
eq
(
"user_id"
,
currentUserId
)
.
eq
(
"target_type"
,
PostPraiseType
.
POST_PRAISE
.
getPraiseType
());
PostPraise
postPraise
=
getOne
(
postPraiseQueryWrapper
);
if
(
null
==
postPraise
)
{
...
...
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