Skip to content

[25.03.16 / TASK-146] Refactor - post service #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/test-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
node-version: [20, 21, 22, 23]
fail-fast: false # ν•œ 버전 μ‹€νŒ¨ μ‹œ 전체 쀑단 λ°©μ§€
fail-fast: false # ν•œ 버전 μ‹€νŒ¨ μ‹œ 전체 쀑단 λ°©μ§€

steps:
- name: Checkout repository
Expand Down Expand Up @@ -50,11 +50,19 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Create .env file
run: |
echo "DATABASE_NAME=${{ secrets.DATABASE_NAME }}" >> .env
echo "POSTGRES_USER=${{ secrets.POSTGRES_USER }}" >> .env
echo "POSTGRES_HOST=${{ secrets.POSTGRES_HOST }}" >> .env
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> .env
echo "POSTGRES_PORT=${{ secrets.POSTGRES_PORT }}" >> .env

- name: Run lint
run: pnpm run lint

- name: Run tests
run: pnpm run test

- name: Run build
run: pnpm run build
run: pnpm run build
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Velog Dashboard Project

- Velog dashboard V2 λ°±μ—”λ“œ, API μ„œλ²„
- ***`node 20+`***
- **_`node 20+`_**

## Project Setup Guide

Expand Down Expand Up @@ -30,6 +30,12 @@ cp .env.sample .env
pnpm dev
```

4. 둜컬 ν…ŒμŠ€νŒ…μ„ μœ„ν•΄μ„œ `post.repo.integration.test` λ₯Ό ν•„μˆ˜ μ°Έμ‘°ν•΄μ£Όμ„Έμš”.

- ν•΄λ‹Ή ν…ŒμŠ€νŠΈλŠ” mocking 없이 DBMS connection 을 λ§Ίκ³  repo κ³„μΈ΅μ˜ μ‹€μ œ μˆ˜ν–‰μ„ ν…ŒμŠ€νŠΈ ν•©λ‹ˆλ‹€.
- 이에 따라, local DBMS 와 connection 을 λ§ΊλŠ”λ‹€λ©΄ **_ν…ŒμŠ€νŠΈλ‘œ μ œκ³΅ν•΄μ•Ό ν•  TEST CASE 의 값듀이 달라져야 ν•©λ‹ˆλ‹€._**
- 이 λ•Œλ¬Έμ— 전체 ν…ŒμŠ€νŠΈμ— μ΄μŠˆκ°€ μžˆμ„ 수 μžˆμœΌλ‹ˆ ν•΄λ‹Ή κ°’ κΌ­ 체크 ν•΄μ£Όμ„Έμš”.

## μ‹€ν–‰ κ°€λŠ₯ν•œ λͺ…λ Ήμ–΄

```bash
Expand All @@ -46,17 +52,17 @@ pnpm start # λΉŒλ“œλœ ν”„λ‘œμ νŠΈ μ‹œμž‘

```bash
β”œβ”€β”€ src/
β”œβ”€β”€ __test__/ # ν…ŒμŠ€νŠΈ 파일
β”œβ”€β”€ configs/ # μ„€μ • 파일 (DB λ“±)
β”œβ”€β”€ constants/ # μƒμˆ˜ 데이터 파일
β”œβ”€β”€ controllers/ # API 컨트둀러
β”œβ”€β”€ exception/ # μ»€μŠ€ν…€ μ—λŸ¬ 파일
β”œβ”€β”€ middlewares/ # 각쒅 미듀웨어 (인증, μ—λŸ¬, 데이터 검증 λ“±)
β”œβ”€β”€ modules/ # λͺ¨λ“ˆ 파일 (μŠ¬λž™ λ“±)
β”œβ”€β”€ repositories/ # 데이터 μ•‘μ„ΈμŠ€ λ ˆμ΄μ–΄
β”œβ”€β”€ routers/ # API 라우트 μ •μ˜
β”œβ”€β”€ services/ # λΉ„μ¦ˆλ‹ˆμŠ€ 둜직
β”œβ”¬β”€β”€ types/ # Enum, DTO λ“± 데이터 νƒ€μž… μ •μ˜
│└── models/ # 데이터 λͺ¨λΈ
└── utils/ # νŽΈμ˜μ„± ν•¨μˆ˜ μ •μ˜
β”‚Β Β  β”œβ”€β”€ __test__/ # ν…ŒμŠ€νŠΈ 파일
β”‚Β Β  β”œβ”€β”€ configs/ # μ„€μ • 파일 (DB λ“±)
β”‚Β Β  β”œβ”€β”€ constants/ # μƒμˆ˜ 데이터 파일
β”‚Β Β  β”œβ”€β”€ controllers/ # API 컨트둀러
β”‚Β Β  β”œβ”€β”€ exception/ # μ»€μŠ€ν…€ μ—λŸ¬ 파일
β”‚Β Β  β”œβ”€β”€ middlewares/ # 각쒅 미듀웨어 (인증, μ—λŸ¬, 데이터 검증 λ“±)
β”‚Β Β  β”œβ”€β”€ modules/ # λͺ¨λ“ˆ 파일 (μŠ¬λž™ λ“±)
β”‚Β Β  β”œβ”€β”€ repositories/ # 데이터 μ•‘μ„ΈμŠ€ λ ˆμ΄μ–΄
β”‚Β Β  β”œβ”€β”€ routers/ # API 라우트 μ •μ˜
β”‚Β Β  β”œβ”€β”€ services/ # λΉ„μ¦ˆλ‹ˆμŠ€ 둜직
β”‚Β Β  β”œβ”€β”€ types/ # Enum, DTO λ“± 데이터 νƒ€μž… μ •μ˜
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ models/ # 데이터 λͺ¨λΈ
β”‚Β Β  └── utils/ # νŽΈμ˜μ„± ν•¨μˆ˜ μ •μ˜
```
6 changes: 3 additions & 3 deletions src/controllers/post.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
export class PostController {
constructor(private postService: PostService) {}

getAllPost: RequestHandler = async (
getAllPosts: RequestHandler = async (
req: Request<object, object, object, GetAllPostsQuery>,
res: Response<PostsResponseDto>,
next: NextFunction,
Expand All @@ -38,15 +38,15 @@ export class PostController {
}
};

getAllPostStatistics: RequestHandler = async (
getAllPostsStatistics: RequestHandler = async (
req: Request,
res: Response<PostStatisticsResponseDto>,
next: NextFunction,
) => {
try {
const { id } = req.user;

const stats = await this.postService.getAllPostStatistics(id);
const stats = await this.postService.getAllPostsStatistics(id);
const totalPostCount = await this.postService.getTotalPostCounts(id);

const response = new PostStatisticsResponseDto(
Expand Down
Loading