Implements Article Pagination Query
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package com.yam.app.article.domain;
|
package com.yam.app.article.domain;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
public interface ArticleReader {
|
public interface ArticleReader {
|
||||||
|
|
||||||
@@ -9,4 +11,6 @@ public interface ArticleReader {
|
|||||||
Optional<Article> findById(Long articleId);
|
Optional<Article> findById(Long articleId);
|
||||||
|
|
||||||
boolean existsById(Long articleId);
|
boolean existsById(Long articleId);
|
||||||
|
|
||||||
|
List<Long> findAll(@Param("offset") int offset, @Param("limit") int limit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.yam.app.article.infrastructure;
|
|||||||
import com.yam.app.article.domain.Article;
|
import com.yam.app.article.domain.Article;
|
||||||
import com.yam.app.article.domain.ArticleReader;
|
import com.yam.app.article.domain.ArticleReader;
|
||||||
import com.yam.app.article.domain.ArticleRepository;
|
import com.yam.app.article.domain.ArticleRepository;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.mybatis.spring.SqlSessionTemplate;
|
import org.mybatis.spring.SqlSessionTemplate;
|
||||||
|
|
||||||
@@ -40,4 +41,9 @@ public final class MybatisArticleRepository implements ArticleReader, ArticleRep
|
|||||||
return template.getMapper(ArticleReader.class).existsById(articleId);
|
return template.getMapper(ArticleReader.class).existsById(articleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Long> findAll(int offset, int limit) {
|
||||||
|
return template.getMapper(ArticleReader.class).findAll(offset, limit);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,20 @@
|
|||||||
|
|
||||||
<mapper namespace="com.yam.app.article.domain.ArticleReader">
|
<mapper namespace="com.yam.app.article.domain.ArticleReader">
|
||||||
|
|
||||||
|
<select id="findAll" resultMap="articleId">
|
||||||
|
SELECT
|
||||||
|
DISTINCT(a.id) AS article_id, a.created_at
|
||||||
|
FROM article a
|
||||||
|
INNER JOIN article_tag atg ON atg.article_id = a.id
|
||||||
|
INNER JOIN tag t ON t.id = atg.tag_id
|
||||||
|
ORDER BY a.created_at DESC
|
||||||
|
LIMIT #{offset}, #{limit}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<resultMap id="articleId" type="Long">
|
||||||
|
<id javaType="Long" column="article_id"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
<select id="existsById" parameterType="Long" resultType="boolean">
|
<select id="existsById" parameterType="Long" resultType="boolean">
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM ARTICLE
|
FROM ARTICLE
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.yam.app.article.domain;
|
package com.yam.app.article.domain;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -35,4 +36,9 @@ public final class FakeArticleRepository implements ArticleRepository, ArticleRe
|
|||||||
public boolean existsById(Long articleId) {
|
public boolean existsById(Long articleId) {
|
||||||
return data.containsKey(articleId);
|
return data.containsKey(articleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Long> findAll(int offset, int limit) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.yam.app.article.infrastructure;
|
||||||
|
|
||||||
|
import com.yam.app.article.domain.ArticleReader;
|
||||||
|
import java.util.List;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@ActiveProfiles("test")
|
||||||
|
public final class ArticleReaderTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ArticleReader articleReader;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void name() {
|
||||||
|
List<Long> idx = articleReader.findAll(0, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user