refactor query mappers
This commit is contained in:
parent
4550e5a3c5
commit
8e7ec76774
@ -2,11 +2,10 @@ package io.spring.application;
|
||||
|
||||
import io.spring.application.data.ArticleData;
|
||||
import io.spring.application.data.ArticleDataList;
|
||||
import io.spring.infrastructure.mybatis.readservice.UserRelationshipQueryService;
|
||||
import io.spring.core.user.User;
|
||||
import io.spring.infrastructure.mybatis.readservice.ArticleReadService;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import io.spring.infrastructure.mybatis.readservice.UserRelationshipQueryService;
|
||||
import lombok.Value;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -130,9 +129,8 @@ public class ArticleQueryService {
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Value
|
||||
class ArticleFavoriteCount {
|
||||
private String id;
|
||||
private int count;
|
||||
private Integer count;
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
<select id="articleFavoriteCount" resultType="java.lang.Integer">
|
||||
select count(1) from article_favorites where article_id = #{articleId}
|
||||
</select>
|
||||
<select id="articlesFavoriteCount" resultMap="favoriteCount">
|
||||
<select id="articlesFavoriteCount" resultMap="transfer.data.favoriteCount">
|
||||
select A.id, count(AF.user_id) as favoriteCount from articles A
|
||||
left join article_favorites AF on A.id = AF.article_id
|
||||
where id in
|
||||
@ -27,10 +27,4 @@
|
||||
</foreach>
|
||||
and AF.user_id = #{currentUser.id}
|
||||
</select>
|
||||
|
||||
<resultMap id="favoriteCount" type="io.spring.application.ArticleFavoriteCount">
|
||||
<id column="id" property="id"/>
|
||||
<result column="favoriteCount" property="count"/>
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
@ -25,11 +25,11 @@
|
||||
left join users U on U.id = A.user_id
|
||||
</sql>
|
||||
|
||||
<select id="findById" resultMap="articleData">
|
||||
<select id="findById" resultMap="transfer.data.articleData">
|
||||
<include refid="selectArticleData"/>
|
||||
where A.id = #{id}
|
||||
</select>
|
||||
<select id="findBySlug" resultMap="articleData">
|
||||
<select id="findBySlug" resultMap="transfer.data.articleData">
|
||||
<include refid="selectArticleData"/>
|
||||
where A.slug = #{slug}
|
||||
</select>
|
||||
@ -79,7 +79,7 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="findArticles" resultMap="articleData">
|
||||
<select id="findArticles" resultMap="transfer.data.articleData">
|
||||
<include refid="selectArticleData"/>
|
||||
where A.id in
|
||||
<foreach index="index" collection="articleIds" item="id" open="(" separator="," close=")">
|
||||
@ -87,7 +87,7 @@
|
||||
</foreach>
|
||||
order by A.created_at desc
|
||||
</select>
|
||||
<select id="findArticlesOfAuthors" resultMap="articleData">
|
||||
<select id="findArticlesOfAuthors" resultMap="transfer.data.articleData">
|
||||
<include refid="selectArticleData"/>
|
||||
where A.user_id in
|
||||
<foreach index="index" collection="authors" item="id" open="(" separator="," close=")">
|
||||
@ -105,25 +105,4 @@
|
||||
<resultMap id="articleId" type="string">
|
||||
<id javaType="string" column="articleId"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="articleData" type="io.spring.application.data.ArticleData">
|
||||
<id column="articleId" property="id"/>
|
||||
<result column="articleSlug" property="slug"/>
|
||||
<result column="articleTitle" property="title"/>
|
||||
<result column="articleDescription" property="description"/>
|
||||
<result column="articleBody" property="body"/>
|
||||
<result column="articleCreatedAt" property="createdAt"/>
|
||||
<result column="articleUpdatedAt" property="updatedAt"/>
|
||||
<association property="profileData" resultMap="profileData"/>
|
||||
<collection property="tagList" javaType="list" ofType="string">
|
||||
<result column="tagName"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="profileData" type="io.spring.application.data.ProfileData">
|
||||
<id column="userId" property="id"/>
|
||||
<result column="userUsername" property="username"/>
|
||||
<result column="userBio" property="bio"/>
|
||||
<result column="userImage" property="image"/>
|
||||
</resultMap>
|
||||
</mapper>
|
@ -12,20 +12,12 @@
|
||||
on C.user_id = U.id
|
||||
</sql>
|
||||
|
||||
<select id="findById" resultMap="commentData">
|
||||
<select id="findById" resultMap="transfer.data.commentData">
|
||||
<include refid="selectCommentData"/>
|
||||
where C.id = #{id}
|
||||
</select>
|
||||
<select id="findByArticleId" resultMap="commentData">
|
||||
<select id="findByArticleId" resultMap="transfer.data.commentData">
|
||||
<include refid="selectCommentData"/>
|
||||
where C.article_id = #{articleId}
|
||||
</select>
|
||||
|
||||
<resultMap id="commentData" type="io.spring.application.data.CommentData">
|
||||
<id column="commentId" property="id"/>
|
||||
<result column="commentBody" property="body"/>
|
||||
<result column="commentCreatedAt" property="createdAt"/>
|
||||
<result column="commentCreatedAt" property="updatedAt"/>
|
||||
<association property="profileData" resultMap="io.spring.infrastructure.mybatis.readservice.ArticleReadService.profileData"/>
|
||||
</resultMap>
|
||||
</mapper>
|
39
src/main/resources/mapper/TransferData.xml
Normal file
39
src/main/resources/mapper/TransferData.xml
Normal file
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="transfer.data">
|
||||
<resultMap id="favoriteCount" type="io.spring.application.ArticleFavoriteCount">
|
||||
<constructor>
|
||||
<idArg column="id" javaType="string"/>
|
||||
<arg column="favoriteCount" javaType="integer"/>
|
||||
</constructor>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="profileData" type="io.spring.application.data.ProfileData">
|
||||
<id column="userId" property="id"/>
|
||||
<result column="userUsername" property="username"/>
|
||||
<result column="userBio" property="bio"/>
|
||||
<result column="userImage" property="image"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="articleData" type="io.spring.application.data.ArticleData">
|
||||
<id column="articleId" property="id"/>
|
||||
<result column="articleSlug" property="slug"/>
|
||||
<result column="articleTitle" property="title"/>
|
||||
<result column="articleDescription" property="description"/>
|
||||
<result column="articleBody" property="body"/>
|
||||
<result column="articleCreatedAt" property="createdAt"/>
|
||||
<result column="articleUpdatedAt" property="updatedAt"/>
|
||||
<association property="profileData" resultMap="transfer.data.profileData"/>
|
||||
<collection property="tagList" javaType="list" ofType="string">
|
||||
<result column="tagName"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="commentData" type="io.spring.application.data.CommentData">
|
||||
<id column="commentId" property="id"/>
|
||||
<result column="commentBody" property="body"/>
|
||||
<result column="commentCreatedAt" property="createdAt"/>
|
||||
<result column="commentCreatedAt" property="updatedAt"/>
|
||||
<association property="profileData" resultMap="profileData"/>
|
||||
</resultMap>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user