Skip to content

Commit 70d4dca

Browse files
committed
Fix pageable method
1 parent 65b63b2 commit 70d4dca

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

backend/src/main/java/es/codeurjc/wallypop/controller/api/ArticleRestController.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,12 @@ public ResponseEntity<Map<String, Object>> articlesPagination(HttpServletRequest
5757
if (page != -1) { // with pagination
5858
int pageSize = 10;
5959
Principal principal = request.getUserPrincipal();
60-
if(principal != null) {
61-
User user = userService.findByNAME(principal.getName()).get();
6260
try {
63-
6461
Map<String, Object> response = new HashMap<>();
6562
List<String> articles_info = new LinkedList<String>();
6663
Pageable paging = (Pageable) PageRequest.of(0, pageSize);
6764
Page<Article> pageTuts;
68-
69-
pageTuts = articleService.findByUSERS(user, paging.withPage(page));
65+
pageTuts = articleService.findAllPageable(paging.withPage(page));
7066
if(pageTuts.getNumberOfElements() == 0) {
7167
articles_info.add("Empty");
7268
}else {
@@ -79,16 +75,10 @@ public ResponseEntity<Map<String, Object>> articlesPagination(HttpServletRequest
7975
response.put("totalItemsUser", pageTuts.getTotalElements());
8076
response.put("totalItemsThisPage", pageTuts.getNumberOfElements());
8177
response.put("articles", articles_info);
82-
83-
84-
8578
return new ResponseEntity<>(response, HttpStatus.OK);
8679
} catch (Exception e) {
8780
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
8881
}
89-
} else {
90-
return ResponseEntity.notFound().build();
91-
}
9282
}else { // without pagination
9383
Principal principal = request.getUserPrincipal();
9484
if(principal != null) {

backend/src/main/java/es/codeurjc/wallypop/service/ArticleService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ public void deletePost(long id, Long id_user, boolean admin) {
3838
public boolean exist(long id) {
3939
return articleRepository.existsById(id);
4040
}
41-
41+
42+
public Page<Article> findAllPageable(Pageable pageable) {
43+
return articleRepository.findAll(pageable);
44+
}
4245
/*
4346
public Page<Article> findByUSERS(User user, Pageable pageable) {
4447
return articleRepository.findByUSERS(user, pageable);

0 commit comments

Comments
 (0)