|
@@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping("/article")
|
|
@@ -172,12 +173,38 @@ public class ArticleController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- @GetMapping("/all")
|
|
|
- public ResponseEntity getArticles() {
|
|
|
- List<ArticleDTO> articleDTOs = this.articleService.findAll();
|
|
|
+ // @GetMapping("/all")
|
|
|
+ // public ResponseEntity getAllArticles() {
|
|
|
+ // List<ArticleDTO> articleDTOs = this.articleService.findAll();
|
|
|
+ // Map<String, Object> data = new HashMap<>();
|
|
|
+ // data.put("articles", articleDTOs);
|
|
|
+
|
|
|
+ // return ResponseEntity.ok().body(data);
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 필요한 것들
|
|
|
+ * - feed: your-feed or global-feed(디폴트)
|
|
|
+ * - articleId: cursor (디폴트 -1, -1인 경우 최초 데이터 조회)
|
|
|
+ */
|
|
|
+ @GetMapping("/page")
|
|
|
+ public ResponseEntity getArticles(HttpServletRequest request,
|
|
|
+ @RequestParam(defaultValue = "global-feed") String feed,
|
|
|
+ @RequestParam(defaultValue = "-1") int articleId) {
|
|
|
+ int userId = (int) request.getSession().getAttribute("ssId");
|
|
|
+
|
|
|
+ List<ArticleDTO> articleDTOs = this.articleService.find(articleId, feed, userId);
|
|
|
+ // List<ArticleDTO> articleDTOs = this.articleService.find(articleId, feed, 10);
|
|
|
+
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
data.put("articles", articleDTOs);
|
|
|
|
|
|
+ final int size = articleDTOs.size();
|
|
|
+ int lastItemArticleId = (size != 0) ? articleDTOs.get(size - 1).getId() : -1;
|
|
|
+ data.put("paging", this.articleService.calculatePagingInfo(articleDTOs, lastItemArticleId, feed, userId));
|
|
|
+ // data.put("paging", this.articleService.calculatePagingInfo(articleDTOs, lastItemArticleId, feed, 10));
|
|
|
+
|
|
|
return ResponseEntity.ok().body(data);
|
|
|
}
|
|
|
|
|
@@ -223,4 +250,4 @@ public class ArticleController {
|
|
|
this.commentService.remove(userId, articleId, commentId);
|
|
|
return ResponseEntity.ok().body("성공적으로 삭제했습니다.");
|
|
|
}
|
|
|
-}
|
|
|
+}
|