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
c8e81e9f
Commit
c8e81e9f
authored
Feb 08, 2020
by
胡学良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
得到标签下的问答列表
parent
0d81a6b5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
2 deletions
+52
-2
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionApi.java
+13
-0
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionTagErrorCode.java
+4
-1
src/main/java/cn/meteor/beyondclouds/modules/question/service/IQuestionService.java
+10
-0
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionServiceImpl.java
+24
-0
src/main/resources/application.yml
+1
-1
No files found.
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionApi.java
View file @
c8e81e9f
...
...
@@ -255,5 +255,18 @@ public class QuestionApi {
return
Response
.
success
(
questionPageVO
);
}
@Anonymous
@ApiOperation
(
"标签下的问答列表"
)
@GetMapping
(
"/tag/{tagId}/questions"
)
public
Response
<
PageVO
<
Question
>>
getQuestionsByTagId
(
@Valid
PageForm
pageForm
,
@PathVariable
(
"tagId"
)
String
tagId
)
{
try
{
IPage
<
Question
>
page
=
questionService
.
getQuestionsByTagId
(
pageForm
.
getPage
(),
pageForm
.
getSize
(),
tagId
);
PageVO
<
Question
>
pageVO
=
new
PageVO
<>(
page
);
return
Response
.
success
(
pageVO
);
}
catch
(
QuestionTagServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
}
}
}
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionTagErrorCode.java
View file @
c8e81e9f
...
...
@@ -7,7 +7,10 @@ import cn.meteor.beyondclouds.core.IErrorCode;
* @since 2020/2/1
*/
public
enum
QuestionTagErrorCode
implements
IErrorCode
{
;
/**
* 标签不存在
*/
TAG_NOT_FOUND
(
6001
,
"标签不存在"
);
private
long
code
;
private
String
msg
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/question/service/IQuestionService.java
View file @
c8e81e9f
...
...
@@ -93,4 +93,14 @@ public interface IQuestionService extends IService<Question> {
*/
IPage
<
Question
>
getHotsQuestionsPage
(
Integer
pageNumber
,
Integer
pageSize
);
/**
* 得到标签下的问答列表
* @param pageNumber 页数
* @param pageSize 页面大小
* @param tagId 标签ID
* @return 分页对象
* @throws QuestionTagServiceException 问题标签业务异常
*/
IPage
<
Question
>
getQuestionsByTagId
(
Integer
pageNumber
,
Integer
pageSize
,
String
tagId
)
throws
QuestionTagServiceException
;
}
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionServiceImpl.java
View file @
c8e81e9f
...
...
@@ -3,6 +3,7 @@ package cn.meteor.beyondclouds.modules.question.service.impl;
import
cn.meteor.beyondclouds.modules.question.bean.QuestionDetails
;
import
cn.meteor.beyondclouds.modules.question.entity.*
;
import
cn.meteor.beyondclouds.modules.question.enums.QuestionErrorCode
;
import
cn.meteor.beyondclouds.modules.question.enums.QuestionTagErrorCode
;
import
cn.meteor.beyondclouds.modules.question.exception.QuestionServiceException
;
import
cn.meteor.beyondclouds.modules.question.exception.QuestionTagServiceException
;
import
cn.meteor.beyondclouds.modules.question.mapper.QuestionMapper
;
...
...
@@ -418,4 +419,27 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
questionTagService
.
remove
(
questionTagQueryWrapper
);
}
@Override
public
IPage
<
Question
>
getQuestionsByTagId
(
Integer
pageNumber
,
Integer
pageSize
,
String
tagId
)
throws
QuestionTagServiceException
{
IPage
<
Question
>
page
=
new
Page
<>(
pageNumber
,
pageSize
);
//1.检查标签是否存在
Tag
tag
=
tagService
.
getById
(
tagId
);
if
(
null
==
tag
)
{
throw
new
QuestionTagServiceException
(
QuestionTagErrorCode
.
TAG_NOT_FOUND
);
}
//2.通过标签ID得到对应的问题ID
List
<
String
>
questionIds
=
questionTagService
.
list
(
QuestionUtils
.
getWrapper
(
"tag_id"
,
tag
.
getTagId
()))
.
stream
().
map
(
QuestionTag:
:
getQuestionId
).
collect
(
Collectors
.
toList
());
if
(!
CollectionUtils
.
isEmpty
(
questionIds
))
{
QueryWrapper
<
Question
>
questionQueryWrapper
=
new
QueryWrapper
<>();
questionQueryWrapper
.
in
(
"q.question_id"
,
questionIds
)
.
orderByDesc
(
"q.create_time"
);
return
questionMapper
.
selectPageWithTags
(
page
,
questionQueryWrapper
);
}
else
{
return
page
;
}
}
}
src/main/resources/application.yml
View file @
c8e81e9f
...
...
@@ -3,7 +3,7 @@ spring:
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username
:
root
password
:
1
00Centa30821%mysql
password
:
1
97442
mail
:
host
:
smtp.163.com
username
:
13546386889@163.com
...
...
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