Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
sonsurim committed Jan 21, 2024
2 parents b228edb + 4f88d3b commit 41bc2d4
Show file tree
Hide file tree
Showing 110 changed files with 1,768 additions and 1,013 deletions.
1 change: 1 addition & 0 deletions src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ declare global {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface ObjectConstructor {
entries<T, K>(o: { [s: T]: K } | ArrayLike<T>): [T, K][]
keys<T = string>(o: object): T[]
}
}
7 changes: 4 additions & 3 deletions src/apis/image/queries.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { DefaultError } from '@tanstack/react-query'
import { useMutation } from '@tanstack/react-query'
import { createUploadImages } from './apis'
import type { CreateUploadImagesReq } from './types'
import type { CreateUploadImagesReq, CreateUploadImagesRes } from './types'

export const useCreateUploadImagesMutation = () =>
useMutation({
mutationFn: (files: CreateUploadImagesReq) => createUploadImages(files)
useMutation<CreateUploadImagesRes, DefaultError, CreateUploadImagesReq>({
mutationFn: files => createUploadImages(files)
})
7 changes: 1 addition & 6 deletions src/apis/image/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import type { ImagesUpload, ImageUpload } from '@types'
import type { ImagesUpload } from '@types'

export type CreateUploadImagesReq = FormData

export type CreateUploadImagesRes = ImagesUpload

export type PostUploadImageReq = {
file: string
}
export type PostUploadImageRes = ImageUpload

export type GetImageReq = {
path: string
}
Expand Down
9 changes: 8 additions & 1 deletion src/apis/like/apis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import type { UpdateLikeStatusReq } from './types'
import type {
GetLikedPostsReq,
GetLikedPostsRes,
UpdateLikeStatusReq
} from './types'
import { http } from '@utils/http'

export const updateLikeStatus = (postId: number) =>
http.put<UpdateLikeStatusReq, null>('/posts/likes', { postId })

export const getLikedPosts = (params: GetLikedPostsReq) =>
http.get<GetLikedPostsReq, GetLikedPostsRes>('/posts/likes', params)
1 change: 1 addition & 0 deletions src/apis/like/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './types'
export * from './apis'
export * from './queries'
16 changes: 12 additions & 4 deletions src/apis/like/queries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { useMutation } from '@tanstack/react-query'
import { updateLikeStatus } from './apis'
import type { DefaultError } from '@tanstack/react-query'
import { useQuery, useMutation } from '@tanstack/react-query'
import { getLikedPosts, updateLikeStatus } from './apis'
import type { GetLikedPostsReq, UpdateLikeStatusReq } from './types'

export const useGetLikedPostsQuery = (searchOptions: GetLikedPostsReq) =>
useQuery({
queryKey: ['likedPosts', searchOptions],
queryFn: () => getLikedPosts(searchOptions)
})

export const useUpdateLikeStatusMutation = () =>
useMutation({
mutationFn: (postId: number) => updateLikeStatus(postId)
useMutation<null, DefaultError, UpdateLikeStatusReq['postId']>({
mutationFn: postId => updateLikeStatus(postId)
})
4 changes: 2 additions & 2 deletions src/apis/like/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { PostSummaries } from '@types'

export type GetLikedPostsReq = {
sort: string
lastId: number
limit: number
lastId?: number
limit?: number
}
export type GetLikedPostsRes = PostSummaries

Expand Down
21 changes: 20 additions & 1 deletion src/apis/member/apis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type {
GetMemberProfileRes,
GetMemberProfileReq,
GetMyProfileRes
GetMyProfileRes,
CheckValidNicknameReq,
CheckValidNicknameRes,
UpdateMyProfileReq,
UpdateMyProfileRes
} from './types'
import { http } from '@utils/http'

Expand All @@ -11,3 +15,18 @@ export const getMyProfile = () =>
export const getMemberProfile = async (
memberId: GetMemberProfileReq['memberId']
) => http.get<null, GetMemberProfileRes>(`/member/${memberId}`)

export const updateMyProfile = async ({
memberId,
...payload
}: UpdateMyProfileReq) =>
http.put<Omit<UpdateMyProfileReq, 'memberId'>, UpdateMyProfileRes>(
`/member/${memberId}`,
payload
)

export const checkValidNickname = async (payload: CheckValidNicknameReq) =>
http.post<CheckValidNicknameReq, CheckValidNicknameRes>(
'/nickname-duplicate',
payload
)
10 changes: 10 additions & 0 deletions src/apis/member/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ export const initialMyProfile = {
reviewCount: 0,
likeProductCount: 0
}

export const initialMemberProfile = {
id: 0,
nickname: '',
profileImageUrl: '',
offerLevel: 0,
sellingProductCount: 0,
soldProductCount: 0,
reviewCount: 0
}
47 changes: 40 additions & 7 deletions src/apis/member/queries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
import { getMemberProfile, getMyProfile } from './apis'
import { initialMyProfile } from './data'
import type { DefaultError } from '@tanstack/react-query'
import { useMutation, useQuery } from '@tanstack/react-query'
import {
checkValidNickname,
getMemberProfile,
getMyProfile,
updateMyProfile
} from './apis'
import { initialMemberProfile, initialMyProfile } from './data'
import type {
CheckValidNicknameReq,
CheckValidNicknameRes,
UpdateMyProfileReq,
UpdateMyProfileRes
} from './types'

export const useGetProfileQuery = (memberId: null | number) =>
useQuery({
queryKey: ['profile', memberId],
queryFn: () => {
if (!memberId) {
return getMyProfile()
}

return getMemberProfile(memberId)
},
initialData: memberId ? initialMemberProfile : initialMyProfile
})

export const useGetMyProfileQuery = (accessToken?: string) =>
useQuery({
Expand All @@ -10,8 +35,16 @@ export const useGetMyProfileQuery = (accessToken?: string) =>
initialData: initialMyProfile
})

export const useGetMemberProfileQuery = (memberId = '') =>
useSuspenseQuery({
queryKey: ['memberProfile', memberId],
queryFn: () => getMemberProfile(Number(memberId))
export const useUpdateMyProfileMutation = () =>
useMutation<UpdateMyProfileRes, DefaultError, UpdateMyProfileReq>({
mutationFn: payload => updateMyProfile(payload)
})

export const useCheckValidNicknameMutation = () =>
useMutation<
CheckValidNicknameRes,
DefaultError,
CheckValidNicknameReq['nickname']
>({
mutationFn: nickname => checkValidNickname({ nickname })
})
14 changes: 6 additions & 8 deletions src/apis/member/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ export type GetMemberProfileReq = {
}
export type GetMemberProfileRes = MemberProfile

export type UpdateMemberProfileReq = {
export type UpdateMyProfileReq = {
memberId: number
nickname: string
profileImageUrl: string
}
// TODO: 정확한 타입 BE 확인 필요
export type UpdateMemberProfileRes = number
export type UpdateMyProfileRes = number

export type CheckValidNickNameReq = {
nickName: string
export type CheckValidNicknameReq = {
nickname: string
}
// TODO: 정확한 타입 BE 확인 필요
export type CheckValidNickNameRes = {
[key in string]: boolean
export type CheckValidNicknameRes = {
duplicate: boolean
}
5 changes: 5 additions & 0 deletions src/apis/offer/apis.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import type {
GetMyOffersReq,
GetMyOffersRes,
GetPostOffersReq,
CreateOfferReq,
GetPostOffersRes
} from './types'
import { http } from '@utils/http'

export const getMyOffers = (params: GetMyOffersReq) =>
http.get<GetMyOffersReq, GetMyOffersRes>('/posts/offers', params)

export const getPostOffers = (params: GetPostOffersReq) =>
http.get<GetPostOffersReq, GetPostOffersRes>(
`/posts/${params.postId}/offers`,
Expand Down
1 change: 1 addition & 0 deletions src/apis/offer/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './types'
export * from './apis'
export * from './queries'
10 changes: 8 additions & 2 deletions src/apis/offer/queries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { useMutation, useQuery } from '@tanstack/react-query'
import { getPostOffers, createOffer } from './apis'
import type { CreateOfferReq, GetPostOffersReq } from './types'
import { getPostOffers, createOffer, getMyOffers } from './apis'
import type { CreateOfferReq, GetPostOffersReq, GetMyOffersReq } from './types'

export const useGetMyOffersQuery = (searchOptions: GetMyOffersReq) =>
useQuery({
queryKey: ['myOffers', searchOptions],
queryFn: () => getMyOffers(searchOptions)
})

export const useGetPostOffersQuery = (params: GetPostOffersReq) =>
useQuery({
Expand Down
4 changes: 2 additions & 2 deletions src/apis/offer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type CreateOfferRes = CommonCreation

export type GetMyOffersReq = {
sort: string
lastId: number
limit: number
lastId?: number
limit?: number
}
export type GetMyOffersRes = OfferSummaries
2 changes: 1 addition & 1 deletion src/apis/post/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const getCategories = () =>
export const getPosts = (params: GetPostsReq) =>
http.get<GetPostsReq, GetPostsRes>('/posts', params)

export const updateTradeStatus = ({
export const updatePostTradeStatus = ({
postId,
...params
}: UpdateTradeStatusReq) =>
Expand Down
13 changes: 7 additions & 6 deletions src/apis/post/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getCategories,
createPost,
getPosts,
updateTradeStatus,
updatePostTradeStatus,
deletePost,
updatePost
} from './apis'
Expand Down Expand Up @@ -73,15 +73,16 @@ export const useGetCategoriesQuery = () =>
queryFn: getCategories
})

export const useGetPostsQuery = (params: GetPostsReq) =>
export const useGetPostsQuery = (searchOptions: GetPostsReq) =>
useQuery({
queryKey: ['getPosts'],
queryFn: () => getPosts(params)
queryKey: ['posts', searchOptions],
queryFn: () => getPosts(searchOptions),
enabled: typeof searchOptions.sellerId === 'number'
})

export const useGetInfinitePostsQuery = (params: GetPostsReq) =>
useInfiniteQuery<GetPostsRes>({
queryKey: ['getPosts'],
queryKey: ['infinitePosts'],
queryFn: () => getPosts(params),
initialPageParam: null,
getNextPageParam: lastPage =>
Expand All @@ -92,7 +93,7 @@ export const useGetInfinitePostsQuery = (params: GetPostsReq) =>

export const useUpdateTradeStatusMutation = () =>
useMutation({
mutationFn: (params: UpdateTradeStatusReq) => updateTradeStatus(params)
mutationFn: (params: UpdateTradeStatusReq) => updatePostTradeStatus(params)
})

export const useDeletePostMutation = (postId: DeletePostReq) =>
Expand Down
1 change: 0 additions & 1 deletion src/apis/post/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export type DeletePostRes = {
// TODO: 정확한 타입 BE 확인 필요
}

// TODO: 정확한 타입 BE 확인 필요
export type UpdateTradeStatusReq = {
postId: number
tradeStatus: TradeStatusCodes
Expand Down
20 changes: 20 additions & 0 deletions src/apis/review/apis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type {
GetReviewsReq,
GetReviewsRes,
CreateReviewReq,
CreateReviewRes,
GetReviewsCountsReq,
GetReviewsCountsRes
} from './types'
import { http } from '@utils/http'

export const getReviews = (params: GetReviewsReq) =>
http.get<GetReviewsReq, GetReviewsRes>('/reviews', params)

export const createReviews = (payload: CreateReviewReq) =>
http.post<CreateReviewReq, CreateReviewRes>('/reviews', payload)

export const getReviewsCounts = (params: GetReviewsCountsReq) =>
http.get<GetReviewsCountsReq, GetReviewsCountsRes>(
`/reviews/counts?memberId=${params.memberId}`
)
16 changes: 16 additions & 0 deletions src/apis/review/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { TradeReviewActivityCodes } from '@types'

export type SelectReviewCounts = {
[key in TradeReviewActivityCodes]: number
}

export const initialReviewsCounts = {
all: 0,
seller: 0,
buyer: 0
}

export const initialReviews = {
hasNext: false,
reviews: []
}
2 changes: 2 additions & 0 deletions src/apis/review/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './types'
export * from './apis'
export * from './queries'
33 changes: 33 additions & 0 deletions src/apis/review/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { DefaultError } from '@tanstack/react-query'
import { useMutation, useQuery } from '@tanstack/react-query'
import { createReviews, getReviews, getReviewsCounts } from './apis'
import type { SelectReviewCounts } from './data'
import { initialReviewsCounts, initialReviews } from './data'
import type { CreateReviewReq, CreateReviewRes, GetReviewsReq } from './types'
import type { ReviewCount } from '@types'

export const useGetReviewsCountsQuery = (memberId: number) =>
useQuery<ReviewCount, Error, SelectReviewCounts>({
queryKey: ['reviewsCounts', memberId],
queryFn: async () => getReviewsCounts({ memberId }),
select: ({ all, seller, buyer }) => ({
ALL: all,
SELLER: seller,
BUYER: buyer
}),
enabled: Boolean(memberId),
initialData: initialReviewsCounts
})

export const useGetReviewsQuery = (searchOptions: GetReviewsReq) =>
useQuery({
queryKey: ['reviews', searchOptions],
queryFn: async () => getReviews({ ...searchOptions }),
enabled: Boolean(searchOptions.memberId),
initialData: initialReviews
})

export const useReviewsMutation = () =>
useMutation<CreateReviewRes, DefaultError, CreateReviewReq>({
mutationFn: payload => createReviews(payload)
})
Loading

0 comments on commit 41bc2d4

Please sign in to comment.