Skip to content

Commit

Permalink
�v2.6.0
Browse files Browse the repository at this point in the history
�v2.6.0
  • Loading branch information
yougyung authored Dec 19, 2023
2 parents 276b920 + c128dfb commit 7feba11
Show file tree
Hide file tree
Showing 50 changed files with 158 additions and 1,209 deletions.
2 changes: 0 additions & 2 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import cookieParser from 'cookie-parser';
import apiRouter from './router/api';
import ssrRouter from './router/ssr';


const __dirname = path.resolve();

const app = express();
Expand Down Expand Up @@ -38,7 +37,6 @@ app.use(express.static('public'));
app.use('/api', apiRouter);
app.use('/', ssrRouter);


app.listen(3000, () => {
console.log('listen to http://localhost:3000');
});
105 changes: 34 additions & 71 deletions server/router/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ const router = express.Router();

const upload = multer({ dest: '../uploads/' });

const DEFAULT_HOST = 'http://ec2-15-165-61-122.ap-northeast-2.compute.amazonaws.com';
const DEFAULT_HOST = 'http://52.79.66.109:8080';
const PREFIX = '/api/v1';
const ROOT_URL = DEFAULT_HOST + PREFIX;

export function getAuthorizationCookie(req) {
const accessToken = req.cookies.authorization;
if (accessToken === undefined) return 'null';
return accessToken;
return `Bearer ${accessToken}`;
}

export async function validateAccessToken(req) {
const accessToken = getAuthorizationCookie(req);
if (accessToken === undefined) return false;
try {
await axios.get(`${ROOT_URL}/auth/check-atk`, {
await axios.get(`${ROOT_URL}/auth/token`, {
headers: {
Authorization: accessToken,
},
Expand All @@ -46,22 +46,24 @@ export async function parsePDF(formData) {
return response.data;
}

export async function validateStudentNumber(formData) {
const response = await axios.post(`${ROOT_URL}/users/studentNumber-validity-checks`, formData);
return !response.data.isNotDuplicated;
export async function validateStudentNumber({ studentNumber }) {
const response = await axios.get(
`${ROOT_URL}/users/sign-up/check-duplicate-student-number?student-number=${studentNumber}`
);
return !response.data.notDuplicated;
}

export async function validateUserId(formData) {
const response = await axios.post(`${ROOT_URL}/users/userid-validity-checks`, formData);
return !response.data.isNotDuplicated;
export async function validateUserId({ userId }) {
const response = await axios.get(`${ROOT_URL}/users/sign-up/check-duplicate-auth-id?auth-id=${userId}`);
return !response.data.notDuplicated;
}

function apiErrorHandler(res, error) {
if (error.response.data.code) {
if (error.response?.data.status) {
return res.status(400).json(error.response.data);
}
return res.status(500).json({
code: 500,
status: 500,
message: '서버에 장애가 있습니다.',
});
}
Expand All @@ -72,10 +74,9 @@ router.post('/file-upload', upload.single('file'), async function (req, res) {

try {
const pdfText = await parsePDF(formData);

const accessToken = getAuthorizationCookie(req);
const response = await axios.post(
`${ROOT_URL}/users/me/taken-lectures`,
`${ROOT_URL}/parsing-text`,
{
parsingText: pdfText,
},
Expand All @@ -93,22 +94,16 @@ router.post('/file-upload', upload.single('file'), async function (req, res) {

router.post('/signin', async function (req, res) {
const formData = {
userId: req.body.id,
authId: req.body.authId,
password: req.body.password,
};

try {
const result = await axios.post(`${ROOT_URL}/auth/sign-in`, formData);
res.cookie('authorization', result.headers.authorization, {
res.cookie('authorization', `${result.data.accessToken}`, {
httpOnly: true,
});

const response = await axios.get(`${ROOT_URL}/users/me/init`, {
headers: {
Authorization: result.headers.authorization,
},
});
res.status(200).json({ isInit: response.data.init });
res.status(200).json({ isInit: false });
} catch (error) {
apiErrorHandler(res, error);
}
Expand All @@ -124,7 +119,7 @@ router.get('/signout', function (req, res) {

router.post('/signup', async function (req, res) {
const formData = {
userId: req.body.id,
authId: req.body.id,
password: req.body.password,
studentNumber: req.body.studentId,
engLv: req.body.englishLevel,
Expand All @@ -133,30 +128,28 @@ router.post('/signup', async function (req, res) {
try {
if (await validateUserId({ userId: req.body.id }))
return res.status(400).json({
code: 400,
status: 400,
message: '이미 아이디가 존재합니다.',
});

if (await validateStudentNumber({ studentNumber: req.body.studentId }))
return res.status(400).json({
code: 400,
status: 400,
message: '이미 등록된 학번입니다.',
});

const result = await axios.post(`${ROOT_URL}/auth/sign-up`, formData);
const result = await axios.post(`${ROOT_URL}/users/sign-up`, formData);
res.status(200).end();
} catch (error) {
apiErrorHandler(res, error);
}
});

router.post('/secession', async function (req, res) {
const formData = {
password: req.body.password,
};
const accessToken = getAuthorizationCookie(req);
try {
const result = await axios.post(`${ROOT_URL}/users/leave`, formData, {
const result = await axios.delete(`${ROOT_URL}/users/me`, {
data: { password: req.body.password },
headers: {
Authorization: accessToken,
},
Expand All @@ -169,11 +162,11 @@ router.post('/secession', async function (req, res) {

router.post('/userConfirm', async function (req, res) {
const formData = {
userId: req.body.id,
authId: req.body.authId,
studentNumber: req.body.studentNumber,
};
try {
await axios.post(`${ROOT_URL}/users/pwinquiry`, formData, {
await axios.get(`${ROOT_URL}/users/${formData.studentNumber}/validate?auth-id=${formData.authId}`, formData, {
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -195,7 +188,7 @@ router.get('/check-atk', async function (req, res) {
router.get('/takenLectures', async function (req, res) {
try {
const accessToken = getAuthorizationCookie(req);
const result = await axios.get(`${ROOT_URL}/users/me/taken-lectures`, {
const result = await axios.get(`${ROOT_URL}/taken-lectures`, {
headers: {
Authorization: accessToken,
},
Expand All @@ -205,26 +198,6 @@ router.get('/takenLectures', async function (req, res) {
apiErrorHandler(res, error);
}
});
router.get('/curriculumInfos', async function (req, res) {
try {
const lectureResult = await axios.get(`${ROOT_URL}/bachelor-info/lectures`, {
headers: {
'Content-Type': 'application/json',
},
params: req.query,
});
const creditResult = await axios.get(`${ROOT_URL}/bachelor-info/requirement`, {
headers: {
// Authorization: accessToken,
'Content-Type': 'application/json',
},
params: req.query,
});
res.json([creditResult.data, lectureResult.data]);
} catch (error) {
apiErrorHandler(res, error);
}
});

router.get('/search-lecture', async function (req, res) {
try {
Expand All @@ -236,7 +209,7 @@ router.get('/search-lecture', async function (req, res) {
params: req.query,
});
res.status(200).json({
searchedLectures: response.data,
searchedLectures: response.data.lectures,
});
} catch (error) {
apiErrorHandler(res, error);
Expand All @@ -251,7 +224,7 @@ router.post('/update-lecture', async function (req, res) {

try {
const accessToken = getAuthorizationCookie(req);
const result = await axios.patch(`${ROOT_URL}/users/me/taken-lectures`, formData, {
const result = await axios.post(`${ROOT_URL}/taken-lectures/update`, formData, {
headers: {
Authorization: accessToken,
},
Expand All @@ -268,11 +241,11 @@ router.get('/myInfo', async function (req, res) {
const accessToken = getAuthorizationCookie(req);
if (accessToken === 'null') {
res.status(500).json({
code: 500,
status: 500,
message: '서버에 장애가 있습니다.',
});
} else {
const result = await axios.get(`${ROOT_URL}/users/me/information`, {
const result = await axios.get(`${ROOT_URL}/users/me`, {
headers: {
Authorization: accessToken,
},
Expand Down Expand Up @@ -301,7 +274,7 @@ router.get('/graduation-result', async function (req, res) {
router.get('/findId', async function (req, res) {
try {
const path = req._parsedUrl.query;
const response = await axios.get(`${ROOT_URL}/users/by/student-number/${path}`, {
const response = await axios.get(`${ROOT_URL}/users/${path}/auth-id`, {
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -314,12 +287,12 @@ router.get('/findId', async function (req, res) {

router.post('/findPw', async function (req, res) {
const formData = {
userId: req.body.userId,
authId: req.body.authId,
newPassword: req.body.newPassword,
passwordCheck: req.body.passwordCheck,
};
try {
const result = await axios.post(`${ROOT_URL}/users/reset-pw`, formData);
const result = await axios.patch(`${ROOT_URL}/users/password`, formData);
res.status(200).end();
} catch (error) {
apiErrorHandler(res, error);
Expand All @@ -330,18 +303,8 @@ router.get('/check-user', async function (req, res) {
const accessToken = req.cookies.authorization;
if (accessToken === undefined) {
res.status(400).end();
} else {
try {
const response = await axios.get(`${ROOT_URL}/users/me/init`, {
headers: {
Authorization: accessToken,
},
});
res.status(200).json(response.data);
} catch (error) {
apiErrorHandler(res, error);
}
}
res.status(200).json({ validToken: true, init: false });
});

export default router;
25 changes: 6 additions & 19 deletions src/async/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ export async function fetchSignIn(formData) {

if (response.status === 200) {
signIn();
const result = await response.json();
if (result.isInit) {
init();
}
return true;
}

Expand Down Expand Up @@ -135,31 +131,22 @@ export async function fetchValidateATK() {
}

export async function fetchValidateUser() {
const response = await fetch('/api/check-user');
const response = await fetch('/api/myInfo');

if (response.status === 200) {
const result = await response.json();

if (result.validToken) {
signIn();
} else {
signOut();
}

if (result.init) {
if (!result.studentName) {
init();
} else {
unInit();
return { init: true };
}

return result;
unInit();
return { init: false };
}

signOut();
unInit();

return {
validToken: false,
init: false,
init: true,
};
}
1 change: 0 additions & 1 deletion src/async/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export async function fetchPDFFileUpload(formData) {
method: 'POST',
body: formData,
});

if (response.status === 400 || response.status === 500) {
throw await makeError(response);
}
Expand Down
19 changes: 1 addition & 18 deletions src/async/lecture.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function fetchGetSearchedLecture(query) {
if (response.status === 400 || response.status === 500) {
const result = await response.json();
const error = new Error(result.message);
error.code = result.code;
error.status = result.status;
throw error;
}

Expand Down Expand Up @@ -45,20 +45,3 @@ export async function fetchGetTakenLectures() {
const result = await response.json();
return result;
}

export async function fetchCurriculumInfos(query) {
const queryString = objectToQueryString(query);

const response = await fetch(`/api/curriculumInfos?${queryString}`, {
headers: {
'Content-Type': 'application/json',
},
});

if (response.status === 400 || response.status === 500) {
throw await makeError(response);
}
const result = await response.json();

return result;
}
4 changes: 0 additions & 4 deletions src/components/GNB/GNB.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default class GNB extends Component {
<div class="GNB__tab-navigator__general-item gnb-result">결과페이지</div>`
: `<div class="GNB__tab-navigator__general-item gnb-signin">로그인</div>`
}
<div class="GNB__tab-navigator__general-item gnb-curriculum">커리큘럼</div>
<div class="GNB__tab-navigator__general-item gnb-tutorial">튜토리얼</div>
<div class="GNB__tab-navigator__general-item gnb-about">팀소개</div>
</div>
Expand Down Expand Up @@ -94,9 +93,6 @@ export default class GNB extends Component {
this.addEvent('click', '.gnb-tutorial', () => {
router.navigate('/tutorial');
});
this.addEvent('click', '.gnb-curriculum', () => {
router.navigate('/curriculum');
});
this.addEvent('click', '.gnb-about', () => {
window.location.href = 'https://jade-sofa-1be.notion.site/7ebf97e49afe403eab8394eaec8e32a1';
});
Expand Down
Loading

0 comments on commit 7feba11

Please sign in to comment.