Skip to content

Commit

Permalink
♻️ Refactor : userService 파일 타입지정 및 기타 오류 수정 #213
Browse files Browse the repository at this point in the history
  • Loading branch information
w-ho-choo committed Jan 10, 2025
1 parent 50ae7a6 commit c8e3503
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
13 changes: 9 additions & 4 deletions src/apis/userService.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { GoodsRecordApiResponse } from './../typings/db'
import { ProfileEditApiResponse } from '@typings/db'
import fetchApi from './ky'
import { MyDataApiReponse, UserDataApiResponse } from '@typings/userForm'

const userService = {
getUserInfo: async (userId: number) => {
const response = await fetchApi.get(`members/${userId}`).json()
const response: UserDataApiResponse = await fetchApi
.get(`members/${userId}`)
.json()

return response.data
},

getMyInfo: async (userId: number) => {
const response = await fetchApi.get(`members/me?memberId=${userId}`).json()
const response: MyDataApiReponse = await fetchApi
.get(`members/me?memberId=${userId}`)
.json()

return response.data
},
Expand All @@ -29,10 +35,9 @@ const userService = {
callingType: string,
page: number,
) => {
const response = await fetchApi
const response: GoodsRecordApiResponse = await fetchApi
.get(`profile/${memberId}/goods/${callingType}?page=${page}&size=5`)
.json()

return response.data
},
}
Expand Down
15 changes: 4 additions & 11 deletions src/pages/GoodsRecordPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,17 @@ import { useLocation, useNavigate, useParams } from 'react-router-dom'
import { useInfiniteQuery } from '@tanstack/react-query'
import { QUERY_KEY } from '@apis/queryClient'
import userService from '@apis/userService'
import { useInView } from 'react-intersection-observer'
import { RefContainer } from '@styles/globalStyle'
import Spinner from '@components/Spinner'
import { toast } from 'react-toastify'
import { ROUTE_PATH } from '@constants/ROUTE_PATH'
import { GoodsRecordData } from '@typings/db'

const HEADER_TEXT = {
sold: '굿즈 판매기록',
bought: '굿즈 구매기록',
}

interface GoodsRecord {
author: string
createdAt: string
imageUrl: string
postId: number
price: number
title: string
}

const GoodsRecordPage = () => {
const location = useLocation()
const navigate = useNavigate()
Expand Down Expand Up @@ -87,7 +78,9 @@ const GoodsRecordPage = () => {
if (!data) return null

const { pages } = data
const goodsRecordList: GoodsRecord[] = pages.flatMap((page) => page.content)
const goodsRecordList: GoodsRecordData[] = pages.flatMap((page) =>
page ? page.content : [],
)

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ProfilePage/ProfileMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ProfileMain = () => {

const [userId, setUserId] = useState(id)
const [isMyProfile, setIsMyProfile] = useState<boolean | null>(null)
const [userInfo, setUserInfo] = useState<UserInfo | null>(null)
const [userInfo, setUserInfo] = useState<UserInfo | undefined>(undefined)

const myInfoResult = useGetMyInfo(Number(loginMemberId))
const userInfoResult = useGetUserInfo(
Expand Down
28 changes: 28 additions & 0 deletions src/typings/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,31 @@ export interface ProfileEditApiResponse {
status: string
timestamp: string
}

// userService.getGoodsRecordList

export interface GoodsRecordData {
postId: number
title: string
imageUrl: string
price: number
author: string
createdAt: string
}

export interface GoodsRecordReponse {
content: GoodsRecordData[]
hasNext: boolean
pageNumber: number
pageSize: number
totalElements: number
totalPages: number
}

export interface GoodsRecordApiResponse {
code: number
data: GoodsRecordReponse
message: string | null
status: string
timestamp: string
}
16 changes: 16 additions & 0 deletions src/typings/userForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@ export interface UserInfo {
teamName: string
visitsCount?: number
}

export interface UserDataApiResponse {
code: number
data: UserInfo
message: string | null
status: string
timestamp: string
}

export interface MyDataApiReponse {
code: number
data: UserInfo
message: string | null
status: string
timestamp: string
}

0 comments on commit c8e3503

Please sign in to comment.