Skip to content

Commit

Permalink
♻️Refactor: PaginationResponse 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
shlee9999 committed Dec 6, 2024
1 parent 7b148a2 commit 8aa8037
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 43 deletions.
39 changes: 3 additions & 36 deletions src/apis/notification/fetchNotificationList.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,13 @@
import { AxiosError } from 'axios'
import { APIResponse, ErrorResponse } from '~types/api'
import { APIResponse, CommonAPIResponse, ErrorResponse, PaginationResponse } from '~types/api'
import { axiosInstance } from '~apis/axiosInstance'
import { BooleanString } from '~types/common'

export type FetchNotificationListRequest = {
page: number
}

export type FetchNotificationListResponse = {
size: number
content: [
{
notificationId: number
type: string
content: string
isRead: BooleanString
memberId: number
createdAt: string
},
]
number: number
sort: {
empty: boolean
sorted: boolean
unsorted: boolean
}
numberOfElements: number
pageable: {
offset: number
sort: {
empty: boolean
sorted: boolean
unsorted: boolean
}
pageSize: number
paged: boolean
pageNumber: number
unpaged: boolean
}
first: boolean
last: boolean
empty: boolean
export type FetchNotificationListResponse = PaginationResponse & {
content: Array<Pick<CommonAPIResponse, 'notificationId' | 'type' | 'content' | 'isRead' | 'memberId' | 'createdAt'>>
}

export const fetchNotificationList = async (
Expand Down
51 changes: 44 additions & 7 deletions src/types/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatType, Gender, FamilyRole, DayOfWeek, Provider, BooleanString, Time } from '~types/common'
import { ChatType, Gender, FamilyRole, DayOfWeek, Provider, BooleanString, Time, NotificationType } from '~types/common'

export type APIResponse<T> = {
code: number
Expand All @@ -18,6 +18,13 @@ export type BasicInfo = {
gender: Gender
}

export type TimeStamp = {
/** 생성 시간 @example "2024-12-03T08:17:04.717Z" */
createdAt: string
/** 업데이트 시간 @example "2024-12-03T08:17:04.717Z" */
updatedAt: string
}

export type Dog = BasicInfo & {
/** 강아지 ID @example 1 */
dogId: number
Expand Down Expand Up @@ -106,7 +113,7 @@ export type Walk = {
totalDistanceInKilometers: number
}

export type Chat = {
export type Chat = TimeStamp & {
/** 채팅 ID @example 123 */
chatId: number
/** 채팅방 ID @example 3 */
Expand All @@ -123,10 +130,6 @@ export type Chat = {
readMessageIds: null
/** 읽지 않은 메시지 수 @example 3 */
unreadMessageCount: number
/** 생성 시간 @example "2024-12-03T08:17:04.717Z" */
createdAt: string
/** 업데이트 시간 @example "2024-12-03T08:17:04.717Z" */
updatedAt: string
}

export type Family = {
Expand All @@ -147,14 +150,21 @@ export type CommonAPIRequest = Member &
totalWalkTimeSecond: number
}

export type Notification = TimeStamp & {
notificationId: number
type: NotificationType
content: string
}

export type CommonAPIResponse = BasicInfo &
Member &
Chat &
Family &
Walk &
Position &
Dog &
OtherDog & {
OtherDog &
Notification & {
dog: Dog
dogs: Dog[]
dogWalkCount: number
Expand All @@ -172,3 +182,30 @@ export type CommonAPIResponse = BasicInfo &
positionList: Position[]
memberEmail: string
}

//* Pagination 관련
export type SortInfo = {
empty: boolean
sorted: boolean
unsorted: boolean
}

export type PageableInfo = {
offset: number
sort: SortInfo
pageSize: number
paged: boolean
pageNumber: number
unpaged: boolean
}

export type PaginationResponse = {
size: number
number: number
numberOfElements: number
first: boolean
last: boolean
empty: boolean
sort: SortInfo
pageable: PageableInfo
}

0 comments on commit 8aa8037

Please sign in to comment.