Skip to content

Commit

Permalink
Fe/dev2 (#87)
Browse files Browse the repository at this point in the history
* WIP: 깃허브 로그인 중

* WIP: 깃허브 로그인

* feat: 로컬 스토리지 토큰 읽어오기

* feat: authorization 추가

* fix: authorization 변수에 할당하여 지정
  • Loading branch information
minjeongHEO authored May 30, 2024
1 parent c8c2ba1 commit af5a62c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
13 changes: 9 additions & 4 deletions FE/src/api/fetchFilterData.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
* @returns {jsonObject}
*/
export const fetchLabelsData = async () => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${LABELS_API_URI}`, {
headers: {
Authorization: `Bearer ${getAccessToken()}`,
Authorization: `Bearer ${accessToken}`,
},
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
Expand All @@ -31,10 +32,11 @@ export const fetchLabelsData = async () => {
* @returns {jsonObject}
*/
export const fetchMembersData = async () => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${MEMBERS_API_URI}`, {
headers: {
Authorization: `Bearer ${getAccessToken()}`,
Authorization: `Bearer ${accessToken}`,
},
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
Expand All @@ -53,12 +55,13 @@ export const fetchMembersData = async () => {
* @returns {jsonObject}
*/
export const fetchMilestonesData = async (isClosed) => {
const accessToken = getAccessToken();
try {
// await delay(5000);

const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${MILESTONES_API_URI}${isClosed}`, {
headers: {
Authorization: `Bearer ${getAccessToken()}`,
Authorization: `Bearer ${accessToken}`,
},
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
Expand All @@ -80,7 +83,9 @@ export const fetchMilestonesData = async (isClosed) => {
* @param {*String} userId
* @returns {jsonObject}
*/

export const fetchIssueListData = async (isClosedParam, authorIdParam, assigneeIdParam, labelIdParam, milestoneNameParam, noValuesParam) => {
const accessToken = getAccessToken();
const isClosed = isClosedParam ?? '';
const authorId = authorIdParam ?? '';
const assigneeId = assigneeIdParam ?? '';
Expand All @@ -95,7 +100,7 @@ export const fetchIssueListData = async (isClosedParam, authorIdParam, assigneeI
}${ISSUE_LIST_API_URI}?isClosed=${isClosed}&authorId=${authorId}&assigneeId=${assigneeId}&labelName=${labelName}&milestoneName=${milestoneNameParam}&noValues=${noValues}`,
{
headers: {
Authorization: `Bearer ${getAccessToken()}`,
Authorization: `Bearer ${accessToken}`,
},
}
);
Expand Down
40 changes: 26 additions & 14 deletions FE/src/api/fetchIssueData.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const ISSUE_DEFAULT_FILE_URI = '/api/files';
*/
export const fetchIssueDetailData = async (issueId) => {
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

const accessToken = getAccessToken();
try {
// await delay(2000);
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_API_URI}/${issueId}`, {
headers: {
Authorization: `Bearer ${getAccessToken()}`,
Authorization: `Bearer ${accessToken}`,
},
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
Expand All @@ -35,12 +35,13 @@ export const fetchIssueDetailData = async (issueId) => {
* @returns {}
*/
export const fetchIssueStateToggle = async (toIssueState, issueIds) => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_API_URI}/${toIssueState ? 'close' : 'open'}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify({ issueIds }),
});
Expand All @@ -66,12 +67,13 @@ export const fetchIssueStateToggle = async (toIssueState, issueIds) => {
*/
export const fetchDeleteIssue = async (issueId) => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_API_URI}/${issueId}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
'Authorization': `Bearer ${accessToken}`,
},
});

Expand All @@ -97,12 +99,13 @@ export const fetchDeleteIssue = async (issueId) => {
- 서버 내부 오류시: 500
*/
export const fetchModifyIssueTitle = async (title, issueId) => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_API_URI}/${issueId}/title`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify({ title }),
});
Expand All @@ -129,12 +132,13 @@ export const fetchModifyIssueTitle = async (title, issueId) => {
- 서버 내부 오류시: 500
*/
export const fetchModifyIssueContent = async (content, fileId, issueId) => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_API_URI}/${issueId}/body`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify({ content, fileId }),
});
Expand All @@ -161,12 +165,13 @@ export const fetchModifyIssueContent = async (content, fileId, issueId) => {
- 서버 내부 오류시: 500
*/
export const fetchModifyIssueComment = async (content, fileId, commentId) => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_COMMENTS_DEFAULT_API_URI}/${commentId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify({ content, fileId }),
});
Expand Down Expand Up @@ -194,12 +199,13 @@ export const fetchModifyIssueComment = async (content, fileId, commentId) => {
- 서버 내부 오류시: 500
*/
export const fetchCreateIssueComment = async (writerId, content, issueId, fileId) => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_COMMENTS_DEFAULT_API_URI}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify({ writerId, content, issueId, fileId }),
});
Expand All @@ -225,12 +231,13 @@ export const fetchCreateIssueComment = async (writerId, content, issueId, fileId
- 서버 내부 오류시: 500
*/
export const fetchDeleteComment = async (commentId) => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_COMMENTS_DEFAULT_API_URI}/${commentId}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
'Authorization': `Bearer ${accessToken}`,
},
});

Expand All @@ -256,12 +263,13 @@ export const fetchDeleteComment = async (commentId) => {
- 서버 내부 오류시: 500
*/
export const fetchModifyIssueLabels = async (issueId, labelIds) => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_API_URI}/${issueId}/label`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify({ labelIds }),
});
Expand All @@ -288,12 +296,13 @@ export const fetchModifyIssueLabels = async (issueId, labelIds) => {
- 서버 내부 오류시: 500
*/
export const fetchModifyIssueAssignees = async (issueId, assigneeIds) => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_API_URI}/${issueId}/assignee`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify({ assigneeIds }),
});
Expand All @@ -320,12 +329,13 @@ export const fetchModifyIssueAssignees = async (issueId, assigneeIds) => {
- 서버 내부 오류시: 500
*/
export const fetchModifyIssueMilestone = async (issueId, milestoneId) => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_API_URI}/${issueId}/milestone`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify({ milestoneId }),
});
Expand All @@ -352,11 +362,12 @@ export const fetchModifyIssueMilestone = async (issueId, milestoneId) => {
*/
//TODO: 파일 형식 미지원 시 에러 처리
export const fetchUploadFile = async (formData) => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_FILE_URI}`, {
method: 'POST',
headers: {
Authorization: `Bearer ${getAccessToken()}`,
Authorization: `Bearer ${accessToken}`,
},
body: formData,
});
Expand Down Expand Up @@ -386,13 +397,14 @@ export const fetchUploadFile = async (formData) => {
- 서버 내부 오류시: 500
*/
export const fetchCreateNewIssue = async (title, content, authorId, milestoneId, fileIdParam, labelIds, assigneeIds) => {
const accessToken = getAccessToken();
const fileId = fileIdParam || null;
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_API_URI}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify({ title, content, authorId, milestoneId, fileId, labelIds, assigneeIds }),
});
Expand Down
16 changes: 14 additions & 2 deletions FE/src/api/fetchLabelData.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
* - 성공: 200
*/
export const fetchLabelMilestoneCountData = async () => {
const accessToken = getAccessToken();
try {
// await delay(2000);
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${HOME_DEFAULT_API_URI}`, {
headers: {
Authorization: `Bearer ${getAccessToken()}`,
Authorization: `Bearer ${accessToken}`,
},
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
Expand All @@ -34,9 +35,14 @@ export const fetchLabelMilestoneCountData = async () => {
* @returns {jsonObject}
*/
export const fetchLabelDetailData = async () => {
const accessToken = getAccessToken();
try {
// await delay(2000);
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${LABEL_DEFAULT_API_URI}`);
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${LABEL_DEFAULT_API_URI}`, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);

if (response.status === 200 || response.status === 201) {
Expand All @@ -61,12 +67,14 @@ export const fetchLabelDetailData = async () => {
- 존재하지 않는 라벨 아이디: 404
*/
export const fetchModifyLabel = async (name, descriptionParam, textColor, bgColor, labelId) => {
const accessToken = getAccessToken();
const description = descriptionParam || null;
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${LABEL_DEFAULT_API_URI}/${labelId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify({ name, description, textColor, bgColor }),
});
Expand Down Expand Up @@ -94,11 +102,13 @@ export const fetchModifyLabel = async (name, descriptionParam, textColor, bgColo
- 존재하지 않는 라벨 아이디: 404
*/
export const fetchDeleteLabel = async (labelId) => {
const accessToken = getAccessToken();
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${LABEL_DEFAULT_API_URI}/${labelId}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${accessToken}`,
},
});

Expand Down Expand Up @@ -126,12 +136,14 @@ export const fetchDeleteLabel = async (labelId) => {
- 라벨 이름 중복: 409
*/
export const fetchCreateNewLabel = async (name, descriptionParam, textColor, bgColor) => {
const accessToken = getAccessToken();
const description = descriptionParam || null;
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${LABEL_DEFAULT_API_URI}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify({ name, description, textColor, bgColor }),
});
Expand Down

0 comments on commit af5a62c

Please sign in to comment.