-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
2,167 additions
and
733 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { apiAuth } from "./api"; | ||
import { get, post, patch, put, del } from "./example"; | ||
|
||
// 한줄평,별점 목록 조회 | ||
export const getBookInfo = async ({ bookinfoId }) => { | ||
try { | ||
const res = await get(`/bookinfo/${bookinfoId}`); | ||
console.log("책정보 조회 성공: ", res); | ||
return res; | ||
} catch (error) { | ||
console.error("책정보 조회 실패: ", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
// 한줄평,별점 목록 조회 | ||
export const getOneLineRatingsInfo = async ({ | ||
bookinfoId, | ||
orderBy, | ||
page, | ||
size, | ||
}) => { | ||
try { | ||
// Query Parameter 생성 (값이 존재하는 경우에만 추가) | ||
const queryParams = new URLSearchParams(); | ||
if (orderBy) queryParams.append("orderBy", orderBy); | ||
if (page) queryParams.append("page", page); | ||
if (size) queryParams.append("size", size); | ||
|
||
// 최종 URL | ||
const url = `/bookinfo/${bookinfoId}/onelineratings${ | ||
queryParams.toString() ? `?${queryParams}` : "" | ||
}`; | ||
|
||
const res = await get(url); | ||
console.log("한줄평 목록 조회 성공: ", res); | ||
return res; | ||
} catch (error) { | ||
console.error("한줄평 목록 조회 실패: ", error); | ||
throw error; | ||
} | ||
}; | ||
// 별점 등록 및 수정 | ||
export const enrollRating = async (userbookId, rating) => { | ||
const url = `books/${userbookId}/rating`; | ||
const data = { rating }; | ||
try { | ||
const res = await patch(url, data); | ||
console.log("별점 등록 성공: ", res); | ||
return res?.data; | ||
} catch (error) { | ||
console.error("별점 등록 실패:", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
//별점 삭제 | ||
export const deleteRating = async (userbookId) => { | ||
const url = `books/${userbookId}/rating`; | ||
try { | ||
const res = await del(url); | ||
console.log("별점 삭제 성공: ", res); | ||
} catch (error) { | ||
console.error("별점 삭제 실패: ", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
//한줄평 생성 | ||
export const enrollOneLine = async (userBookId, oneLineContent) => { | ||
const url = `onelines`; | ||
const data = { oneLineContent, userBookId }; | ||
try { | ||
const res = await post(url, data); | ||
console.log("한줄평 등록 성공: ", res); | ||
return res?.data; | ||
} catch (error) { | ||
console.error("한줄평 등록 실패:", error); | ||
throw error; | ||
} | ||
}; | ||
// 한줄평 수정 | ||
export const editOneLine = async (onelineId, oneLineContent) => { | ||
const url = `onelines/${onelineId}`; | ||
const data = { oneLineContent }; | ||
try { | ||
const res = await put(url, data); | ||
console.log("한줄평 수정 성공: ", res); | ||
return res?.data; | ||
} catch (error) { | ||
console.error("한줄평 수정 실패:", error); | ||
throw error; | ||
} | ||
}; | ||
//한줄평 삭제 | ||
export const deleteOneLine = async (onelineId) => { | ||
const url = `onelines/${onelineId}`; | ||
try { | ||
const res = await del(url); | ||
console.log("한줄평 삭제 성공: ", res); | ||
} catch (error) { | ||
console.error("한줄평 삭제 실패: ", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
//한줄평 좋아요 | ||
export const enrollLike = async (onelineId) => { | ||
const url = `onelines/${onelineId}/like`; | ||
try { | ||
const res = await post(url); | ||
console.log("한줄평 좋아요 성공: ", res); | ||
return res; | ||
} catch (error) { | ||
console.error("한줄평 좋아요 실패:", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
//한줄평 좋아요 삭제 | ||
export const deleteLike = async (onelineId) => { | ||
const url = `onelines/${onelineId}/like`; | ||
try { | ||
const res = await del(url); | ||
console.log("한줄평 좋아요 삭제 성공: ", res); | ||
} catch (error) { | ||
console.error("한줄평 좋아요 삭제 실패: ", error); | ||
throw 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,38 @@ | ||
import { apiAuth } from "./api"; | ||
import { get, post, patch, put, del } from "./example"; | ||
|
||
// 유저 정보 조회 - 닉네임, 기록 수 | ||
export const getUserInfo = async (userId) => { | ||
try { | ||
const res = await get(`/users/${userId}`); | ||
console.log("유저 정보 조회 성공: ", res); | ||
return res; | ||
} catch (error) { | ||
console.error("유저 정보 조회 실패: ", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
// 유저 레벨 정보 조회 | ||
export const getUserLevelInfo = async (userId) => { | ||
try { | ||
const res = await get(`/users/${userId}/growth`); | ||
console.log("유저 레벨 정보 조회 성공: ", res); | ||
return res; | ||
} catch (error) { | ||
console.error("유저 레벨 정보 조회 실패: ", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
// 캐릭터 아이템 조회 | ||
export const getItemLists = async () => { | ||
try { | ||
const res = await get(`/useritems`); | ||
console.log("아이템 리스트 조회 성공: ", res); | ||
return res; | ||
} catch (error) { | ||
console.error("아이템 리스트 조회 실패: ", error); | ||
throw 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 |
---|---|---|
@@ -1,30 +1,58 @@ | ||
import { apiAuth } from "./api"; | ||
import { api } from "./api"; | ||
|
||
const BACK_DOMAIN = import.meta.env.VITE_API_BASE_URL; | ||
export const KakaoURI = `${BACK_DOMAIN}/oauth2/authorization/kakao`; | ||
export const GoogleURI = `${BACK_DOMAIN}/oauth2/authorization/google`; | ||
/*토큰 만료 여부 확인*/ | ||
const isTokenExpired = () => { | ||
const expiresIn = localStorage.getItem("expiresIn"); | ||
return expiresIn && new Date().getTime() > expiresIn; | ||
|
||
/*토큰 만료 여부*/ | ||
export const isTokenExpired = () => { | ||
const token = JSON.parse(localStorage.getItem("token")); | ||
const expiresAt = token?.expiresAt || null; | ||
const isExpired = expiresAt && Date.now() > expiresAt; | ||
return isExpired; | ||
}; | ||
|
||
/*userId 가져오기*/ | ||
export const getUserId = () => { | ||
const token = JSON.parse(localStorage.getItem("token")); | ||
return token?.userId || null; | ||
}; | ||
|
||
/*엑세스 토큰 재발급*/ | ||
export const postAccessTokenIssue = async () => { | ||
if (!isTokenExpired()) { | ||
console.log("액세스 토큰이 아직 만료되지 않았습니다."); | ||
return; | ||
} | ||
// if (!isTokenExpired()) { | ||
// console.log("액세스 토큰이 아직 만료되지 않았습니다."); | ||
// return; | ||
// } | ||
try { | ||
const response = await apiAuth.post(`/auth/refresh`); | ||
const token = { | ||
/*기존 토큰에서 accessToken, userId 가져오기*/ | ||
const tokenData = JSON.parse(localStorage.getItem("token")); | ||
const accessToken = tokenData?.accessToken; | ||
const userId = tokenData?.userId; | ||
console.log("post할 accessToken", accessToken); | ||
|
||
const response = await api.post( | ||
`/auth/refresh?accessToken=${accessToken}`, | ||
null, | ||
{ withCredentials: true } | ||
); | ||
|
||
console.log(response); | ||
|
||
/*새 토큰*/ | ||
const newToken = { | ||
accessToken: response.data.accessToken, | ||
expiresIn: new Date().getTime() + response.data.accessTokenMaxAge, | ||
expiresAt: new Date().getTime() + response.data.accessTokenMaxAge * 1000, | ||
isNewUser: false, | ||
userId: userId, | ||
}; | ||
localStorage.setItem("token", JSON.stringify(token)); | ||
console.log(newToken); | ||
|
||
/*새 토큰 넣기*/ | ||
localStorage.setItem("token", JSON.stringify(newToken)); | ||
console.log("새로운 토큰 저장 완료"); | ||
return response; | ||
} catch (error) { | ||
localStorage.removeItem("token"); | ||
throw error; | ||
console.error("토큰 재발행 오류: ", error); | ||
} | ||
}; |
Oops, something went wrong.