Skip to content

Commit 6ba4531

Browse files
authored
[25.03.16 / TASK-146] Refactor - post service (#23)
* hotfix: 날짜 조회 SQL 쿼리의 치명적인 이슈 핸들링 * feature: 실제 DBMS 와 연결해서 진짜 쿼리를 던지는 통합 테스팅 실시 * feature: 통합 테스트 코드 업데이트 완료 * feature: readme 에 상세 내용 추가 * modify: service 로직 테스트 코드 강화
1 parent 4312528 commit 6ba4531

File tree

12 files changed

+1052
-309
lines changed

12 files changed

+1052
-309
lines changed

.github/workflows/test-ci.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
node-version: [20, 21, 22, 23]
16-
fail-fast: false # 한 버전 실패 시 전체 중단 방지
16+
fail-fast: false # 한 버전 실패 시 전체 중단 방지
1717

1818
steps:
1919
- name: Checkout repository
@@ -50,11 +50,19 @@ jobs:
5050
- name: Install dependencies
5151
run: pnpm install --frozen-lockfile
5252

53+
- name: Create .env file
54+
run: |
55+
echo "DATABASE_NAME=${{ secrets.DATABASE_NAME }}" >> .env
56+
echo "POSTGRES_USER=${{ secrets.POSTGRES_USER }}" >> .env
57+
echo "POSTGRES_HOST=${{ secrets.POSTGRES_HOST }}" >> .env
58+
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> .env
59+
echo "POSTGRES_PORT=${{ secrets.POSTGRES_PORT }}" >> .env
60+
5361
- name: Run lint
5462
run: pnpm run lint
5563

5664
- name: Run tests
5765
run: pnpm run test
5866

5967
- name: Run build
60-
run: pnpm run build
68+
run: pnpm run build

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Velog Dashboard Project
22

33
- Velog dashboard V2 백엔드, API 서버
4-
- ***`node 20+`***
4+
- **_`node 20+`_**
55

66
## Project Setup Guide
77

@@ -30,6 +30,12 @@ cp .env.sample .env
3030
pnpm dev
3131
```
3232

33+
4. 로컬 테스팅을 위해서 `post.repo.integration.test` 를 필수 참조해주세요.
34+
35+
- 해당 테스트는 mocking 없이 DBMS connection 을 맺고 repo 계층의 실제 수행을 테스트 합니다.
36+
- 이에 따라, local DBMS 와 connection 을 맺는다면 **_테스트로 제공해야 할 TEST CASE 의 값들이 달라져야 합니다._**
37+
- 이 때문에 전체 테스트에 이슈가 있을 수 있으니 해당 값 꼭 체크 해주세요.
38+
3339
## 실행 가능한 명령어
3440

3541
```bash
@@ -46,17 +52,17 @@ pnpm start # 빌드된 프로젝트 시작
4652

4753
```bash
4854
├── src/
49-
├── __test__/ # 테스트 파일
50-
├── configs/ # 설정 파일 (DB 등)
51-
├── constants/ # 상수 데이터 파일
52-
├── controllers/ # API 컨트롤러
53-
├── exception/ # 커스텀 에러 파일
54-
├── middlewares/ # 각종 미들웨어 (인증, 에러, 데이터 검증 등)
55-
├── modules/ # 모듈 파일 (슬랙 등)
56-
├── repositories/ # 데이터 액세스 레이어
57-
├── routers/ # API 라우트 정의
58-
├── services/ # 비즈니스 로직
59-
├┬── types/ # Enum, DTO 등 데이터 타입 정의
60-
── models/ # 데이터 모델
61-
└── utils/ # 편의성 함수 정의
55+
│   ├── __test__/ # 테스트 파일
56+
│   ├── configs/ # 설정 파일 (DB 등)
57+
│   ├── constants/ # 상수 데이터 파일
58+
│   ├── controllers/ # API 컨트롤러
59+
│   ├── exception/ # 커스텀 에러 파일
60+
│   ├── middlewares/ # 각종 미들웨어 (인증, 에러, 데이터 검증 등)
61+
│   ├── modules/ # 모듈 파일 (슬랙 등)
62+
│   ├── repositories/ # 데이터 액세스 레이어
63+
│   ├── routers/ # API 라우트 정의
64+
│   ├── services/ # 비즈니스 로직
65+
│   ├── types/ # Enum, DTO 등 데이터 타입 정의
66+
   │   ├── models/ # 데이터 모델
67+
│   └── utils/ # 편의성 함수 정의
6268
```

src/controllers/post.controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
export class PostController {
1414
constructor(private postService: PostService) {}
1515

16-
getAllPost: RequestHandler = async (
16+
getAllPosts: RequestHandler = async (
1717
req: Request<object, object, object, GetAllPostsQuery>,
1818
res: Response<PostsResponseDto>,
1919
next: NextFunction,
@@ -38,15 +38,15 @@ export class PostController {
3838
}
3939
};
4040

41-
getAllPostStatistics: RequestHandler = async (
41+
getAllPostsStatistics: RequestHandler = async (
4242
req: Request,
4343
res: Response<PostStatisticsResponseDto>,
4444
next: NextFunction,
4545
) => {
4646
try {
4747
const { id } = req.user;
4848

49-
const stats = await this.postService.getAllPostStatistics(id);
49+
const stats = await this.postService.getAllPostsStatistics(id);
5050
const totalPostCount = await this.postService.getTotalPostCounts(id);
5151

5252
const response = new PostStatisticsResponseDto(

0 commit comments

Comments
 (0)