Skip to content
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

🧼 clean: μ½”λ“œ 일관성 ν–₯상 #11

Merged
merged 8 commits into from
Jan 13, 2025

Conversation

Jo-Minseok
Copy link
Collaborator

@Jo-Minseok Jo-Minseok commented Jan 11, 2025

πŸ”¨ ν…ŒμŠ€ν¬

Redis Scan λ°˜ν™˜μ„ μ •μˆ˜λ‘œ λ°”κΎΈλ©΄ μ•ˆ λ˜λ‚˜?

  • Redis에 μ–΄λŠ μ •λ„μ˜ 데이터가 μ €μž₯λ˜μ–΄μžˆλŠ” 지 μ• ν”Œλ¦¬μΌ€μ΄μ…˜ λ‹¨μ—μ„œ 미리 νŒŒμ•…ν•  수 μ—†λ‹€.
  • JS의 μ΅œλŒ€ 숫자 λ²”μœ„λ₯Ό λ²—μ–΄λ‚˜λ²„λ¦¬λ©΄ μ„œλΉ„μŠ€ μ˜ˆμ™Έκ°€ λ°œμƒν•œλ‹€.
  • JS의 μ΅œλŒ€ 숫자 λ²”μœ„ 9007199254740991 만큼 개수 λ²”μœ„κ°€ ν¬μ§€λŠ” μ•Šκ² μ§€λ§Œ μ‹œμŠ€ν…œ μ•ˆμ •μ„±μ„ μœ„ν•΄ λ¬Έμžμ—΄λ‘œ λ°˜ν™˜ν•˜λ„λ‘ 처리

λ‹€μŒ μž‘μ—… μˆ˜ν–‰ λͺ©λ‘ (PR룰에 따라 뢄리)

  1. Repository ν•¨μˆ˜ μž¬μ‚¬μš©ν•˜κ²Œ λ³€κ²½
  2. Swagger 처리 λΆ€λΆ„ λ³€κ²½
    • Swagger Request Example api-docs.ts -> DTO둜 λ³€κ²½
      • μž‘μ—… μ‚¬μœ : ν˜„μž¬ μƒˆλ‘œμš΄ API μƒμ„±μ‹œ api-docs.ts에 μˆ˜λ™μœΌλ‘œ API Request DTO의 속성듀을 λ“±λ‘ν•˜λŠ” λͺ‡λͺ‡ 뢀뢄듀이 있음. Request DTOλ₯Ό 생성할 λ•Œ, ApiPropertyλ₯Ό μ‚¬μš©ν•΄μ„œ μžλ™μœΌλ‘œ μ—°λ™λ˜λ„λ‘ ν•˜λŠ” 게 νŽΈν• λ“― 함
    • Swagger Response Example DTO둜 λ³€κ²½ ν•˜λŠ₯ ν•˜λ‹€λ©΄ λ³€κ²½
      • μž‘μ—… μ‚¬μœ : μœ„μ™€ 동일

μž‘μ—… μ‚¬μœ 

  • μ½”λ“œλŠ” μ—¬λŸ¬ λͺ…이 μ μ—ˆλ‹€ ν•œλ“€ ν•˜λ‚˜μ˜ ν”„λ‘œμ νŠΈ 내뢀라면 μ½”λ“œ ν˜•μ‹μ΄ λͺ¨λ‘ 동일해야 ν•œλ‹€κ³  νŒλ‹¨ν–ˆλ‹€.
  • μΆ”μƒμ μœΌλ‘œ μž‘μ„±λ˜μ–΄ μžˆλŠ” μ½”λ“œλ“€μ΄ λ§Žμ•„ λ‹€μ‹œ μ½”λ“œλ₯Ό 읽을 λ•Œ 이해 μ•ˆ λ˜λŠ” 뢀뢄이 μƒλ‹Ήνžˆ λ§Žμ•˜λ‹€.
  • λˆˆμ— κ±°μŠ¬λ¦¬λŠ” μ½”λ“œλ„ λ„ˆλ¬΄ λ§Žμ•˜κΈ°μ— μž‘μ—…μ„ μˆ˜ν–‰ν–ˆλ‹€.
  • μ •κ·œ ν”„λ‘œμ νŠΈ κΈ°κ°„μ—λŠ” 마감 일자둜 인해 촉박해져 막 μž‘μ—…ν•œ 뢀뢄이 κ½€ λ§Žμ•˜λ‹€.

πŸ“‹ μž‘μ—… λ‚΄μš©

  • νŒŒλΌλ―Έν„° DTO 적용 ν•˜μ—¬ κ°’ κ²€μ¦ν•˜κ²Œ λ³€κ²½

    • νŠΉμ • μ½”λ“œλŠ” νŒŒλΌλ―Έν„°λ₯Ό 직접 μΆ”μΆœν•˜λŠ” 방식이라 κ°’ 검증이 μ•ˆ λ˜λŠ” λ¬Έμ œκ°€ μžˆμ—ˆμŒ. μ½”λ“œ 톡일성을 μœ„ν•΄ DTO μΆ”κ°€
    @Params('feedId') params: Params

    λ³€κ²½

    @Params('feedId') params: FeedPaginationRequestDto
  • Validation μ½”λ“œ 정리, 제거

    • ν•„μš”μ—†λŠ” Validation λ°œκ²¬ν•˜μ—¬ 정리함, 라인도 정리
  • Controller 별도 data λ³€μˆ˜ μ—†μ• μ„œ μ½”λ“œ 톡일

    • λͺ‡λͺ‡ Controller μ½”λ“œμ—μ„œ 일관성이 λ§žμ§€ μ•ŠμŒμ„ 확인
    const data = μ„œλΉ„μŠ€ ν•¨μˆ˜();
    return ApiResponse.responseWithData('메세지',data);

    λ³€κ²½

    return ApiResponse.responseWithData('메세지',μ„œλΉ„μŠ€ ν•¨μˆ˜());
  • νŒŒλΌλ―Έν„° 별도 λ³€μˆ˜ 제거

    const { id } = params
    μ„œλΉ„μŠ€ ν•¨μˆ˜(id);

    λΆˆν•„μš”ν•˜κ²Œ id λ³€μˆ˜λ₯Ό μƒμ„±ν•˜λŠ” ꡬ문 제거

    μ„œλΉ„μŠ€ ν•¨μˆ˜(params.id);
  • Request Example 더미 λ°μ΄ν„°λ‘œ λ³€κ²½
    더미 데이터(ex. test)κ°€ μ•„λ‹Œ μž„μ‹œ 데이터(ex. seok3765)κ°€ λ“€μ–΄κ°€ μžˆλŠ” λΆ€λΆ„ λ³€κ²½

  • λ³€μˆ˜ 이름 result, item, data 처럼 좔상적인 λΆ€λΆ„ ꡬ체화
    map, filter 같이 κ³ μ°¨ ν•¨μˆ˜μ—μ„œ result, item, data와 같이 좔상적인 λ³€μˆ˜λͺ…μœΌλ‘œ 가독성이 λΆˆνŽΈν–ˆλ˜ λΆ€λΆ„ ꡬ체화λ₯Ό 톡해 κ°œμ„ 

  • Validation Pipe Global둜 λ³€κ²½
    μΆ”ν›„ μ»¨νŠΈλ‘€λŸ¬μ— ν•¨μˆ˜λ₯Ό μΆ”κ°€ν•  λ•Œλ§ˆλ‹€ UsePipe둜 Validation을 μˆ˜ν–‰ν•˜λ„λ‘ 적어야 ν•œλ‹€.
    μ½”λ“œ 쀑볡이 λ°œμƒν•œλ‹€κ³  μƒκ°ν–ˆκ³ , λ²ˆκ±°λ‘œμ›€μ΄ λŠκ»΄μ‘Œλ‹€. κ°„κ²°ν•˜κ²Œ ν‘œν˜„μ΄ κ°€λŠ₯ν•  것 κ°™μ•˜λ‹€.
    μ–΄μ§œν”Ό λͺ¨λ“  Requestλ₯Ό DTO둜 μ‚¬μš©ν•˜μžκ³  μ–˜κΈ°κ°€ λ‚˜μ™”κΈ° λ•Œλ¬Έμ— Global Pipe둜 μ²˜λ¦¬ν•΄λ„ λ¬Έμ œμ—†μ„ 것 κ°™λ‹€κ³  μƒκ°ν–ˆλ‹€.

@Jo-Minseok Jo-Minseok added the 🧹 Cleanup μ½”λ“œ 정리 label Jan 11, 2025
@Jo-Minseok Jo-Minseok self-assigned this Jan 11, 2025
@Jo-Minseok Jo-Minseok changed the title 🧼 clean: μ½”λ“œ 일관성, λ³€μˆ˜ 이름 λ³€κ²½ 🧼 clean: μ½”λ“œ 일관성 ν–₯상 Jan 11, 2025
Copy link
Collaborator

@CodeVac513 CodeVac513 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

특히 DTO에 μŠ€μ›¨κ±°κ°€ μ—°λ™λ˜λ„λ‘ ν•΄μ„œ λ¬Έμ„œκ°€ 2번 μˆ˜μ •λ˜λŠ” κ±Έ μ˜ˆλ°©ν•˜λŠ” 게 μΈμƒμ μ΄μ—ˆμŠ΅λ‹ˆλ‹€.
μ „μ²΄μ μœΌλ‘œ 무심코 μ§€λ‚˜κ°”λ˜ 뢀뢄도 μΊμΉ˜ν•΄μ„œ 잘 μž‘μ—…ν•΄μ£Όμ‹  것 κ°™μ•„μš”.

수고 λ§ŽμœΌμ…¨μŠ΅λ‹ˆλ‹€!

Copy link
Member

@asn6878 asn6878 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

item, data 이런거 λŒ€λΆ€λΆ„ μ œκ°€ 썼을텐데 λ°˜μ„±ν•΄μ•Όκ² κ΅°μš” γ… γ… γ… 

고생 λ§ŽμœΌμ…¨μŠ΅λ‹ˆλ‹€! πŸ‘

@Jo-Minseok Jo-Minseok merged commit 824225d into main Jan 13, 2025
1 check passed
@Jo-Minseok Jo-Minseok deleted the refactor/clean-code branch January 13, 2025 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧹 Cleanup μ½”λ“œ 정리
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants