Skip to content
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

πŸ”€ κ΄€λ¦¬μž ν”„λ‘œν•„ 뢈러였기 #89

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/app/api/admin/my/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { AxiosError } from 'axios';
import { cookies } from 'next/headers';
import { NextResponse } from 'next/server';
import { apiClient } from '@/shared/libs/apiClient';

export async function GET() {
const cookieStore = cookies();
const accessToken = cookieStore.get('accessToken')?.value;

Comment on lines +7 to +9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

토큰 μœ νš¨μ„± 검사 μΆ”κ°€ ν•„μš”

accessToken이 μ—†λŠ” κ²½μš°μ— λŒ€ν•œ μ²˜λ¦¬κ°€ λˆ„λ½λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

λ‹€μŒκ³Ό 같이 μˆ˜μ •ν•˜λŠ” 것을 μ œμ•ˆν•©λ‹ˆλ‹€:

   const cookieStore = cookies();
   const accessToken = cookieStore.get('accessToken')?.value;
+  
+  if (!accessToken) {
+    return NextResponse.json(
+      { error: '인증 토큰이 μ—†μŠ΅λ‹ˆλ‹€.' },
+      { status: 401 }
+    );
+  }
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const cookieStore = cookies();
const accessToken = cookieStore.get('accessToken')?.value;
const cookieStore = cookies();
const accessToken = cookieStore.get('accessToken')?.value;
if (!accessToken) {
return NextResponse.json(
{ error: '인증 토큰이 μ—†μŠ΅λ‹ˆλ‹€.' },
{ status: 401 }
);
}

try {
const response = await apiClient.get('/admin/my', {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
return NextResponse.json(response.data, { status: response.status });
} catch (error) {
const axiosError = error as AxiosError<{ message: string }>;
const status = axiosError.response?.status || 500;
const message =
axiosError.response?.data?.message || 'admin data get failed';
return NextResponse.json({ error: message }, { status });
}
}
9 changes: 5 additions & 4 deletions src/entities/admin/ui/AdminProfile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import { Logout } from '@/shared/assets/icons';
import { AdminData } from '@/shared/types/admin/type';
import { useDeleteUserAccount } from '../../model/useDeleteUserAccount';
import { useLogout } from '../../model/useLogout';

Expand All @@ -10,7 +11,7 @@ const ProfileInfo = ({ label, value }: { label: string; value: string }) => (
</div>
);

const AdminProfile = () => {
const AdminProfile = ({ data }: { data: AdminData }) => {
const { mutate: logout } = useLogout();
const { mutate: deleteAccount } = useDeleteUserAccount();
const [isToggleLogout, setIsToggleLogout] = useState(false);
Expand All @@ -23,9 +24,9 @@ const AdminProfile = () => {
<div className="relative flex w-full justify-between">
<div className="flex items-center gap-[124px] mobile:flex-col mobile:gap-[30px]">
<div className="space-y-[32px]">
<ProfileInfo label="이름" value="김진원" />
<ProfileInfo label="아이디" value="jin1234" />
<ProfileInfo label="이메일" value="[email protected]" />
<ProfileInfo label="이름" value={data.name} />
<ProfileInfo label="아이디" value={data.nickname} />
<ProfileInfo label="이메일" value={data.email} />
</div>
</div>
<div>
Expand Down
5 changes: 5 additions & 0 deletions src/shared/types/admin/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ export interface SignUpItem extends Record<string, unknown> {
email: string;
phoneNumber: string;
}
export interface AdminData {
name: string;
nickname: string;
email: string;
}
7 changes: 6 additions & 1 deletion src/widgets/admin/api/getAdminData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import { ExpoItem, SignUpItem } from '@/shared/types/admin/type';
import { AdminData, ExpoItem, SignUpItem } from '@/shared/types/admin/type';

export const getExpoList = async (): Promise<ExpoItem[]> => {
const response = await axios.get('/api/expo');
Expand All @@ -10,3 +10,8 @@ export const getRequestSignUp = async (): Promise<SignUpItem[]> => {
const response = await axios.get('/api/admin');
return response.data;
};

export const getAdminData = async (): Promise<AdminData> => {
const response = await axios.get('/api/admin/my');
return response.data;
};
Comment on lines +14 to +17
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

μ—λŸ¬ 처리 둜직 μΆ”κ°€ ν•„μš”

API 호좜 μ‹€νŒ¨ μ‹œμ˜ μ—λŸ¬ μ²˜λ¦¬κ°€ λˆ„λ½λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. try-catch 블둝을 μΆ”κ°€ν•˜μ—¬ μ—λŸ¬λ₯Ό 적절히 μ²˜λ¦¬ν•΄ μ£Όμ„Έμš”.

λ‹€μŒκ³Ό 같이 μˆ˜μ •ν•˜λŠ” 것을 μ œμ•ˆν•©λ‹ˆλ‹€:

 export const getAdminData = async (): Promise<AdminData> => {
-  const response = await axios.get('/api/admin/my');
-  return response.data;
+  try {
+    const response = await axios.get('/api/admin/my');
+    return response.data;
+  } catch (error) {
+    console.error('κ΄€λ¦¬μž 데이터 쑰회 μ‹€νŒ¨:', error);
+    throw error;
+  }
 };
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const getAdminData = async (): Promise<AdminData> => {
const response = await axios.get('/api/admin/my');
return response.data;
};
export const getAdminData = async (): Promise<AdminData> => {
try {
const response = await axios.get('/api/admin/my');
return response.data;
} catch (error) {
console.error('κ΄€λ¦¬μž 데이터 쑰회 μ‹€νŒ¨:', error);
throw error;
}
};

20 changes: 16 additions & 4 deletions src/widgets/admin/model/useAdminData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { useQuery } from '@tanstack/react-query';
import { ExpoItem, SignUpItem } from '@/shared/types/admin/type';
import { getExpoList, getRequestSignUp } from '../api/getAdminData';
import { AdminData, ExpoItem, SignUpItem } from '@/shared/types/admin/type';
import {
getAdminData,
getExpoList,
getRequestSignUp,
} from '../api/getAdminData';

export const useAdminData = () => {
const expoListData = useQuery<ExpoItem[], Error>({
Expand All @@ -13,7 +17,15 @@ export const useAdminData = () => {
queryFn: getRequestSignUp,
});

const isLoading = expoListData.isLoading || requestSignUpData.isLoading;
const requestAdminData = useQuery<AdminData, Error>({
queryKey: ['requestAdnubData'],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

쿼리 ν‚€μ˜ μ˜€νƒ€λ₯Ό μˆ˜μ •ν•΄ μ£Όμ„Έμš”

'requestAdnubData'에 μ˜€νƒ€κ°€ μžˆμŠ΅λ‹ˆλ‹€.

λ‹€μŒκ³Ό 같이 μˆ˜μ •ν•˜λŠ” 것을 μ œμ•ˆν•©λ‹ˆλ‹€:

-    queryKey: ['requestAdnubData'],
+    queryKey: ['requestAdminData'],
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
queryKey: ['requestAdnubData'],
queryKey: ['requestAdminData'],

queryFn: getAdminData,
});

const isLoading =
expoListData.isLoading ||
requestSignUpData.isLoading ||
requestAdminData.isLoading;

return { expoListData, requestSignUpData, isLoading };
return { expoListData, requestSignUpData, requestAdminData, isLoading };
};
6 changes: 4 additions & 2 deletions src/widgets/admin/ui/AdminPageWrapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
import { useAdminData } from '../../model/useAdminData';

const AdminPageWrapper = () => {
const { expoListData, requestSignUpData, isLoading } = useAdminData();
const { expoListData, requestSignUpData, requestAdminData, isLoading } =
useAdminData();

const checkSignupActions = checkActions(async () => {
await requestSignUpData.refetch();
Expand All @@ -22,12 +23,13 @@ const AdminPageWrapper = () => {

const expoList = expoListData.data || [];
const requestSignUp = requestSignUpData.data || [];
const requestAdmin = requestAdminData.data;

return withLoading({
isLoading,
children: (
<div className="space-y-[73px]">
<AdminProfile />
{requestAdmin && <AdminProfile data={requestAdmin} />}
<div className="space-y-[26px]">
<p className="text-h2 text-black">νšŒμ›κ°€μž… μš”μ²­</p>
<div className="h-auto">
Expand Down