Skip to content

Commit 3d5c822

Browse files
sukangpunchclaude
andcommitted
feat: 게시글 카테고리에 동행, 중고거래 추가
- PostCategory enum에 동행, 중고거래 추가 - post 테이블 category ENUM 컬럼 마이그레이션 (V52) - 신규 카테고리 게시글 생성 및 카테고리별 조회 필터링 테스트 추가 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent bf0b7b2 commit 3d5c822

4 files changed

Lines changed: 71 additions & 1 deletion

File tree

src/main/java/com/example/solidconnection/community/post/domain/PostCategory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.stream.Collectors;
66

77
public enum PostCategory {
8-
전체, 자유, 질문;
8+
전체, 자유, 질문, 동행, 중고거래;
99

1010
private static final Set<String> NAMES = Arrays.stream(values())
1111
.map(Enum::name)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE post
2+
MODIFY COLUMN category ENUM ('자유', '전체', '질문', '동행', '중고거래') NULL;

src/test/java/com/example/solidconnection/community/post/service/PostCommandServiceTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.junit.jupiter.api.DisplayName;
3939
import org.junit.jupiter.api.Nested;
4040
import org.junit.jupiter.api.Test;
41+
import org.junit.jupiter.params.ParameterizedTest;
42+
import org.junit.jupiter.params.provider.ValueSource;
4143
import org.springframework.beans.factory.annotation.Autowired;
4244
import org.springframework.mock.web.MockMultipartFile;
4345
import org.springframework.test.context.bean.override.mockito.MockitoBean;
@@ -164,6 +166,22 @@ class 게시글_생성_테스트 {
164166
);
165167
}
166168

169+
@ParameterizedTest
170+
@ValueSource(strings = {"자유", "질문", "동행", "중고거래"})
171+
@Transactional
172+
void 전체를_제외한_카테고리로_게시글을_생성한다(String category) {
173+
// given
174+
PostCreateRequest request = createPostCreateRequest(category);
175+
List<MultipartFile> imageFiles = List.of();
176+
177+
// when
178+
PostCreateResponse response = postCommandService.createPost(user1.getId(), request, imageFiles);
179+
180+
// then
181+
Post savedPost = postRepository.findById(response.id()).orElseThrow();
182+
assertThat(savedPost.getCategory()).isEqualTo(PostCategory.valueOf(category));
183+
}
184+
167185
@Test
168186
void 전체_카테고리로_생성하면_예외가_발생한다() {
169187
// given

src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,56 @@ void setUp() {
135135
);
136136
}
137137

138+
@Test
139+
void 동행_카테고리로_조회시_해당_카테고리의_게시글만_조회한다() {
140+
// given
141+
Post 동행_게시글 = postFixture.게시글(
142+
"동행 제목",
143+
"동행 내용",
144+
false,
145+
PostCategory.동행,
146+
boardFixture.자유게시판(),
147+
user
148+
);
149+
150+
// when
151+
List<PostListResponse> actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAtDesc(
152+
BoardCode.FREE.name(),
153+
PostCategory.동행.name(),
154+
null
155+
);
156+
157+
// then
158+
assertThat(actualResponses)
159+
.extracting(PostListResponse::id)
160+
.containsExactly(동행_게시글.getId());
161+
}
162+
163+
@Test
164+
void 중고거래_카테고리로_조회시_해당_카테고리의_게시글만_조회한다() {
165+
// given
166+
Post 중고거래_게시글 = postFixture.게시글(
167+
"중고거래 제목",
168+
"중고거래 내용",
169+
false,
170+
PostCategory.중고거래,
171+
boardFixture.자유게시판(),
172+
user
173+
);
174+
175+
// when
176+
List<PostListResponse> actualResponses = postQueryService.findPostsByCodeAndPostCategoryOrderByCreatedAtDesc(
177+
BoardCode.FREE.name(),
178+
PostCategory.중고거래.name(),
179+
null
180+
);
181+
182+
// then
183+
assertThat(actualResponses)
184+
.extracting(PostListResponse::id)
185+
.containsExactly(중고거래_게시글.getId());
186+
}
187+
138188
@Test
139189
void 전체_카테고리로_조회시_해당_게시판의_모든_게시글을_조회한다() {
140190
// given

0 commit comments

Comments
 (0)