|
@@ -9,7 +9,6 @@ import com.dbs.realworld.mapper.ArticleMapper;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
public class ArticleService {
|
|
public class ArticleService {
|
|
@@ -23,6 +22,7 @@ public class ArticleService {
|
|
|
this.commentService = commentService;
|
|
this.commentService = commentService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// default: rollbackFor = {RuntimeExceeption.class, Error.class}
|
|
// default: rollbackFor = {RuntimeExceeption.class, Error.class}
|
|
|
// uncheckedException과 error 뿐만 아니라 모든 예외에 대해 롤백하고 싶은 경우
|
|
// uncheckedException과 error 뿐만 아니라 모든 예외에 대해 롤백하고 싶은 경우
|
|
|
// @Transactional(rollbackFor = Exception.class)
|
|
// @Transactional(rollbackFor = Exception.class)
|
|
@@ -32,27 +32,48 @@ public class ArticleService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 사용자 상세 페이지에 배치될 아티클 리스트
|
|
|
|
|
+ * 피드 타입이 "your-type"인 경우 해당 사용자가 좋아요 한 게시물 리스트
|
|
|
|
|
+ * "favorite-type"인 경우 사용자가 좋아요 한 게시물 리스트
|
|
|
|
|
+ * @param viewer 조회자
|
|
|
|
|
+ * @param userId 타겟 사용자 아이디
|
|
|
|
|
+ * @param articleId 커서
|
|
|
|
|
+ * @param feed 피드 타입
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<ArticleDTO> findMyArticles(int viewer, int userId, int articleId, String feed) {
|
|
|
|
|
+ List<ArticleDTO> articles = null;
|
|
|
|
|
+ if (feed.equals("your-feed")) {
|
|
|
|
|
+ articles = this.articleMapper.selectMyArticles(viewer, userId, articleId);
|
|
|
|
|
+ } else if (feed.equals("favorite-feed")) {
|
|
|
|
|
+ articles = this.articleMapper.selectFavoriteArticles(viewer, userId, articleId);
|
|
|
|
|
+ }
|
|
|
|
|
+ return articles;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
* @param feed feed 타입, 'your-feed', 'global-feed'
|
|
* @param feed feed 타입, 'your-feed', 'global-feed'
|
|
|
* @param id cursor(articleId), 다음 페이지에 필요한 데이터를 위한 기준
|
|
* @param id cursor(articleId), 다음 페이지에 필요한 데이터를 위한 기준
|
|
|
*/
|
|
*/
|
|
|
- public List<ArticleDTO> find(int articleId, String feed, int userId) {
|
|
|
|
|
|
|
+ public List<ArticleDTO> find(int articleId, String feed, int userId) {
|
|
|
return this.articleMapper.select(articleId, feed, userId);
|
|
return this.articleMapper.select(articleId, feed, userId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- public Map<String, Object> calculatePagingInfo(List<ArticleDTO> articleDTOs, int lastArticleId, String feed, int userId) {
|
|
|
|
|
|
|
+ public Map<String, Object> calculatePagingInfo(List<ArticleDTO> articleDTOs, String feed, int userId) {
|
|
|
|
|
+
|
|
|
|
|
+ final int size = articleDTOs.size();
|
|
|
|
|
+ int lastArticleId = (size != 0) ? articleDTOs.get(size - 1).getId() : -1;
|
|
|
|
|
+
|
|
|
Map<String, Object> paging = this.articleMapper.selectPagingInfo(lastArticleId, feed, userId);
|
|
Map<String, Object> paging = this.articleMapper.selectPagingInfo(lastArticleId, feed, userId);
|
|
|
paging.put("size", articleDTOs.size());
|
|
paging.put("size", articleDTOs.size());
|
|
|
if (lastArticleId == -1) {
|
|
if (lastArticleId == -1) {
|
|
|
paging.put("isNext", false);
|
|
paging.put("isNext", false);
|
|
|
- paging.put("firstId", null);
|
|
|
|
|
- paging.put("lastId", null);
|
|
|
|
|
} else {
|
|
} else {
|
|
|
paging.put("isNext", ((Long) paging.get("nextItemNum")).intValue() > 0);
|
|
paging.put("isNext", ((Long) paging.get("nextItemNum")).intValue() > 0);
|
|
|
- paging.put("firstId", articleDTOs.get(0).getId());
|
|
|
|
|
- paging.put("lastId", articleDTOs.get(articleDTOs.size() - 1).getId());
|
|
|
|
|
}
|
|
}
|
|
|
return paging;
|
|
return paging;
|
|
|
}
|
|
}
|
|
@@ -71,8 +92,6 @@ public class ArticleService {
|
|
|
List<CommentDTO> commentDTOs = this.commentService.findAllByArticleId(articleId);
|
|
List<CommentDTO> commentDTOs = this.commentService.findAllByArticleId(articleId);
|
|
|
articleDTO.setComments(commentDTOs);
|
|
articleDTO.setComments(commentDTOs);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
return articleDTO;
|
|
return articleDTO;
|
|
|
}
|
|
}
|
|
|
|
|
|