-
Notifications
You must be signed in to change notification settings - Fork 0
[25.12.17 / TASK-257] Feature - SVG Badge API 추가 #47
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
Open
Jihyun3478
wants to merge
9
commits into
main
Choose a base branch
from
feature/total-stats-svg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ab21edc
feat: SVG Badge API 구현
Jihyun3478 1b8086b
fix: 쿼리 파라미터 오류 수정
Jihyun3478 ea0407f
refactor: SVG Badge API 구조 개선 및 응답 Json으로 변경
Jihyun3478 ffdc0f0
refactor: 사용하지 않는 파라미터 및 함수 삭제
Jihyun3478 764ec4b
test: SVG Badge API 단위 테스트 추가
Jihyun3478 678e989
fix: lint 오류 수정 및 응답 형식 통일
Jihyun3478 131fc22
fix: lint 오류 수정
Jihyun3478 4fe1504
style: prettier 포맷팅 적용
Jihyun3478 9e04ad4
fix: safeNumber 함수의 리턴 타입 명시
Jihyun3478 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { NextFunction, RequestHandler, Request, Response } from 'express'; | ||
| import logger from '@/configs/logger.config'; | ||
| import { GetSvgBadgeQuery, BadgeDataResponseDto } from '@/types'; | ||
| import { SvgService } from '@/services/svg.service'; | ||
|
|
||
| export class SvgController { | ||
| constructor(private svgService: SvgService) {} | ||
|
|
||
| getSvgBadge: RequestHandler = async ( | ||
| req: Request<object, object, object, GetSvgBadgeQuery>, | ||
| res: Response<BadgeDataResponseDto>, | ||
| next: NextFunction, | ||
| ) => { | ||
| try { | ||
| const { username } = req.params as { username: string }; | ||
| const { type = 'default' } = req.query; | ||
|
|
||
| const data = await this.svgService.getBadgeData(username, type); | ||
| const response = new BadgeDataResponseDto(true, '배지 데이터 조회에 성공하였습니다.', data, null); | ||
|
|
||
| res.status(200).json(response); | ||
| } catch (error) { | ||
| logger.error('SVG Badge 조회 실패:', error); | ||
| next(error); | ||
| } | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import pool from '@/configs/db.config'; | ||
| import express, { Router } from 'express'; | ||
| import { LeaderboardRepository } from '@/repositories/leaderboard.repository'; | ||
| import { SvgService } from '@/services/svg.service'; | ||
| import { SvgController } from '@/controllers/svg.controller'; | ||
| import { validateRequestDto } from '@/middlewares/validation.middleware'; | ||
| import { GetSvgBadgeQueryDto } from '@/types'; | ||
|
|
||
| const router: Router = express.Router(); | ||
|
|
||
| const leaderboardRepository = new LeaderboardRepository(pool); | ||
| const svgService = new SvgService(leaderboardRepository); | ||
| const svgController = new SvgController(svgService); | ||
|
|
||
| /** | ||
| * @swagger | ||
| * /api/{username}/badge: | ||
| * get: | ||
| * summary: 사용자 배지 데이터 조회 | ||
| * tags: | ||
| * - SVG | ||
| * security: [] | ||
| * parameters: | ||
| * - in: path | ||
| * name: username | ||
| * required: true | ||
| * schema: | ||
| * type: string | ||
| * description: 조회할 사용자명 | ||
| * example: ljh3478 | ||
| * - in: query | ||
| * name: type | ||
| * schema: | ||
| * type: string | ||
| * enum: [default, simple] | ||
| * default: default | ||
| * responses: | ||
| * '200': | ||
| * description: 배지 데이터 조회 성공 | ||
| * content: | ||
| * application/json: | ||
| * schema: | ||
| * type: object | ||
| * properties: | ||
| * user: | ||
| * type: object | ||
| * properties: | ||
| * username: | ||
| * type: string | ||
| * totalViews: | ||
| * type: number | ||
| * totalLikes: | ||
| * type: number | ||
| * totalPosts: | ||
| * type: number | ||
| * viewDiff: | ||
| * type: number | ||
| * likeDiff: | ||
| * type: number | ||
| * postDiff: | ||
| * type: number | ||
| * recentPosts: | ||
| * type: array | ||
| * items: | ||
| * type: object | ||
| * '404': | ||
| * description: 사용자를 찾을 수 없음 | ||
| * '500': | ||
| * description: 서버 오류 | ||
| */ | ||
| router.get('/:username/badge', validateRequestDto(GetSvgBadgeQueryDto, 'query'), svgController.getSvgBadge); | ||
|
|
||
| export default router; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
타입 안전성 개선이 필요합니다.
라인 3에서
GetSvgBadgeParams타입을 import하지 않고, 라인 10에서 params 타입을object로 지정한 후 라인 15에서 타입 단언(as { username: string })을 사용하고 있습니다. 이는 TypeScript의 타입 체크를 우회하며, 라우트가 변경될 경우 런타임 에러가 발생할 수 있습니다.다음 diff를 적용하여 타입 안전성을 개선하세요:
Also applies to: 9-15
🤖 Prompt for AI Agents