-
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.
Merge pull request #23 from MARU-EGG/admin-questions-answer-table
[Admin] Refactor: all admin page
- Loading branch information
Showing
19 changed files
with
585 additions
and
102 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,24 @@ | ||
import { server_axiosInstance } from '../utils/axios'; | ||
import { getCookie } from '../utils/cookies'; | ||
|
||
interface AdminCheckQuestionAnswerProps { | ||
questionId: number; | ||
check: boolean; | ||
} | ||
export async function AdminCheckQuestionAnswer({ questionId, check }: AdminCheckQuestionAnswerProps) { | ||
const data = { | ||
questionId, | ||
check, | ||
}; | ||
try { | ||
const response = await server_axiosInstance.post('/api/admin/questions/check', JSON.stringify(data), { | ||
headers: { | ||
Authorization: `Bearer ${getCookie('accessToken')}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
return response.data; | ||
} catch (error: any) { | ||
throw new Error('checked failed'); | ||
} | ||
} |
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,22 @@ | ||
import { server_axiosInstance } from '../utils/axios'; | ||
import { getCookie } from '../utils/cookies'; | ||
|
||
export async function AdminEditAnswer(id: number, content: string): Promise<any> { | ||
const data = { | ||
id, | ||
content, | ||
}; | ||
|
||
try { | ||
const response = await server_axiosInstance.post('/api/admin/answers', JSON.stringify(data), { | ||
headers: { | ||
Authorization: `Bearer ${getCookie('accessToken')}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
console.log(response.data); | ||
return response.data; | ||
} catch (error: any) { | ||
throw new Error('Post Failed'); | ||
} | ||
} |
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,34 +1,30 @@ | ||
import axios from 'axios'; | ||
import useSWR, { mutate } from 'swr'; | ||
import { server_axiosInstance } from '../utils/axios'; | ||
import { getCookie, removeCookie, setCookie } from '../utils/cookies'; | ||
|
||
interface LoginResponse { | ||
token: string; | ||
user: { | ||
email: string; | ||
export async function AdminLogin(email: string, password: string) { | ||
const data = { | ||
email, | ||
password, | ||
}; | ||
} | ||
|
||
const fetcher = (url: string) => axios.get(url).then((res) => res.data); | ||
try { | ||
if (getCookie('accessToken')) { | ||
removeCookie('accessToken'); | ||
removeCookie('refreshToken'); | ||
} | ||
|
||
export async function login(email: string, password: string): Promise<LoginResponse> { | ||
const response = await axios.post<LoginResponse>('경로변경넣어야됌', { email, password }, { withCredentials: true }); | ||
return response.data; | ||
} | ||
const response = await server_axiosInstance.post('/api/auth/sign-in', data); | ||
const accessToken: string = response.headers['authorization']; | ||
const refreshToken: string = response.headers['authorization-refresh']; | ||
|
||
export function useUser() { | ||
const { data, error } = useSWR<LoginResponse>('경로넣어야행', fetcher); | ||
return { | ||
user: data, | ||
isLoading: !error && !data, | ||
isError: error, | ||
}; | ||
setCookie('accessToken', accessToken.split(' ')[1], { path: '/admin', secure: true, sameSite: 'lax' }); | ||
setCookie('refreshToken', refreshToken.split(' ')[1], { path: '/admin', secure: true, sameSite: 'lax' }); | ||
} catch (error: any) { | ||
throw new Error('Login Failed - Server network failed'); | ||
} | ||
} | ||
|
||
export async function handleLogin(email: string, password: string): Promise<void> { | ||
try { | ||
const userData = await login(email, password); | ||
mutate('경로헤헿콩', userData, false); | ||
} catch (err: any) { | ||
throw new Error(err.message); | ||
} | ||
export function AdminLogout() { | ||
removeCookie('accessToken', { path: '/admin', secure: true, sameSite: 'lax' }); | ||
removeCookie('refreshToken', { path: '/admin', secure: true, sameSite: 'lax' }); | ||
} |
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,20 @@ | ||
import { server_axiosInstance } from '../utils/axios'; | ||
|
||
interface AdminQuestionCheckProps { | ||
type: string; | ||
category?: string; | ||
} | ||
|
||
export async function adminQuestionCheck({ type, category }: AdminQuestionCheckProps) { | ||
try { | ||
const response = await server_axiosInstance.get('/api/questions', { | ||
params: { | ||
type, | ||
category, | ||
}, | ||
}); | ||
return response.data; | ||
} catch (error: any) { | ||
throw new Error(`Upload failed: ${error.message}`); | ||
} | ||
} |
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,20 @@ | ||
import { llm_axiosInstance } from '../utils/axios'; | ||
|
||
interface AdminRetrieveFileProps { | ||
type?: string; | ||
category?: string; | ||
} | ||
|
||
export async function adminRetrieveFile({ type, category }: AdminRetrieveFileProps) { | ||
try { | ||
const response = await llm_axiosInstance.get('/retrieve_documents_by_type_and_category', { | ||
params: { | ||
type, | ||
category, | ||
}, | ||
}); | ||
return response.data; | ||
} catch (error: any) { | ||
throw new Error(`Upload failed: ${error.message}`); | ||
} | ||
} |
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 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
Oops, something went wrong.