-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76ef3f4
commit 4e2d561
Showing
8 changed files
with
120 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
backend/src/main/resources/db/migration/V10__category_column_denormalization.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ALTER TABLE category ADD COLUMN template_count BIGINT DEFAULT 0; | ||
|
||
UPDATE category c | ||
SET template_count = ( | ||
SELECT COUNT(1) | ||
FROM template t | ||
WHERE t.category_id = c.id | ||
); |
8 changes: 8 additions & 0 deletions
8
backend/src/main/resources/db/migration/V14__category_column_denormalization.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ALTER TABLE category ADD COLUMN template_count BIGINT DEFAULT 0; | ||
|
||
UPDATE category c | ||
SET template_count = ( | ||
SELECT COUNT(1) | ||
FROM template t | ||
WHERE t.category_id = c.id | ||
); |
56 changes: 56 additions & 0 deletions
56
backend/src/test/java/codezap/category/domain/CategoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package codezap.category.domain; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import codezap.fixture.CategoryFixture; | ||
import codezap.fixture.MemberFixture; | ||
import codezap.member.domain.Member; | ||
|
||
public class CategoryTest { | ||
|
||
@Nested | ||
@DisplayName("템플릿 개수 증가 성공") | ||
class IncreaseTemplateCount { | ||
|
||
@Test | ||
@DisplayName("템플릿 개수 증가 성공") | ||
void increaseTemplateCountSuccess() { | ||
Category category = CategoryFixture.getDefaultCategory(MemberFixture.getFirstMember()); | ||
|
||
category.increaseTemplateCount(); | ||
|
||
assertThat(category.getTemplateCount()).isEqualTo(1); | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("템플릿 개수 감소 성공") | ||
class DecreaseTemplateCount { | ||
|
||
@Test | ||
@DisplayName("템플릿 개수 감소 성공") | ||
void decreaseTemplateCountSuccess() { | ||
Category category = CategoryFixture.getDefaultCategory(MemberFixture.getFirstMember()); | ||
|
||
category.increaseTemplateCount(); | ||
category.increaseTemplateCount(); | ||
category.decreaseTemplateCount(); | ||
|
||
assertThat(category.getTemplateCount()).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
@DisplayName("템플릿 개수 감소 성공: 이미 0개인 경우에도 성공") | ||
void decreaseTemplateCountSuccessAlreadyZero() { | ||
Category category = CategoryFixture.getDefaultCategory(MemberFixture.getFirstMember()); | ||
|
||
category.decreaseTemplateCount(); | ||
|
||
assertThat(category.getTemplateCount()).isEqualTo(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule private
updated
from f0781c to 520cb3