Skip to content

Commit 97d10bb

Browse files
authored
refactor/#182 about 엔티티 단순화 (#188)
* refactor: detailCategory 삭제 * refactor: 추가 수정 * refactor: 일단 저장 * refactor: 비즈니스 로직 수정 * refactor: db 스키마 수정 * refactor: 더미데이터 내용 수정 * refactor: about testcode 수정 * refactor: testcode 수정 * refactor: ddl auto 수정 * refactor: category 제약조건 추가 * refactor: domain test code 수정 * Delete .DS_Store * refactor: 코멘트 적용 * Update AboutCreateRequest.java * refactor: description 제거 * refactor: club category 제거 * refactor: testcode 수정 * refactor: getAbout 메소드 이름 수정 * Update AboutControllerImpl.java
1 parent 684c459 commit 97d10bb

File tree

22 files changed

+100
-368
lines changed

22 files changed

+100
-368
lines changed

aics-admin/src/main/java/kgu/developers/admin/about/application/AboutAdminFacade.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class AboutAdminFacade {
1616
private final AboutCommandService aboutCommandService;
1717

1818
public AboutPersistResponse createAbout(AboutCreateRequest request) {
19-
Long id = aboutCommandService.createAbout(request.main(), request.sub(), request.detail(), request.content());
19+
Long id = aboutCommandService.createAbout(request.category(), request.content());
2020
return AboutPersistResponse.of(id);
2121
}
2222

aics-admin/src/main/java/kgu/developers/admin/about/presentation/request/AboutCreateRequest.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
package kgu.developers.admin.about.presentation.request;
22

3-
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED;
43
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
54

65
import io.swagger.v3.oas.annotations.media.Schema;
76
import jakarta.validation.constraints.NotNull;
8-
import kgu.developers.domain.about.domain.MainCategory;
9-
import kgu.developers.domain.about.domain.SubCategory;
7+
import kgu.developers.domain.about.domain.Category;
108
import lombok.Builder;
119

1210
@Builder
1311
public record AboutCreateRequest(
14-
@Schema(description = "메인 카테고리", example = "EDU_ACTIVITIES", requiredMode = REQUIRED)
12+
@Schema(description = "카테고리", example = "DEPT_INTRO", requiredMode = REQUIRED)
1513
@NotNull
16-
MainCategory main,
17-
18-
@Schema(description = "보조 카테고리", example = "CURRICULUM", requiredMode = REQUIRED)
19-
@NotNull
20-
SubCategory sub,
21-
22-
@Schema(description = "세부 카테고리", example = "2019", requiredMode = NOT_REQUIRED)
23-
String detail,
14+
Category category,
2415

2516
@Schema(description = "페이지 내용(JSON 형식)", example = "{key:value}", requiredMode = REQUIRED)
2617
@NotNull

aics-admin/src/testFixtures/java/about/application/AboutAdminFacadeTest.java

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package about.application;
22

3-
import static kgu.developers.domain.about.domain.MainCategory.DEPT_INTRO;
4-
import static kgu.developers.domain.about.domain.MainCategory.EDU_ACTIVITIES;
5-
import static kgu.developers.domain.about.domain.SubCategory.CURRICULUM;
6-
import static kgu.developers.domain.about.domain.SubCategory.HISTORY;
3+
import static kgu.developers.domain.about.domain.Category.DEPT_INTRO;
74
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
85
import static org.junit.jupiter.api.Assertions.assertEquals;
96

@@ -17,10 +14,8 @@
1714
import kgu.developers.admin.about.presentation.response.AboutPersistResponse;
1815
import kgu.developers.domain.about.application.command.AboutCommandService;
1916
import kgu.developers.domain.about.domain.About;
20-
import kgu.developers.domain.about.domain.MainCategory;
21-
import kgu.developers.domain.about.domain.SubCategory;
17+
import kgu.developers.domain.about.domain.Category;
2218
import kgu.developers.domain.about.exception.AboutNotFoundException;
23-
import kgu.developers.domain.about.exception.CategoryNotMatchException;
2419
import mock.repository.FakeAboutRepository;
2520

2621
public class AboutAdminFacadeTest {
@@ -35,26 +30,20 @@ public void init() {
3530
);
3631

3732
fakeAboutRepository.save(About.builder()
38-
.mainCategory(EDU_ACTIVITIES)
39-
.subCategory(CURRICULUM)
40-
.detailCategory("initDetail")
41-
.content("initContent")
33+
.category(DEPT_INTRO)
34+
.content("content")
4235
.build());
4336
}
4437

4538
@Test
4639
@DisplayName("createAbout은 about을 생성한다")
4740
public void createAbout_Success() {
4841
// given
49-
MainCategory main = DEPT_INTRO;
50-
SubCategory sub = HISTORY;
51-
String detail = "detail";
42+
Category category = DEPT_INTRO;
5243
String content = "content";
5344

5445
AboutCreateRequest request = AboutCreateRequest.builder()
55-
.main(main)
56-
.sub(sub)
57-
.detail(detail)
46+
.category(category)
5847
.content(content)
5948
.build();
6049

@@ -65,28 +54,6 @@ public void createAbout_Success() {
6554
assertEquals(2L, result.id());
6655
}
6756

68-
@Test
69-
@DisplayName("createAbout은 메인 카테고리와 서브 카테고리의 관계가 올바르지 않은 생성 요청 시 CategoryNotMatchException을 발생시킨다")
70-
public void createAbout_CategoryNotMatch_ThrowsException() {
71-
// given
72-
MainCategory main = DEPT_INTRO;
73-
SubCategory sub = CURRICULUM;
74-
String detail = "detail";
75-
String content = "content";
76-
77-
AboutCreateRequest request = AboutCreateRequest.builder()
78-
.main(main)
79-
.sub(sub)
80-
.detail(detail)
81-
.content(content)
82-
.build();
83-
84-
// when
85-
// then
86-
assertThatThrownBy(() -> aboutAdminFacade.createAbout(request))
87-
.isInstanceOf(CategoryNotMatchException.class);
88-
}
89-
9057
@Test
9158
@DisplayName("updateAbout은 About의 content를 수정한다")
9259
public void updateAbout_Success() {

aics-api/src/main/java/kgu/developers/api/about/application/AboutFacade.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import kgu.developers.api.about.presentation.response.AboutResponse;
77
import kgu.developers.domain.about.application.query.AboutQueryService;
88
import kgu.developers.domain.about.domain.About;
9-
import kgu.developers.domain.about.domain.MainCategory;
10-
import kgu.developers.domain.about.domain.SubCategory;
9+
import kgu.developers.domain.about.domain.Category;
1110
import lombok.RequiredArgsConstructor;
1211

1312
@Component
@@ -16,8 +15,8 @@
1615
public class AboutFacade {
1716
private final AboutQueryService aboutQueryService;
1817

19-
public AboutResponse getAbout(MainCategory main, SubCategory sub, String detail) {
20-
About about = aboutQueryService.getAbout(main, sub, detail);
18+
public AboutResponse getAboutByCategory(Category category) {
19+
About about = aboutQueryService.getAboutByCategory(category);
2120
return AboutResponse.from(about);
2221
}
2322
}

aics-api/src/main/java/kgu/developers/api/about/presentation/AboutController.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import io.swagger.v3.oas.annotations.responses.ApiResponse;
1111
import io.swagger.v3.oas.annotations.tags.Tag;
1212
import kgu.developers.api.about.presentation.response.AboutResponse;
13-
import kgu.developers.domain.about.domain.MainCategory;
14-
import kgu.developers.domain.about.domain.SubCategory;
13+
import kgu.developers.domain.about.domain.Category;
1514

1615
@Tag(name = "About", description = "소개글 API")
1716
public interface AboutController {
@@ -25,18 +24,9 @@ public interface AboutController {
2524
content = @Content(schema = @Schema(implementation = AboutResponse.class)))
2625
ResponseEntity<AboutResponse> getAbout(
2726
@Parameter(
28-
description = "메인 카테고리 ENUM 타입 입니다.",
29-
example = "EDU_ACTIVITIES",
27+
description = "카테고리 ENUM 타입 입니다.",
28+
example = "DEPT_INTRO",
3029
required = true
31-
) @RequestParam(name = "main") MainCategory main,
32-
@Parameter(
33-
description = "보조 카테고리 ENUM 타입 입니다.",
34-
example = "CURRICULUM",
35-
required = true
36-
) @RequestParam(name = "sub") SubCategory sub,
37-
@Parameter(
38-
description = "세부 카테고리 입니다.",
39-
example = "2019"
40-
) @RequestParam(name = "detail", required = false) String detail
30+
) @RequestParam(name = "category") Category category
4131
);
4232
}

aics-api/src/main/java/kgu/developers/api/about/presentation/AboutControllerImpl.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,21 @@
88

99
import kgu.developers.api.about.application.AboutFacade;
1010
import kgu.developers.api.about.presentation.response.AboutResponse;
11-
import kgu.developers.domain.about.domain.MainCategory;
12-
import kgu.developers.domain.about.domain.SubCategory;
11+
import kgu.developers.domain.about.domain.Category;
1312
import lombok.RequiredArgsConstructor;
1413

1514
@RestController
1615
@RequiredArgsConstructor
1716
@RequestMapping("/api/v1/abouts")
18-
public class AboutControllerImpl implements AboutController{
17+
public class AboutControllerImpl implements AboutController {
1918
private final AboutFacade aboutFacade;
2019

2120
@Override
2221
@GetMapping
2322
public ResponseEntity<AboutResponse> getAbout(
24-
@RequestParam(name = "main") MainCategory main,
25-
@RequestParam(name = "sub") SubCategory sub,
26-
@RequestParam(name = "detail", required = false) String detail
23+
@RequestParam Category category
2724
) {
28-
AboutResponse response = aboutFacade.getAbout(main, sub, detail);
25+
AboutResponse response = aboutFacade.getAboutByCategory(category);
2926
return ResponseEntity.ok(response);
3027
}
3128
}

aics-api/src/main/java/kgu/developers/api/about/presentation/response/AboutResponse.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88

99
@Builder
1010
public record AboutResponse(
11-
@Schema(description = "소개글 id", example = "1", requiredMode = REQUIRED)
12-
Long id,
13-
14-
@Schema(description = "페이지 내용(JSON 형식)", example = "{key:value}", requiredMode = Schema.RequiredMode.REQUIRED)
11+
@Schema(description = "페이지 내용(JSON 형식)", example = "{key:value}", requiredMode = REQUIRED)
1512
String content
1613
) {
1714
public static AboutResponse from(About about) {
1815
return AboutResponse.builder()
19-
.id(about.getId())
2016
.content(about.getContent())
2117
.build();
2218
}

aics-api/src/main/resources/db/data.sql

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
-- about
2-
INSERT INTO about (content, detail_category, main_category, sub_category, created_at, updated_at)
3-
VALUES ('학과 소개 내용입니다.', NULL, 'DEPT_INTRO', 'DEPT_INTRO', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
4-
('커리큘럼 설명입니다.', '2019', 'EDU_ACTIVITIES', 'CURRICULUM', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
5-
('연혁 더미데이터입니다.', NULL, 'DEPT_INTRO', 'HISTORY', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
6-
('연구 활동 소개입니다.', NULL, 'EDU_ACTIVITIES', 'LEARNING_ACTIVITIES', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
7-
('학생 지원 서비스 안내입니다.', NULL, 'DEPT_INTRO', 'DEPT_INTRO', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
8-
('졸업 요건 설명입니다.', NULL, 'DEPT_INTRO', 'CURRICULUM', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
9-
('학과 소식지 발행 안내입니다.', NULL, 'DEPT_INTRO', 'DEPT_INTRO', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
2+
INSERT INTO about (content, category, description, created_at, updated_at)
3+
VALUES ('학과 소개 내용입니다.', 'DEPT_INTRO', "경기대학교 AI컴퓨터공학부를 소개해요.", CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
4+
('경기대학교 수원캠퍼스 8강의동에 있습니다.', 'DIRECTIONS', "경기대학교 AI컴퓨터공학부에 찾아오시는 길을 알려드려요.", CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
5+
('이런 저런 동아리가 있습니다.', 'CLUB', "경기대학교 AI컴퓨터공학부에 어떤 동아리가 있는지 알려드려요.", CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
106

117
-- club
128
INSERT INTO club (name, description, site, created_at, updated_at)

aics-api/src/main/resources/db/schema.sql

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ CREATE TABLE about
77
updated_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
88
deleted_at TIMESTAMP(6) DEFAULT NULL,
99
content TEXT NOT NULL,
10-
detail_category VARCHAR(100),
11-
main_category VARCHAR(50) NOT NULL
12-
CONSTRAINT about_main_category_check
13-
CHECK ((main_category)::TEXT = ANY (ARRAY ['DEPT_INTRO', 'EDU_ACTIVITIES'])),
14-
sub_category VARCHAR(50) NOT NULL
15-
CONSTRAINT about_sub_category_check
16-
CHECK ((sub_category)::TEXT = ANY
17-
(ARRAY ['DEPT_INTRO', 'HISTORY', 'EDU_ENVIRONMENT', 'EDU_OBJECTIVES', 'CURRICULUM', 'LEARNING_ACTIVITIES', 'CLUB_INTRO']))
10+
description VARCHAR(100),
11+
category VARCHAR(50) NOT NULL UNIQUE
12+
CONSTRAINT about_category_check
13+
CHECK ((category)::TEXT = ANY (ARRAY ['DEPT_INTRO', 'DIRECTIONS', 'CLUB']))
1814
);
1915

2016
-- club
Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package about.application;
22

3-
import static kgu.developers.domain.about.domain.MainCategory.DEPT_INTRO;
4-
import static kgu.developers.domain.about.domain.MainCategory.EDU_ACTIVITIES;
5-
import static kgu.developers.domain.about.domain.SubCategory.CURRICULUM;
6-
import static kgu.developers.domain.about.domain.SubCategory.HISTORY;
3+
import static kgu.developers.domain.about.domain.Category.DEPT_INTRO;
4+
import static kgu.developers.domain.about.domain.Category.DIRECTIONS;
75
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
86
import static org.junit.jupiter.api.Assertions.assertEquals;
97

@@ -15,10 +13,8 @@
1513
import kgu.developers.api.about.presentation.response.AboutResponse;
1614
import kgu.developers.domain.about.application.query.AboutQueryService;
1715
import kgu.developers.domain.about.domain.About;
18-
import kgu.developers.domain.about.domain.MainCategory;
19-
import kgu.developers.domain.about.domain.SubCategory;
16+
import kgu.developers.domain.about.domain.Category;
2017
import kgu.developers.domain.about.exception.AboutNotFoundException;
21-
import kgu.developers.domain.about.exception.CategoryNotMatchException;
2218
import mock.repository.FakeAboutRepository;
2319

2420
public class AboutFacadeTest {
@@ -32,56 +28,33 @@ public void init() {
3228
);
3329

3430
fakeAboutRepository.save(About.builder()
35-
.mainCategory(EDU_ACTIVITIES)
36-
.subCategory(CURRICULUM)
37-
.detailCategory("initDetail")
38-
.content("initContent")
31+
.category(DEPT_INTRO)
32+
.content("content")
3933
.build());
4034
}
4135

4236
@Test
43-
@DisplayName("getAbout은 About을 조회한다")
44-
public void getAbout_Success() {
37+
@DisplayName("getAboutByCategory은 About을 조회한다")
38+
public void getAboutByCategory() {
4539
// given
46-
MainCategory main = EDU_ACTIVITIES;
47-
SubCategory sub = CURRICULUM;
48-
String detail = "initDetail";
40+
Category category = DEPT_INTRO;
4941

5042
// when
51-
AboutResponse aboutResponse = aboutFacade.getAbout(main, sub, detail);
43+
AboutResponse aboutResponse = aboutFacade.getAboutByCategory(category);
5244

5345
// then
54-
assertEquals("initContent", aboutResponse.content());
55-
}
56-
57-
@Test
58-
@DisplayName("getAbout은 메인 카테고리와 서브 카테고리의 관계가 올바르지 않을 시 CategoryNotMatchException을 발생시킨다")
59-
public void getAbout_CategoryNotMatch_ThrowsException() {
60-
// given
61-
MainCategory main = DEPT_INTRO;
62-
SubCategory sub = CURRICULUM;
63-
String detail = "failDetail";
64-
65-
// when
66-
// then
67-
assertThatThrownBy(() -> aboutFacade.getAbout(main, sub, detail))
68-
.isInstanceOf(CategoryNotMatchException.class);
46+
assertEquals("content", aboutResponse.content());
6947
}
7048

7149
@Test
7250
@DisplayName("getAbout은 존재하지 않는 카테고리로 조회 시 AboutNotFoundException을 발생시킨다")
7351
public void getAbout_AboutNotFound_ThrowsException() {
7452
// given
75-
MainCategory main = DEPT_INTRO;
76-
SubCategory sub = HISTORY;
77-
String detail = "failDetail";
53+
Category category = DIRECTIONS;
7854

7955
// when
8056
// then
81-
assertThatThrownBy(() -> aboutFacade.getAbout(main, sub, null))
82-
.isInstanceOf(AboutNotFoundException.class);
83-
84-
assertThatThrownBy(() -> aboutFacade.getAbout(main, sub, detail))
57+
assertThatThrownBy(() -> aboutFacade.getAboutByCategory(category))
8558
.isInstanceOf(AboutNotFoundException.class);
8659
}
8760
}

0 commit comments

Comments
 (0)