Skip to content
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
5 changes: 4 additions & 1 deletion apps/web/src/api/member/point.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { authApi } from '../instance/authApi'
import { PointHistoryResponse } from '@/types/_shared/pointHistory'
import { MAX_PAGE_SIZE } from '@/utils/pagedResponse'

export const fetchPointHistory = async (): Promise<PointHistoryResponse> => {
try {
// 서버가 기본 size=10으로 잘라 보내므로 명시적으로 최대치를 요청한다.
// (엔벨로프 키 `pointHistory`는 전환 전후 동일해 별도 정규화가 필요 없다.)
const response = await authApi.get<PointHistoryResponse>(
'/member/point-history',
`/member/point-history?size=${MAX_PAGE_SIZE}`,
)
return response.data
} catch (error) {
Expand Down
8 changes: 5 additions & 3 deletions apps/web/src/api/myComments.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { authApi } from '@/api/instance/authApi'
import { MyCommentsResponse } from '@/types/api/myComments'
import { MAX_PAGE_SIZE, unwrapList } from '@/utils/pagedResponse'

export const fetchMyComments = async (sort: string = 'latest') => {
try {
const res = await authApi.get<MyCommentsResponse[]>(
`/comments/mine?sort=${sort}`,
// 페이지네이션 UI가 없으므로 한 번에 최대치까지 받아 기존 동작을 유지한다.
const res = await authApi.get(
`/comments/mine?sort=${sort}&size=${MAX_PAGE_SIZE}`,
)
return res.data
return unwrapList<MyCommentsResponse>(res.data, 'comments')
} catch (error) {
throw error
}
Expand Down
15 changes: 10 additions & 5 deletions apps/web/src/api/votes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CreateVoteData, MineVotesResponse } from '@/types/api/votes'
import { CreateVoteData, MineVoteItem } from '@/types/api/votes'
import { MAX_PAGE_SIZE, unwrapList } from '@/utils/pagedResponse'
import { authApi } from './instance/authApi'

export interface VoteOption {
Expand Down Expand Up @@ -80,11 +81,13 @@ export const fetchMineVotesCreated = async (
params.append('category', category)
}
params.append('sort', sort)
// 페이지네이션 UI가 없으므로 한 번에 최대치까지 받아 기존 동작을 유지한다.
params.append('size', String(MAX_PAGE_SIZE))

const response = await authApi.get<MineVotesResponse>(
const response = await authApi.get(
`/votes/mine/created?${params.toString()}`,
)
return response.data
return unwrapList<MineVoteItem>(response.data, 'votes')
} catch (error) {
throw error
}
Expand All @@ -101,11 +104,13 @@ export const fetchMineVotesVoted = async (
params.append('category', category)
}
params.append('sort', sort)
// 페이지네이션 UI가 없으므로 한 번에 최대치까지 받아 기존 동작을 유지한다.
params.append('size', String(MAX_PAGE_SIZE))

const response = await authApi.get<MineVotesResponse>(
const response = await authApi.get(
`/votes/mine/voted?${params.toString()}`,
)
return response.data
return unwrapList<MineVoteItem>(response.data, 'votes')
} catch (error) {
throw error
}
Expand Down
11 changes: 9 additions & 2 deletions apps/web/src/types/api/votes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { VoteCategory } from '../_shared/vote'
import type { PageMeta } from '@/utils/pagedResponse'

export type CreateVoteOption = {
content: string
Expand All @@ -17,12 +18,18 @@ export type MineVoteOption = {
imageUrl?: string | null
}

export type MineVotesResponse = {
/** 내가 만든/투표한 밸런스 게임 목록의 개별 항목 */
export type MineVoteItem = {
voteId: number
title: string
content: string | null
category: string
totalVoteCount: number
createdAt: string
options: MineVoteOption[]
}[]
}

/** `/votes/mine/*` 페이지 엔벨로프 응답 */
export type PagedMineVotesResponse = PageMeta & {
votes: MineVoteItem[]
}
42 changes: 42 additions & 0 deletions apps/web/src/utils/pagedResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* 목록 API 응답 형태 과도기 대응 유틸.
*
* 서버가 목록 응답을 배열에서 페이지 엔벨로프로 전환하는 중이다.
*
* - 배열: `[{...}, {...}]`
* - 엔벨로프: `{ votes: [...], page, size, hasNext }`
*
* 서버 `dev`에는 엔벨로프가 적용됐지만 `main`에는 아직 배열이라,
* 동일한 프론트 코드가 두 환경 모두에서 동작해야 한다.
* 서버 전환이 모든 환경에 끝나면 이 유틸을 제거하고 엔벨로프 타입만 남긴다.
*/

/** 페이지 엔벨로프 공통 메타 (서버 PaginationValidator 기준) */
export type PageMeta = {
page: number
size: number
hasNext: boolean
}

/** 서버가 허용하는 최대 page size. 초과 시 400을 반환한다. */
export const MAX_PAGE_SIZE = 50

/**
* 배열 또는 페이지 엔벨로프를 항상 배열로 정규화한다.
*
* @param data 응답 본문 (배열 또는 엔벨로프)
* @param key 엔벨로프 안에서 목록이 담긴 키 (예: `votes`, `comments`)
*/
export function unwrapList<T>(data: unknown, key: string): T[] {
if (Array.isArray(data)) return data as T[]

if (data !== null && typeof data === 'object') {
const items = (data as Record<string, unknown>)[key]
if (Array.isArray(items)) return items as T[]
}

// 예상 밖의 형태는 빈 목록으로 처리한다.
// 배열을 가정한 컴포넌트에서 `.map is not a function`으로 터지는 것보다,
// 빈 상태 문구를 보여주는 편이 낫다.
return []
}
6 changes: 4 additions & 2 deletions docs/screens/SCR-MY-COMMENT-001_my-comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@

| Method | Endpoint | 용도 |
|---|---|---|
| GET | `/member/comments` (추정) | 내 댓글 목록 |
| DELETE | (TODO) | 다중 댓글 삭제 |
| GET | `/comments/mine?sort&size=50` | 내 댓글 목록 (응답 키 `comments`) |
| DELETE | `/comments/{commentId}` | 댓글 삭제 (다중 선택 시 병렬 호출) |
> **응답 형태 과도기**: 서버가 목록 응답을 배열 → `{ <목록키>, page, size, hasNext }` 엔벨로프로 전환 중이다(서버 `dev` 적용 / `main` 미적용). 프론트는 `unwrapList`로 두 형태를 모두 배열로 정규화하며, 페이지네이션 UI가 없으므로 `size=50`(서버 상한)을 요청해 기존 동작을 유지한다.


## 📎 관련 문서

Expand Down
4 changes: 3 additions & 1 deletion docs/screens/SCR-MY-CREATED-001_my-created.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@

| Method | Endpoint | 용도 |
|---|---|---|
| GET | (TODO: HistoryPage 컴포넌트 확인) | 내 생성 게임 목록 |
| GET | `/votes/mine/created?category&sort&size=50` | 내 생성 게임 목록 (응답 키 `votes`) |
> **응답 형태 과도기**: 서버가 목록 응답을 배열 → `{ <목록키>, page, size, hasNext }` 엔벨로프로 전환 중이다(서버 `dev` 적용 / `main` 미적용). 프론트는 `unwrapList`로 두 형태를 모두 배열로 정규화하며, 페이지네이션 UI가 없으므로 `size=50`(서버 상한)을 요청해 기존 동작을 유지한다.


## 📎 관련 문서

Expand Down
5 changes: 4 additions & 1 deletion docs/screens/SCR-MY-POINT-001_my-point.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@

| Method | Endpoint | 용도 |
|---|---|---|
| GET | `/member/point-history` | 포인트 내역 + 잔액(각 항목 `remainingPoint`) 조회 |
| GET | `/member/point-history?size=50` | 포인트 내역 + 잔액(각 항목 `remainingPoint`) 조회 |

> **페이지네이션**: 서버 기본 `size=10`으로 내역이 잘리므로 상한 50을 명시 요청한다. 엔벨로프 키 `pointHistory`는 전환 전후 동일해 별도 정규화가 필요 없다.


## 🎨 디자인 토큰 참조

Expand Down
4 changes: 3 additions & 1 deletion docs/screens/SCR-MY-VOTED-001_my-voted.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@

| Method | Endpoint | 용도 |
|---|---|---|
| GET | (TODO: HistoryPage 컴포넌트 확인) | 내 투표 이력 |
| GET | `/votes/mine/voted?category&sort&size=50` | 내 투표 이력 (응답 키 `votes`) |
> **응답 형태 과도기**: 서버가 목록 응답을 배열 → `{ <목록키>, page, size, hasNext }` 엔벨로프로 전환 중이다(서버 `dev` 적용 / `main` 미적용). 프론트는 `unwrapList`로 두 형태를 모두 배열로 정규화하며, 페이지네이션 UI가 없으므로 `size=50`(서버 상한)을 요청해 기존 동작을 유지한다.


## 📎 관련 문서

Expand Down