-
Notifications
You must be signed in to change notification settings - Fork 1
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 #151 from prgrms-web-devcourse-final-project/48-fe…
…ature/familyddang-update [Feature] #48 패밀리댕 (견주,댕 정보수정)
- Loading branch information
Showing
17 changed files
with
486 additions
and
282 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { AxiosError } from 'axios' | ||
import { APIResponse, CommonAPIResponse, ErrorResponse } from '~types/api' | ||
import { axiosInstance } from '~apis/axiosInstance' | ||
import { DayOfWeek } from '~types/common' | ||
|
||
export type FetchFamilyDDangResponse = Pick< | ||
CommonAPIResponse, | ||
'familyId' | 'dogs' | 'totalWalkCount' | 'totalDistanceInKilometers' | 'totalCalorie' | ||
> & { | ||
members: (CommonAPIResponse['members'][number] & { | ||
walkScheduleInfoList: { | ||
walkScheduleId: number | ||
dayOfWeek: DayOfWeek | ||
walkTime: string | ||
}[] | ||
totalWalkCount: number // 추가된 속성 | ||
})[] | ||
} | ||
|
||
export const fetchFamilyDDang = async (): Promise<APIResponse<FetchFamilyDDangResponse>> => { | ||
try { | ||
const { data } = await axiosInstance.get<APIResponse<FetchFamilyDDangResponse>>(`/family`) | ||
console.log('패밀리댕 정보 바인딩 : ', data) | ||
return data | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
const { response } = error as AxiosError<ErrorResponse> | ||
|
||
if (response) { | ||
const { code, message } = response.data | ||
switch (code) { | ||
case 400: | ||
throw new Error(message || '잘못된 요청입니다.') | ||
case 401: | ||
throw new Error(message || '인증에 실패했습니다.') | ||
case 500: | ||
throw new Error(message || '서버 오류가 발생했습니다.') | ||
default: | ||
throw new Error(message || '알 수 없는 오류가 발생했습니다.') | ||
} | ||
} | ||
// 요청 자체가 실패한 경우 | ||
throw new Error('네트워크 연결을 확인해주세요') | ||
} | ||
|
||
console.error('예상치 못한 에러:', error) | ||
throw new Error('다시 시도해주세요') | ||
} | ||
} |
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,39 @@ | ||
import { AxiosError } from 'axios' | ||
import { APIResponse, CommonAPIResponse, ErrorResponse } from '~types/api' | ||
import { axiosInstance } from '~apis/axiosInstance' | ||
|
||
export type FetchOwnerProfileResponse = Pick< | ||
CommonAPIResponse, | ||
'memberId' | 'name' | 'gender' | 'familyRole' | 'profileImg' | ||
> | ||
|
||
export const fetchOwnerProfile = async (): Promise<APIResponse<FetchOwnerProfileResponse>> => { | ||
try { | ||
const { data } = await axiosInstance.get<APIResponse<FetchOwnerProfileResponse>>(`/member/update`) | ||
console.log('잘 오나?', data) | ||
return data | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
const { response } = error as AxiosError<ErrorResponse> | ||
|
||
if (response) { | ||
const { code, message } = response.data | ||
switch (code) { | ||
case 400: | ||
throw new Error(message || '잘못된 요청입니다.') | ||
case 401: | ||
throw new Error(message || '인증에 실패했습니다.') | ||
case 500: | ||
throw new Error(message || '서버 오류가 발생했습니다.') | ||
default: | ||
throw new Error(message || '알 수 없는 오류가 발생했습니다.') | ||
} | ||
} | ||
// 요청 자체가 실패한 경우 | ||
throw new Error('네트워크 연결을 확인해주세요') | ||
} | ||
|
||
console.error('예상치 못한 에러:', error) | ||
throw new Error('다시 시도해주세요') | ||
} | ||
} |
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,42 @@ | ||
import { AxiosError } from 'axios' | ||
import { APIResponse, CommonAPIRequest, ErrorResponse, CommonAPIResponse } from '~types/api' | ||
import { axiosInstance } from '~apis/axiosInstance' | ||
|
||
export type UpdateOwnerProfileRequest = Pick<CommonAPIRequest, 'name' | 'gender' | 'familyRole' | 'profileImg'> | ||
|
||
export type UpdateOwnerProfileResponse = Pick< | ||
CommonAPIResponse, | ||
'memberId' | 'name' | 'gender' | 'familyRole' | 'profileImg' | ||
> | ||
|
||
export const updateOwnerProfile = async ( | ||
req: UpdateOwnerProfileRequest | ||
): Promise<APIResponse<UpdateOwnerProfileResponse>> => { | ||
try { | ||
const { data } = await axiosInstance.patch<APIResponse<UpdateOwnerProfileResponse>>(`/member/update`, req) | ||
return data | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
const { response } = error as AxiosError<ErrorResponse> | ||
|
||
if (response) { | ||
const { code, message } = response.data | ||
switch (code) { | ||
case 400: | ||
throw new Error(message || '잘못된 요청입니다.') | ||
case 401: | ||
throw new Error(message || '인증에 실패했습니다.') | ||
case 500: | ||
throw new Error(message || '서버 오류가 발생했습니다.') | ||
default: | ||
throw new Error(message || '알 수 없는 오류가 발생했습니다.') | ||
} | ||
} | ||
// 요청 자체가 실패한 경우 | ||
throw new Error('네트워크 연결을 확인해주세요') | ||
} | ||
|
||
console.error('예상치 못한 에러:', error) | ||
throw new Error('다시 시도해주세요') | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.