-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Fashion-Cloud/refact/i20
refact: Posts 생성 api 호출 훅 리팩토링
- Loading branch information
Showing
4 changed files
with
73 additions
and
34 deletions.
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,31 @@ | ||
import { useMutation } from 'react-query'; | ||
|
||
import { PostService } from '../service/PostService'; | ||
|
||
export const useAddPost = ( | ||
userId: string, | ||
name: string, | ||
image: string, | ||
skyStatus: string, | ||
temperature: number, | ||
rainfallType: string, | ||
windSpeed: number, | ||
review: number, | ||
onSuccess: () => void | ||
) => { | ||
return useMutation({ | ||
mutationFn: () => | ||
PostService.addPost( | ||
userId, | ||
name, | ||
image, | ||
skyStatus, | ||
temperature, | ||
rainfallType, | ||
windSpeed, | ||
review | ||
), | ||
onSuccess: onSuccess, | ||
onError: () => alert('새 포스트 등록에 실패했습니다.'), | ||
}); | ||
}; |
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,25 @@ | ||
import apiV1Instance from 'src/api/api-instance'; | ||
|
||
export class PostService { | ||
public static addPost = async ( | ||
userId: string, | ||
name: string, | ||
image: string, | ||
skyStatus: string, | ||
temperature: number, | ||
rainfallType: string, | ||
windSpeed: number, | ||
review: number | ||
): Promise<void> => { | ||
await apiV1Instance.post('/posts', { | ||
userId, | ||
name, | ||
image, | ||
skyStatus, | ||
temperature, | ||
rainfallType, | ||
windSpeed, | ||
review, | ||
}); | ||
}; | ||
} |
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