-
Notifications
You must be signed in to change notification settings - Fork 40
[윤예지] Sprint10 #316
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
The head ref may contain hidden characters: "Next-\uC724\uC608\uC9C0-sprint10"
[윤예지] Sprint10 #316
Changes from all commits
312ae98
4ce3670
bef94ae
f27228d
1222054
40586dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| NEXT_PUBLIC_ACCESS_TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NDkzLCJzY29wZSI6ImFjY2VzcyIsImlhdCI6MTczMzU2NzgwMywiZXhwIjoxNzMzNTY5NjAzLCJpc3MiOiJzcC1wYW5kYS1tYXJrZXQifQ.15l2pH_P-kh0tMemBn521wnFwugH38QssNljRzNa3Qo" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import axios, { AxiosResponse } from 'axios'; | ||
| import axiosInstance from './axios'; | ||
|
|
||
| interface GetCommentResultResponse { | ||
| list: Comment[]; | ||
| nextCursor: string; | ||
| } | ||
|
|
||
| interface CreateCommentResultResponse {} | ||
|
|
||
| // -- Comment API | ||
| export const getComment = async ( | ||
| productId: number, | ||
| params: {}, | ||
| ): Promise<AxiosResponse<GetCommentResultResponse>> => { | ||
|
Comment on lines
+12
to
+15
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이런 함수 파라미터를 작성할 땐 일반적으로 객체로 받는 것이 좋습니다. 객체로 작성하게 되면 아래 장점이 있어요.
|
||
| try { | ||
| return await axiosInstance.get(`/products/${productId}/comments`, { | ||
| params: { | ||
| productId: productId, | ||
| limit: 10, | ||
| cursor: null, | ||
| ...params, | ||
| }, | ||
| }); | ||
| } catch (error) { | ||
| if (axios.isAxiosError(error)) { | ||
| console.error('Axios Error:', error.response?.data || error.message); | ||
| throw new Error('데이터를 불러오는도중 에러가 발생했습니다.'); | ||
| } else { | ||
| console.error('Unknown Error:', error); | ||
| throw new Error('기타 에러입니다.'); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| export const createComments = async ( | ||
| productId: number, | ||
| content: { content: string }, | ||
| ) => { | ||
| try { | ||
| return await axiosInstance.post( | ||
| `/products/${productId}/comments`, | ||
| content, | ||
| { | ||
| headers: { | ||
| Authorization: `Bearer ${process.env.NEXT_PUBLIC_ACCESS_TOKEN}`, | ||
| }, | ||
| }, | ||
| ); | ||
| } catch (error) { | ||
| if (axios.isAxiosError(error)) { | ||
| console.error('Axios Error:', error.response?.data || error.message); | ||
| throw new Error('데이터를 불러오는도중 에러가 발생했습니다.'); | ||
| } else { | ||
| console.error('Unknown Error:', error); | ||
| throw new Error('기타 에러입니다.'); | ||
| } | ||
| } | ||
| }; | ||
|
Comment on lines
+25
to
+59
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지금 보면 아래 에러 처리 코드가 동일하게 반복되는데요. 이런 경우 별도 함수로 분리해볼 수 있는 방법이 있어요. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import axios, { AxiosResponse } from 'axios'; | ||
| import axiosInstance from './axios'; | ||
|
|
||
| interface UploadImageResponse { | ||
| url: string; | ||
| } | ||
|
|
||
| export const uploadImage = async ( | ||
| file: File, | ||
| ): Promise<UploadImageResponse | undefined> => { | ||
| const formData = new FormData(); | ||
| formData.append('image', file); | ||
|
|
||
| try { | ||
| const response: AxiosResponse = await axiosInstance.post( | ||
| '/images/upload', | ||
| formData, | ||
| { | ||
| headers: { | ||
| 'Content-Type': 'multipart/form-data', | ||
| Authorization: `Bearer ${process.env.NEXT_PUBLIC_ACCESS_TOKEN}`, | ||
| }, | ||
| }, | ||
| ); | ||
| console.log('파일 업로드 성공:', response.data); | ||
| return response.data; | ||
| } catch (error: unknown) { | ||
| if (axios.isAxiosError(error)) { | ||
| console.error('파일 업로드 실패:', error.response?.data || error.message); | ||
| } else { | ||
| console.error('알 수 없는 오류 발생:', error); | ||
| } | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| .comment { | ||
| padding-top: 4rem; | ||
| border-bottom: 1px solid #e5e7eb; | ||
| background-color: #fcfcfc; | ||
| } | ||
|
|
||
| .comment-top { | ||
| display: flex; | ||
| justify-content: space-between; | ||
| } | ||
|
|
||
| .content { | ||
| font-weight: 400; | ||
| font-size: 1.4rem; | ||
| line-height: 2.4rem; | ||
| color: #1f2937; | ||
| } | ||
|
|
||
| .comment-bottom { | ||
| padding: 2.4rem 1.2rem; | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.8rem; | ||
| } | ||
|
|
||
| .profile { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 0.4em; | ||
| } | ||
|
|
||
| .nickName { | ||
| font-weight: 400; | ||
| font-size: 1.2rem; | ||
| line-height: 1.8rem; | ||
| color: #4b5563; | ||
| } | ||
|
|
||
| .date { | ||
| font-weight: 400; | ||
| font-size: 1.2rem; | ||
| line-height: 1.8rem; | ||
| color: #9ca3af; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import Image from 'next/image'; | ||
| import React from 'react'; | ||
| import profile from '@/public/profile.svg'; | ||
| import Iconkebab from '@/public/ic_kebab.svg'; | ||
| import styles from './Comment.module.css'; | ||
|
|
||
| interface Writer { | ||
| image: string; | ||
| nickname: string; | ||
| id: number; | ||
| } | ||
|
|
||
| export interface Comment { | ||
| writer: Writer; | ||
| updatedAt: string; | ||
| createdAt: string; | ||
| content: string; | ||
| id: number; | ||
| } | ||
|
|
||
| export interface CommentProps { | ||
| comment: Comment; | ||
| } | ||
|
|
||
| const Comment: React.FC<CommentProps> = ({ comment }) => { | ||
| return ( | ||
| <div className={styles.comment}> | ||
| <div className={styles['comment-top']}> | ||
| <div className={styles.content}>{comment.content}</div> | ||
| <Image src={Iconkebab} alt=""></Image> | ||
| </div> | ||
| <div className={styles['comment-bottom']}> | ||
| <div> | ||
| <Image | ||
| src={profile} | ||
| width={24} | ||
| height={24} | ||
| alt="프로파일이미지" | ||
| ></Image> | ||
| </div> | ||
| <div className={styles.profile}> | ||
| <div className={styles.nickName}>{comment.writer.nickname}</div> | ||
| <div className={styles.date}>{comment.createdAt}</div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
|
Comment on lines
+25
to
+49
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UI 분리되게 잘 작성하셨어요! Image에 alt 값만 넣어주세요~ |
||
| export default Comment; | ||
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.