Skip to content

Commit

Permalink
Feat/content page data fetch (#22)
Browse files Browse the repository at this point in the history
* bug: Content.header section margin -> 0

* cors 테스트

* Style: 콤마찍는거 제거

* feat: content api 구현

* feat: contentPage에서 fetch후 컴포넌트에 props로 주입

* feat: Contet.Header 데이터

* feat: Content.Cast 데이터 props로 주입

* feat: Content.panel 데이터 props로 주입 및 MyCommentBox 컴포넌트 분리

* feat: MyCommentBox 컴포넌트 구현

* feat: 모달 컴포넌트 구현

* feat: 코멘트, 대댓글 작성 모달 구현

* feat: Content.Comment 데이터 props로 주입

* feat: 코멘트 api구현

* feat: 평점 매기기 api연결

* feat: 코멘트 리스트 페이지 데이터 fetch 구현

* feat : 별점 api 서비스 구현

* feat : 코멘트 작성/수정/삭제 기능 추가

* feat : user subpage의 유저가 평가한 영화 리스트 데이터 패칭 추가

---------

Co-authored-by: suhyeonOh <[email protected]>
  • Loading branch information
izone00 and ohsuhyeon0119 authored Jan 22, 2024
1 parent ba82d1c commit dca2178
Show file tree
Hide file tree
Showing 27 changed files with 1,366 additions and 504 deletions.
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"semi": true,
"useTabs": false,
"tabWidth": 2,
"trailingComma": "all",
"printWidth": 80
}
17 changes: 2 additions & 15 deletions src/apis/auth.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

// import { BASE_API_URL } from "./const";
import { BASE_API_AUTH_URL } from "./const";

export async function postSignup(
nickname: string,
username: string,
password1: string,
password2: string,
password2: string
) {
return fetch(`${BASE_API_AUTH_URL}/auth/register/`, {
return fetch(`${BASE_API_AUTH_URL}/auth/token/register/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -18,9 +17,7 @@ export async function postSignup(
}

export async function postLogin(username: string, password: string) {

return fetch(`${BASE_API_AUTH_URL}/auth/token/`, {

method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -34,9 +31,7 @@ export async function postLogin(username: string, password: string) {
}

export async function getMyUserData(accessToken: string) {

return fetch(`${BASE_API_AUTH_URL}/users/mypage/`, {

method: "GET",
headers: {
Authorization: `Bearer ${accessToken}`,
Expand All @@ -46,39 +41,32 @@ export async function getMyUserData(accessToken: string) {

// 리프레시 토큰 및 엑세스 토큰을 갱신. 자동로그인을 위해 사용
export async function postNewToken() {

return fetch(`${BASE_API_AUTH_URL}/auth/token/refresh/new/`, {

method: "POST",
credentials: "include",
});
}

export async function postLogout() {

return fetch(`${BASE_API_AUTH_URL}/auth/token/logout/`, {

method: "POST",
credentials: "include",
});
}


export async function getKakaoAutoCallback(code: string | null) {
return fetch(`${BASE_API_AUTH_URL}/auth/kakao/login?code=${code}`);
}

// 카카오 회원탈퇴 기능이 구현되어 있는 엔드포인트이나, 기본 탈퇴 기능도 구현되어 있어서 이 api만 사용
export async function deleteWithDrawalUser(accessToken: string) {
return fetch(`${BASE_API_AUTH_URL}/users/mypage/delete/kakao_unlink/`, {

method: "DELETE",
credentials: "include",
headers: {
Authorization: `Bearer ${accessToken}`,
},
});

}

/*
Expand All @@ -91,4 +79,3 @@ export async function deleteWithDrawalUser(accessToken: string) {
},
});
}*/

83 changes: 83 additions & 0 deletions src/apis/comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { BASE_API_URL } from "./const";

// 아직 영화리스트가 없어서 받아보기 어려움
// type은 추후에 enum으로 수정
export async function getCommentListRequest(movieCD: string) {
return fetch(`${BASE_API_URL}/contents/${movieCD}/comments`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
}

export async function createCommentRequest(
movieCD: string,
accessToken: string,
content: string,
has_spoiler: boolean
) {
return fetch(`${BASE_API_URL}/contents/${movieCD}/comments/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + accessToken,
},
body: JSON.stringify({
content,
has_spoiler: has_spoiler,
}),
});
}

//특정 코멘트 아이디의 코멘트를 알 수 있다.
export async function getCommentRequest(commentId: number) {
return fetch(`${BASE_API_URL}/comments/${commentId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
});
}

export async function updateCommentRequest(
commentId: number,
accessToken: string,
content: string,
hasSpoiler: boolean
) {
return fetch(`${BASE_API_URL}/comments/${commentId}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + accessToken,
},
credentials: "include",
body: JSON.stringify({
content,
has_spoiler: hasSpoiler,
}),
});
}

export async function deleteCommentRequest(id: number, accessToken: string) {
return fetch(`${BASE_API_URL}/comments/${id}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + accessToken,
},
credentials: "include",
});
}

export async function getCommentReplies(commentId: number) {
return fetch(`${BASE_API_URL}/comments/${commentId}/replies`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
});
}
76 changes: 76 additions & 0 deletions src/apis/content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { BASE_API_URL } from "./const";

// 아직 영화리스트가 없어서 받아보기 어려움
// type은 추후에 enum으로 수정
export async function getContentListRequest(order: string) {
return fetch(`${BASE_API_URL}/contents?order=${order}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
});
}

export async function getContentRequest(movieCD: string, accessToken?: string) {
const headers: HeadersInit = accessToken
? {
"Content-Type": "application/json",
Authorization: "Bearer " + accessToken,
}
: {
"Content-Type": "application/json",
};
return fetch(`${BASE_API_URL}/contents/${movieCD}`, {
method: "GET",
headers,
// credentials: "include",
});
}

export async function createRatingRequest(
movieCD: string,
rate: number,
accessToken: string
) {
return fetch(`${BASE_API_URL}/contents/${movieCD}/rate`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + accessToken,
},
credentials: "include",
body: JSON.stringify({
rate,
}),
});
}

export async function updateRatingRequest(
rateId: number,
rate: number,
accessToken: string
) {
return fetch(`${BASE_API_URL}/contents/rates/${rateId}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + accessToken,
},
credentials: "include",
body: JSON.stringify({
rate,
}),
});
}

export async function deleteRatingRequest(rateId: number, accessToken: string) {
return fetch(`${BASE_API_URL}/contents/rates/${rateId}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + accessToken,
},
credentials: "include",
});
}
36 changes: 18 additions & 18 deletions src/apis/user.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// 모두가 접근 가능한 유저페이지에 대한 api
import { BASE_API_URL } from "./const";

export async function getUserDetail(id: number) {
return fetch(`${BASE_API_URL}/users/${id}/`);
export async function getUserDetail(userId: number) {
return fetch(`${BASE_API_URL}/users/${userId}/`);
}

export async function getFollowingList(id: number) {
return fetch(`${BASE_API_URL}/users/${id}/followings/`);
export async function getFollowingList(userId: number) {
return fetch(`${BASE_API_URL}/users/${userId}/followings/`);
}
export async function getFollowerList(id: number) {
return fetch(`${BASE_API_URL}/users/${id}/followers/`);
export async function getFollowerList(userId: number) {
return fetch(`${BASE_API_URL}/users/${userId}/followers/`);
}

export async function postAddFollow(accessToken: string, id: number) {
export async function postAddFollow(accessToken: string, userId: number) {
return fetch(`${BASE_API_URL}/users/add/follow/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify({ user_id: id }),
body: JSON.stringify({ user_id: userId }),
});
}

Expand All @@ -41,24 +41,24 @@ export async function getUserLikesComments(id: number) {
}

export async function getUserWrittenComments(
id: number,
query: "like" | "created" | "high-rating" | "low-rating" | undefined,
userId: number,
query?: "like" | "created" | "high-rating" | "low-rating"
) {
if (query === undefined) {
return fetch(`${BASE_API_URL}/users/${id}/comments/`);
return fetch(`${BASE_API_URL}/users/${userId}/comments/`);
}

return fetch(`${BASE_API_URL}/users/${id}/comments/?order=${query}`);
return fetch(`${BASE_API_URL}/users/${userId}/comments/?order=${query}`);
}

export async function getUserRatings(id: number) {
return fetch(`${BASE_API_URL}/users/${id}/ratings/`);
export async function getUserRatings(userId: number) {
return fetch(`${BASE_API_URL}/users/${userId}/ratings/`);
}
export async function getUserDoings(id: number) {
return fetch(`${BASE_API_URL}/users/${id}/movies/watching/`);
export async function getUserDoings(userId: number) {
return fetch(`${BASE_API_URL}/users/${userId}/movies/watching/`);
}
export async function getUserWishes(id: number) {
return fetch(`${BASE_API_URL}/users/${id}/movies/want_to_watch/`);
export async function getUserWishes(userId: number) {
return fetch(`${BASE_API_URL}/users/${userId}/movies/want_to_watch/`);
}

/*
Expand Down
Loading

0 comments on commit dca2178

Please sign in to comment.