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

Feat: 401 인증정보 오류 페이지 #81

Merged
merged 6 commits into from
Oct 2, 2024
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
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