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
611f56f1
Commit
611f56f1
authored
Feb 06, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增删除话题关注的接口
parent
e9b05067
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
16 deletions
+55
-16
src/main/java/cn/meteor/beyondclouds/modules/topic/api/TopicApi.java
+14
-0
src/main/java/cn/meteor/beyondclouds/modules/topic/enums/TopicErrorCode.java
+2
-1
src/main/java/cn/meteor/beyondclouds/modules/topic/service/ITopicService.java
+9
-0
src/main/java/cn/meteor/beyondclouds/modules/topic/service/impl/TopicServiceImpl.java
+30
-15
No files found.
src/main/java/cn/meteor/beyondclouds/modules/topic/api/TopicApi.java
View file @
611f56f1
...
...
@@ -142,4 +142,18 @@ public class TopicApi {
return
Response
.
success
(
topicPageVO
);
}
@ApiOperation
(
"取消关注话题"
)
@DeleteMapping
(
"/topic/{topicId}/follower"
)
public
Response
delTopicFollower
(
@PathVariable
(
"topicId"
)
String
topicId
,
@CurrentSubject
Subject
subject
)
{
try
{
topicService
.
delFollowTopic
((
String
)
subject
.
getId
(),
topicId
);
return
Response
.
success
();
}
catch
(
TopicServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
}
}
}
src/main/java/cn/meteor/beyondclouds/modules/topic/enums/TopicErrorCode.java
View file @
611f56f1
...
...
@@ -13,7 +13,8 @@ public enum TopicErrorCode implements IErrorCode {
*/
TOPIC_EXISTS
(
3001
,
"该话题已存在"
),
TOPIC_NOT_EXISTS
(
3002
,
"该话题不存在"
),
AlREADY_FOLLOWED
(
3003
,
"已关注过该话题"
);
AlREADY_FOLLOWED
(
3003
,
"已关注过该话题"
),
NOT_FOLLOWED
(
3004
,
"未关注过该话题"
);
TopicErrorCode
(
long
code
,
String
msg
)
{
this
.
code
=
code
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/topic/service/ITopicService.java
View file @
611f56f1
package
cn
.
meteor
.
beyondclouds
.
modules
.
topic
.
service
;
import
cn.meteor.beyondclouds.modules.tag.exception.TagServiceException
;
import
cn.meteor.beyondclouds.modules.topic.entity.Topic
;
import
cn.meteor.beyondclouds.modules.topic.exception.TopicServiceException
;
import
cn.meteor.beyondclouds.modules.user.entity.User
;
...
...
@@ -87,4 +88,12 @@ public interface ITopicService extends IService<Topic> {
* @param count
*/
void
increaseReferenceCount
(
String
topicId
,
int
count
);
/**
* 取消关注话题
* @param userId
* @param topicId
* @throws TopicServiceException
*/
void
delFollowTopic
(
String
userId
,
String
topicId
)
throws
TopicServiceException
;
}
src/main/java/cn/meteor/beyondclouds/modules/topic/service/impl/TopicServiceImpl.java
View file @
611f56f1
package
cn
.
meteor
.
beyondclouds
.
modules
.
topic
.
service
.
impl
;
import
cn.meteor.beyondclouds.modules.tag.exception.TagServiceException
;
import
cn.meteor.beyondclouds.modules.topic.entity.Topic
;
import
cn.meteor.beyondclouds.modules.topic.entity.TopicFollow
;
import
cn.meteor.beyondclouds.modules.topic.enums.TopicErrorCode
;
...
...
@@ -15,7 +16,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.util.List
;
import
java.util.stream.Collectors
;
...
...
@@ -109,7 +109,7 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
@Override
public
IPage
<
Topic
>
getTopicsMyFollowed
(
Integer
pageNumber
,
Integer
pageSize
,
String
userId
)
{
// 1. 通过用户id获取
该话题所有关注着
// 1. 通过用户id获取
关注的所有话题id
// 设置分页信息
IPage
<
TopicFollow
>
page
=
new
Page
<>(
pageNumber
,
pageSize
);
...
...
@@ -123,13 +123,8 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
.
map
(
TopicFollow:
:
getTopicId
)
.
collect
(
Collectors
.
toList
());
// 3. 通过用户id批量查询用户
List
<
Topic
>
topics
;
if
(
CollectionUtils
.
isEmpty
(
topicIds
))
{
topics
=
List
.
of
();
}
else
{
topics
=
listByIds
(
topicIds
);
}
// 3. 通过话题id批量查询用户
List
<
Topic
>
topics
=
listByIds
(
topicIds
);
// 5.构造分页结果
IPage
<
Topic
>
userPage
=
new
Page
<>();
...
...
@@ -160,12 +155,7 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
.
collect
(
Collectors
.
toList
());
// 3. 通过用户id批量查询用户
List
<
User
>
followers
;
if
(
CollectionUtils
.
isEmpty
(
followerIds
))
{
followers
=
List
.
of
();
}
else
{
followers
=
userService
.
listByIds
(
followerIds
);
}
List
<
User
>
followers
=
userService
.
listByIds
(
followerIds
);
// 4.去除敏感信息
followers
.
stream
()
...
...
@@ -212,4 +202,29 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
}
}
@Override
public
void
delFollowTopic
(
String
userId
,
String
topicId
)
throws
TopicServiceException
{
//1. 获取话题
Topic
topic
=
getById
(
topicId
);
//2. 找不到该话题,抛出业务异常
if
(
topic
==
null
)
{
throw
new
TopicServiceException
(
TopicErrorCode
.
TOPIC_NOT_EXISTS
);
}
//3. 判断用户是否关注该话题
QueryWrapper
<
TopicFollow
>
delTopicFollowQueryWrapper
=
new
QueryWrapper
<>();
delTopicFollowQueryWrapper
.
eq
(
"user_id"
,
userId
);
delTopicFollowQueryWrapper
.
eq
(
"topic_id"
,
topicId
);
if
(
null
==
topicFollowService
.
getOne
(
delTopicFollowQueryWrapper
))
{
throw
new
TopicServiceException
(
TopicErrorCode
.
NOT_FOLLOWED
);
}
//4. 取消关注话题
topicFollowService
.
remove
(
delTopicFollowQueryWrapper
);
}
}
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