Skip to content

Commit

Permalink
Merge pull request #81 from TEAM-Hearus/feat/401-page
Browse files Browse the repository at this point in the history
Feat: 401 ์ธ์ฆ์ •๋ณด ์˜ค๋ฅ˜ ํŽ˜์ด์ง€
  • Loading branch information
Nangniya authored Oct 2, 2024
2 parents a9e9fd8 + e10259f commit 26e4749
Show file tree
Hide file tree
Showing 29 changed files with 361 additions and 268 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 60 additions & 67 deletions src/apis/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,30 @@ interface IGetScheduleObject {

export const getSchedule = async (
name: string,
): Promise<IScheduleElement[]> => {
retryCount: number = 0, // ๋ฌดํ•œ ๋ฃจํ”„ ๋ฐฉ์ง€
): Promise<IGetScheduleResponse> => {
const MAX_RETRIES = 1;
const token = getToken();
try {
const res = await fetch(
`${API_URL}/api/v1/schedule/getSchedule?name=${name}`,
{
headers: {
Authorization: `Bearer ${token}`,
},
const res = await fetch(
`${API_URL}/api/v1/schedule/getSchedule?name=${name}`,
{
headers: {
Authorization: `Bearer ${token}`,
},
);
const data: IGetScheduleResponse = await res.json();
if (data.msg === 'Schedule not found with name') {
await createNewScheduleName(name);
return getSchedule(name);
},
);
const data: IGetScheduleResponse = await res.json();
// userName์œผ๋กœ ๋œ ์‹œ๊ฐ„ํ‘œ๊ฐ€ ์—†์„ ๊ฒฝ์šฐ ๋งŒ๋“ค๊ณ  ์žฌ๊ท€ ํ˜ธ์ถœ
if (data.msg === 'Schedule not found with name') {
if (retryCount >= MAX_RETRIES) {
throw new Error(
'Maximum retry limit reached. Unable to create schedule.',
);
}
return data.object['scheduleElements'];
} catch (error) {
throw error;
await createNewScheduleName(name);
return getSchedule(name, retryCount + 1);
}
return data;
};

interface IGetLectureByScheduleElementResponse
Expand All @@ -50,20 +54,16 @@ interface ILectureItem {

export const getLectureByScheduleElement = async (id: number) => {
const token = getToken();
try {
const res = await fetch(
`${API_URL}/api/v1/lecture/getLectureByScheduleElement?scheduleElementId=${id}`,
{
headers: {
Authorization: `Bearer ${token}`,
},
const res = await fetch(
`${API_URL}/api/v1/lecture/getLectureByScheduleElement?scheduleElementId=${id}`,
{
headers: {
Authorization: `Bearer ${token}`,
},
);
const data: IGetLectureByScheduleElementResponse = await res.json();
return data.object;
} catch (error) {
throw error;
}
},
);
const data: IGetLectureByScheduleElementResponse = await res.json();
return data;
};

interface IPOSTScheduleElementResponse extends IApiResponse<null> {}
Expand All @@ -73,55 +73,48 @@ export const addScheduleElement = async (
name: string,
) => {
const token = getToken();
try {
const res = await fetch(`${API_URL}/api/v1/schedule/addElement`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
const res = await fetch(`${API_URL}/api/v1/schedule/addElement`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
scheduleDTO: {
name,
},
body: JSON.stringify({
scheduleDTO: {
name,
},
scheduleElementDTO: inputData,
}),
});
const data: IPOSTScheduleElementResponse = await res.json();
return data.success;
} catch (error) {
throw error;
}
scheduleElementDTO: inputData,
}),
});
const data: IPOSTScheduleElementResponse = await res.json();
return data;
};

export const deleteScheduleElement = async (
scheduleElementId: number,
name: string,
) => {
const token = getToken();
try {
const res = await fetch(`${API_URL}/api/v1/schedule/deleteElement`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
const res = await fetch(`${API_URL}/api/v1/schedule/deleteElement`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
scheduleDTO: {
name,
},
body: JSON.stringify({
scheduleDTO: {
name,
},
scheduleElementDTO: {
id: scheduleElementId,
},
}),
});
const data: IPOSTScheduleElementResponse = await res.json();
return data.success;
} catch (error) {
throw error;
}
scheduleElementDTO: {
id: scheduleElementId,
},
}),
});
const data: IPOSTScheduleElementResponse = await res.json();
return data;
};

/** ํ˜„์žฌ๋Š” ์‹œ๊ฐ„ํ‘œ ์กฐํšŒํ• ๋•Œ userName์œผ๋กœ ๋œ ์‹œ๊ฐ„ํ‘œ ์—†์„ ๋•Œ๋งŒ ์“ฐ์ž„. */
const createNewScheduleName = async (name: string) => {
const token = getToken();
try {
Expand Down
42 changes: 17 additions & 25 deletions src/apis/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,27 @@ interface IScriptDetail {
processedScript: string[];
}

export const getAllScripts = async (): Promise<IScriptInList[]> => {
export const getAllScripts = async (): Promise<IGetAllScriptResponse> => {
const token = getToken();
try {
const res = await fetch(`${API_URL}/api/v1/lecture/getAllLecture`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
const data: IGetAllScriptResponse = await res.json();
return data.object;
} catch (error) {
throw error;
}
const res = await fetch(`${API_URL}/api/v1/lecture/getAllLecture`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
const data: IGetAllScriptResponse = await res.json();
return data;
};

export const getScriptDetail = async (id: string) => {
const token = getToken();
try {
const res = await fetch(
`${API_URL}/api/v1/lecture/getLecture?lectureId=${id}`,
{
headers: {
Authorization: `Bearer ${token}`,
},
const res = await fetch(
`${API_URL}/api/v1/lecture/getLecture?lectureId=${id}`,
{
headers: {
Authorization: `Bearer ${token}`,
},
);
const data: IGetScriptDetailResponse = await res.json();
return data.object;
} catch (error) {
throw error;
}
},
);
const data: IGetScriptDetailResponse = await res.json();
return data;
};
24 changes: 10 additions & 14 deletions src/apis/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@ export interface IProblemInput {

export const generateProblem = async (inputData: IProblemInput) => {
const token = getToken();
try {
const res = await fetch(`${API_URL}/api/v1/lecture/generateProblems`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(inputData),
});
const data: IGenerateProblemResponse = await res.json();
return data;
} catch (error) {
throw error;
}
const res = await fetch(`${API_URL}/api/v1/lecture/generateProblems`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(inputData),
});
const data: IGenerateProblemResponse = await res.json();
return data;
};
88 changes: 38 additions & 50 deletions src/apis/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,13 @@ export interface IUserSupplementaryUpdateInfo {

export const getUserInfo = async () => {
const token = getToken();
try {
const res = await fetch(`${API_URL}/api/v1/user/present-user`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
const data: IGetUserInfoResponse = await res.json();
return data.object;
} catch (error) {
throw error;
}
const res = await fetch(`${API_URL}/api/v1/user/present-user`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
const data: IGetUserInfoResponse = await res.json();
return data;
};

export const updateInfo = async ({
Expand All @@ -58,50 +54,42 @@ export const updateInfo = async ({
userGrade,
}: IUserUpdateInfo) => {
const token = getToken();
try {
const res = await fetch(`${API_URL}/api/v1/user/updateUser`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
userName,
userPassword,
userSchool,
userMajor,
userGrade,
}),
});
const data: IUpdateUserInfoResponse = await res.json();
return data.object;
} catch (error) {
throw error;
}
const res = await fetch(`${API_URL}/api/v1/user/updateUser`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
userName,
userPassword,
userSchool,
userMajor,
userGrade,
}),
});
const data: IUpdateUserInfoResponse = await res.json();
return data;
};

export const SupplementaryUpdateInfo = async ({
export const updateSupplementaryInfo = async ({
userSchool,
userMajor,
userGrade,
}: IUserSupplementaryUpdateInfo) => {
const token = getToken();
try {
const res = await fetch(`${API_URL}/api/v1/user/updateUser`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
userSchool,
userMajor,
userGrade,
}),
});
const data: ISupplementaryUpdateInfoResponse = await res.json();
return data.object;
} catch (error) {
throw error;
}
const res = await fetch(`${API_URL}/api/v1/user/updateUser`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
userSchool,
userMajor,
userGrade,
}),
});
const data: ISupplementaryUpdateInfoResponse = await res.json();
return data;
};
Binary file added src/assets/images/401image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/components/atoms/HighlightedText/HighlightedText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ const HighlightedText = ({ text, isPreview }: IProps) => {
if (index % 2 === 0) {
return part;
} else {
return <span className={styles.highlight}>{part}</span>;
return (
<span key={`${part}-${index}`} className={styles.highlight}>
{part}
</span>
);
}
})}
</p>
Expand Down
Loading

0 comments on commit 26e4749

Please sign in to comment.