-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: 리뷰 등록 step 1,2,3 페이지 구현 #162
Open
hy57in
wants to merge
5
commits into
develop
Choose a base branch
from
feat/create-review-1
base: develop
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.
+254
−143
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cb24630
refactor: post -> create 네이밍 수정
62e7ef9
fix: feelStatus name feel로 되어 있는 것 field 수정 및 mock data로 확인
d9f8cdb
fix: currentSlide pageIndex로 수정
bf34ee2
refactor: queryKeyFactory로 react query key 관리, mutaion 훅 추가
bb00ed1
fix: create review에서 review list를 invalidate 시키는 것으로 수정
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 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 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,45 @@ | ||
import { useMutation, useQueryClient } from 'react-query'; | ||
|
||
import request from '@/commons/axios'; | ||
import { queryKeyFactory } from '@/commons/queryKeyFactory'; | ||
import { IBaseResponse, IReview } from '@/types'; | ||
|
||
/** | ||
* 리뷰 등록 | ||
*/ | ||
|
||
export interface ICreateReviewResponseData extends IBaseResponse<IReview> {} | ||
|
||
export interface ICreateReviewPayload { | ||
beerId: number; | ||
content: string; | ||
feelStatus: number; | ||
imageUrl: string; | ||
isPublic: boolean; | ||
flavorIds: number[]; | ||
} | ||
|
||
export const createReview = async (payload: ICreateReviewPayload) => { | ||
const res = await request<ICreateReviewResponseData>({ | ||
method: 'post', | ||
url: '/api/v1/reviews', | ||
data: { payload }, | ||
}); | ||
|
||
return res.data; | ||
}; | ||
|
||
export const useCreateReviewMutation = () => { | ||
const cache = useQueryClient(); | ||
|
||
const { mutateAsync: createReviewMutation, ...rest } = useMutation(createReview, { | ||
onSuccess: async () => { | ||
await cache.invalidateQueries(queryKeyFactory.GET_REVIEW()); | ||
}, | ||
}); | ||
|
||
return { | ||
createReview: createReviewMutation, | ||
...rest, | ||
}; | ||
}; |
This file contains 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,16 @@ | ||
import { IGetReview } from '@/apis/review/getReview'; | ||
import request from '@/commons/axios'; | ||
|
||
/** | ||
* 나의 리뷰 삭제 | ||
*/ | ||
|
||
export const deleteReview = async (id?: number) => { | ||
const res = await request<IGetReview>({ | ||
method: 'delete', | ||
url: '/api/v1/reviews', | ||
params: { id }, | ||
}); | ||
|
||
return res.data; | ||
}; |
This file contains 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,18 @@ | ||
import request from '@/commons/axios'; | ||
import { IBaseResponse, IReview } from '@/types'; | ||
|
||
export interface IGetReview extends IBaseResponse<IReview> {} | ||
|
||
/** | ||
* 나의 리뷰 조회 | ||
*/ | ||
|
||
export const getReview = async (id?: number) => { | ||
const res = await request<IGetReview>({ | ||
method: 'get', | ||
url: '/api/v1/reviews', | ||
params: { id }, | ||
}); | ||
|
||
return res.data; | ||
}; |
This file contains 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,49 @@ | ||
import { useQuery } from 'react-query'; | ||
|
||
import request from '@/commons/axios'; | ||
import { queryKeyFactory } from '@/commons/queryKeyFactory'; | ||
import { IBaseResponse, IBeer, IReview } from '@/types'; | ||
|
||
export interface IGetReviews extends IBaseResponse<IReview[]> {} | ||
|
||
/** | ||
* 맥주별 reviews 조회 | ||
*/ | ||
|
||
export const getReviewsByBeer = async (beerId: number) => { | ||
const res = await request<IGetReviews>({ | ||
method: 'get', | ||
url: '/api/v1/reviews', | ||
params: { | ||
beerId, | ||
}, | ||
}); | ||
|
||
return res.data; | ||
}; | ||
|
||
// @todo: 페이지네이션 구현 | ||
|
||
export const useGetReviewsByBeer = (beerId: IBeer['id'], initialData?: IReview[]) => { | ||
const result = useQuery(queryKeyFactory.GET_REVIEWS(beerId), () => getReviewsByBeer(beerId), { | ||
cacheTime: Infinity, | ||
initialData, | ||
enabled: !!beerId, | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
/** | ||
* 나의 리뷰 목록 조회 | ||
*/ | ||
|
||
export const getMyReviews = async (limit?: number) => { | ||
const res = await request<IGetReviews>({ | ||
method: 'get', | ||
url: '/api/v1/reviews/me', | ||
data: { limit }, | ||
}); | ||
|
||
return res.data; | ||
}; |
This file contains 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 |
---|---|---|
@@ -1,102 +1,4 @@ | ||
import { useQuery } from 'react-query'; | ||
|
||
import request from '@/commons/axios'; | ||
import { IBaseResponse, IBeer, IReview } from '@/types'; | ||
|
||
export interface IGetReview extends IBaseResponse<IReview> {} | ||
export interface IGetReviews extends IBaseResponse<IReview[]> {} | ||
|
||
/** | ||
* 맥주별 reviews 조회 | ||
*/ | ||
|
||
export const getReviewsByBeer = async (beerId: number) => { | ||
const res = await request<IGetReviews>({ | ||
method: 'get', | ||
url: '/api/v1/reviews', | ||
params: { | ||
beerId, | ||
}, | ||
}); | ||
|
||
return res.data; | ||
}; | ||
|
||
// @todo: 페이지네이션 구현 | ||
|
||
export const useGetReviewsByBeer = (beerId: IBeer['id'], initialData?: IReview[]) => { | ||
const result = useQuery(['reviews', beerId], () => getReviewsByBeer(beerId), { | ||
cacheTime: Infinity, | ||
initialData, | ||
enabled: !!beerId, | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
/** | ||
* 리뷰 등록 | ||
*/ | ||
|
||
export interface ICreateReviewResponseData extends IBaseResponse<IReview> {} | ||
|
||
export interface ICreateReviewPayload { | ||
beerId: number; | ||
content: string; | ||
feelStatus: number; | ||
imageUrl: string; | ||
isPublic: boolean; | ||
flavorIds: number[]; | ||
} | ||
|
||
export const postReview = async (payload: ICreateReviewPayload) => { | ||
const res = await request<ICreateReviewResponseData>({ | ||
method: 'post', | ||
url: '/api/v1/reviews', | ||
data: { payload }, | ||
}); | ||
|
||
return res.data; | ||
}; | ||
|
||
/** | ||
* 나의 리뷰 조회 | ||
*/ | ||
|
||
export const getReview = async (id?: number) => { | ||
const res = await request<IGetReview>({ | ||
method: 'get', | ||
url: '/api/v1/reviews', | ||
params: { id }, | ||
}); | ||
|
||
return res.data; | ||
}; | ||
|
||
/** | ||
* 나의 리뷰 삭제 | ||
*/ | ||
|
||
export const deleteReview = async (id?: number) => { | ||
const res = await request<IGetReview>({ | ||
method: 'delete', | ||
url: '/api/v1/reviews', | ||
params: { id }, | ||
}); | ||
|
||
return res.data; | ||
}; | ||
|
||
/** | ||
* 나의 리뷰 목록 조회 | ||
*/ | ||
|
||
export const getMyReviews = async (limit?: number) => { | ||
const res = await request<IGetReviews>({ | ||
method: 'get', | ||
url: '/api/v1/reviews/me', | ||
data: { limit }, | ||
}); | ||
|
||
return res.data; | ||
}; | ||
export * from './createReview'; | ||
export * from './getReview'; | ||
export * from './getReviews'; | ||
export * from './deleteReview'; |
This file contains 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 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 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 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 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
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.
'?' 없어도 괜찮을 것 같아요!