Skip to content

Commit

Permalink
categoryMapper bug update
Browse files Browse the repository at this point in the history
  • Loading branch information
mingming-01 committed Dec 10, 2024
1 parent ce19a9c commit 3e3890c
Showing 1 changed file with 15 additions and 110 deletions.
125 changes: 15 additions & 110 deletions stockMate/src/main/resources/mappers/categoryMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<result property="updatedAt" column="updated_at" />
<result property="isDeleted" column="is_deleted" />
</resultMap>

<!-- 카테고리 등록 -->
<insert id="insertCategory" parameterType="com.stockm8.domain.vo.CategoryVO">
INSERT INTO test_categories (
Expand All @@ -39,7 +39,6 @@
)
</insert>


<!-- 카테고리 목록 조회 -->
<select id="selectAllCategories" resultMap="categoryResultMap">
SELECT
Expand All @@ -57,7 +56,7 @@
</select>

<!-- 특정 사업자 소속의 카테고리 목록 조회 -->
<select id="selectCategoriesByBusinessId" parameterType="int" resultMap="categoryResultMap">
<select id="selectCategoriesById" parameterType="int" resultMap="categoryResultMap">
SELECT
category_id,
parent_id,
Expand All @@ -73,8 +72,15 @@
ORDER BY level ASC, category_name ASC
</select>

<!-- 카테고리ID로 카테고리명 조회 -->
<select id="selectCategoryNameById" parameterType="int" resultType="String">
SELECT category_name
FROM test_categories
WHERE category_id = #{categoryId}
</select>

<!-- 카테고리 존재 여부 확인 -->
<select id="existsById" parameterType="map" resultType="Boolean">
<select id="existsById" parameterType="map" resultType="int">
SELECT COUNT(*)
FROM test_categories
WHERE category_id = #{categoryId}
Expand All @@ -87,7 +93,8 @@
SET
parent_id = #{parentId},
category_name = #{categoryName},
level = #{level}
level = #{level},
updated_at = NOW()
WHERE category_id = #{categoryId}
</update>

Expand All @@ -97,86 +104,8 @@
WHERE category_id = #{categoryId}
</delete>

<!-- 카테고리 등록 -->
<insert id="insertCategory"
parameterType="com.stockm8.domain.vo.CategoryVO">
insert into categories (parentId, businessId,
categoryName, level,
createdAt)
values (#{parentId}, #{businessId},
#{categoryName}, #{level},
#{createdAt})
</insert>

<!-- 카테고리 목록 조회 -->
<select id="selectAllCategories" resultMap="categoryResultMap">
SELECT
category_id,
parent_id,
business_id,
category_name,
level,
created_at,
updated_at,
is_deleted
FROM test_categories
WHERE is_deleted = 0
ORDER BY level ASC, category_name ASC
</select>

<!-- 특정 사업자(businessId) 소속의 카테고리 목록을 조회 -->
<select id="selectCategoriesByBusinessId" parameterType="int"
resultMap="categoryResultMap">
SELECT
category_id,
parent_id,
business_id,
category_name,
level,
created_at,
updated_at,
is_deleted
FROM
test_categories
WHERE
business_id = #{businessId}
AND is_deleted = 0
ORDER BY
level ASC,
category_name ASC
</select>

<!-- 카테고리ID로 카테고리명 조회 -->
<select id="selectCategoryNameById" resultType="String" parameterType="int">
SELECT category_name
FROM test_categories
WHERE category_id = #{categoryId}
</select>

<!-- existsById 쿼리 -->
<select id="existsById" parameterType="map" resultType="int">
SELECT
EXISTS(
SELECT 1
FROM test_categories
WHERE category_id = #{categoryId}
AND business_id = #{businessId}
)
</select>

<!-- 카테고리 수정 -->
<update id="updateCategory"
parameterType="com.stockm8.domain.vo.CategoryVO">
update test_categories
set parent_id = #{parentId},
category_name = #{categoryName}, level =
#{level}
where category_id =
#{categoryId}
</update>

<!-- 상위 카테고리 조회 -->
<select id="selectParentCategories" resultMap="categoryResultMap">
<!-- 카테고리 ID로 조회 -->
<select id="selectCategoryById" parameterType="int" resultMap="categoryResultMap">
SELECT
category_id,
parent_id,
Expand All @@ -187,31 +116,7 @@
updated_at,
is_deleted
FROM test_categories
WHERE parent_id IS NULL
AND is_deleted = 0
</select>

<!-- 카테고리와 부모 카테고리 조회 -->
<select id="selectCategoryWithParents" resultMap="categoryResultMap">
SELECT
c.category_id,
c.parent_id,
c.business_id,
c.category_name,
c.level,
c.created_at,
c.updated_at,
c.is_deleted,
p.category_name AS parentCategoryName
FROM test_categories c
LEFT JOIN test_categories p ON c.parent_id = p.category_id
WHERE c.category_id = #{categoryId}
WHERE category_id = #{categoryId}
</select>

<select id="selectCategoryById" parameterType="int" resultType="com.stockm8.domain.vo.CategoryVO">
SELECT * FROM test_categories WHERE category_id = #{categoryId}
</select>



</mapper>

0 comments on commit 3e3890c

Please sign in to comment.