Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo-1
Commits
cf40c6ef
Unverified
Commit
cf40c6ef
authored
Mar 30, 2019
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🐛
Fix #12733
parent
57cace98
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
5 deletions
+56
-5
src/main/java/org/b3log/solo/processor/CategoryProcessor.java
...main/java/org/b3log/solo/processor/CategoryProcessor.java
+53
-2
src/main/java/org/b3log/solo/service/ArticleQueryService.java
...main/java/org/b3log/solo/service/ArticleQueryService.java
+3
-3
No files found.
src/main/java/org/b3log/solo/processor/CategoryProcessor.java
View file @
cf40c6ef
...
...
@@ -29,7 +29,9 @@ import org.b3log.latke.servlet.RequestContext;
import
org.b3log.latke.servlet.annotation.RequestProcessing
;
import
org.b3log.latke.servlet.annotation.RequestProcessor
;
import
org.b3log.latke.servlet.renderer.AbstractFreeMarkerRenderer
;
import
org.b3log.latke.servlet.renderer.JsonRenderer
;
import
org.b3log.latke.util.Paginator
;
import
org.b3log.latke.util.Stopwatchs
;
import
org.b3log.latke.util.URLs
;
import
org.b3log.solo.model.Article
;
import
org.b3log.solo.model.Category
;
...
...
@@ -49,7 +51,7 @@ import java.util.Map;
* Category processor.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.
0.1.6, Jan 5
, 2019
* @version 1.
1.0.0, Mar 30
, 2019
* @since 2.0.0
*/
@RequestProcessor
...
...
@@ -102,6 +104,55 @@ public class CategoryProcessor {
@Inject
private
StatisticMgmtService
statisticMgmtService
;
/**
* Gets category articles paged with the specified context.
*
* @param context the specified context
*/
@RequestProcessing
(
value
=
"/articles/category/{categoryURI}"
,
method
=
HttpMethod
.
GET
)
public
void
getCategoryArticlesByPage
(
final
RequestContext
context
)
{
final
JSONObject
jsonObject
=
new
JSONObject
();
final
HttpServletRequest
request
=
context
.
getRequest
();
final
String
categoryURI
=
context
.
pathVar
(
"categoryURI"
);
final
int
currentPageNum
=
Paginator
.
getPage
(
request
);
Stopwatchs
.
start
(
"Get Category-Articles Paged [categoryURI="
+
categoryURI
+
", pageNum="
+
currentPageNum
+
']'
);
try
{
final
JSONObject
category
=
categoryQueryService
.
getByURI
(
categoryURI
);
if
(
null
==
category
)
{
context
.
sendError
(
HttpServletResponse
.
SC_NOT_FOUND
);
return
;
}
jsonObject
.
put
(
Keys
.
STATUS_CODE
,
true
);
final
String
categoryId
=
category
.
optString
(
Keys
.
OBJECT_ID
);
final
JSONObject
preference
=
optionQueryService
.
getPreference
();
final
int
pageSize
=
preference
.
getInt
(
Option
.
ID_C_ARTICLE_LIST_DISPLAY_COUNT
);
final
JSONObject
articlesResult
=
articleQueryService
.
getCategoryArticles
(
categoryId
,
currentPageNum
,
pageSize
);
final
List
<
JSONObject
>
articles
=
(
List
<
JSONObject
>)
articlesResult
.
opt
(
Keys
.
RESULTS
);
dataModelService
.
setArticlesExProperties
(
context
,
articles
,
preference
);
final
int
pageCount
=
articlesResult
.
optJSONObject
(
Pagination
.
PAGINATION
).
optInt
(
Pagination
.
PAGINATION_PAGE_COUNT
);
final
JSONObject
result
=
new
JSONObject
();
final
JSONObject
pagination
=
new
JSONObject
();
pagination
.
put
(
Pagination
.
PAGINATION_PAGE_COUNT
,
pageCount
);
result
.
put
(
Pagination
.
PAGINATION
,
pagination
);
result
.
put
(
Article
.
ARTICLES
,
articles
);
jsonObject
.
put
(
Keys
.
RESULTS
,
result
);
}
catch
(
final
Exception
e
)
{
jsonObject
.
put
(
Keys
.
STATUS_CODE
,
false
);
LOGGER
.
log
(
Level
.
ERROR
,
"Gets article paged failed"
,
e
);
}
finally
{
Stopwatchs
.
end
();
}
final
JsonRenderer
renderer
=
new
JsonRenderer
();
context
.
setRenderer
(
renderer
);
renderer
.
setJSONObject
(
jsonObject
);
}
/**
* Shows articles related with a category with the specified context.
*
...
...
@@ -134,7 +185,7 @@ public class CategoryProcessor {
final
String
categoryId
=
category
.
optString
(
Keys
.
OBJECT_ID
);
final
JSONObject
result
=
articleQueryService
.
getCategoryArticles
(
categoryId
,
currentPageNum
,
pageSize
);
final
List
<
JSONObject
>
articles
=
(
List
<
JSONObject
>)
result
.
opt
(
Article
.
ARTICLE
S
);
final
List
<
JSONObject
>
articles
=
(
List
<
JSONObject
>)
result
.
opt
(
Keys
.
RESULT
S
);
final
int
pageCount
=
result
.
optJSONObject
(
Pagination
.
PAGINATION
).
optInt
(
Pagination
.
PAGINATION_PAGE_COUNT
);
if
(
0
==
pageCount
)
{
...
...
src/main/java/org/b3log/solo/service/ArticleQueryService.java
View file @
cf40c6ef
...
...
@@ -53,7 +53,7 @@ import static org.b3log.solo.model.Article.*;
* @author <a href="https://hacpai.com/member/armstrong">ArmstrongCN</a>
* @author <a href="http://zephyr.b3log.org">Zephyr</a>
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @version 1.3.2.1
1, Mar 4
, 2019
* @version 1.3.2.1
2, Mar 30
, 2019
* @since 0.3.5
*/
@Service
...
...
@@ -179,7 +179,7 @@ public class ArticleQueryService {
public
JSONObject
getCategoryArticles
(
final
String
categoryId
,
final
int
currentPageNum
,
final
int
pageSize
)
throws
ServiceException
{
final
JSONObject
ret
=
new
JSONObject
();
ret
.
put
(
Article
.
ARTICLE
S
,
(
Object
)
Collections
.
emptyList
());
ret
.
put
(
Keys
.
RESULT
S
,
(
Object
)
Collections
.
emptyList
());
final
JSONObject
pagination
=
new
JSONObject
();
ret
.
put
(
Pagination
.
PAGINATION
,
pagination
);
...
...
@@ -241,7 +241,7 @@ public class ArticleQueryService {
articles
.
add
(
article
);
}
ret
.
put
(
Article
.
ARTICLE
S
,
(
Object
)
articles
);
ret
.
put
(
Keys
.
RESULT
S
,
(
Object
)
articles
);
return
ret
;
}
catch
(
final
RepositoryException
e
)
{
...
...
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