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: userRouter, userController 파일 세팅 #63

Closed
wants to merge 1 commit into from
Closed
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
51 changes: 51 additions & 0 deletions controller/UserController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import User from './User.js'

const { pg } = require('../models/database');

const signup = async (req, res) => {
const {
name,
email,
password
} = req.body;
try {

} catch(error) {
this.sendServerError(error);
}
}
const login = async (req, res) => {
const email = req.body.email;8
const password = req.body.password;
try {
//이거 쿼리문 바뀔
const user = await pg.query('SELECT id, email, password, name FROM "User" WHERE email = ${email}', );
} catch (error) {
this.sendServerError(error);
}

//todo: 처리코드
if (user === null) {
res.status(404).json({ message: "존재하지 않는 메일입니다."});
}
if (password === user.password) {
res.status(200).json({ id: user.id });
} else {
res.statuc(404).json({ message: "비밀번호가 틀렸습니다."});
}
}
const isEmailRepeated = async (req, res) => {

}
const logout = async (res) => {

}
const modifyPassword = async (req, res) => {

}
function sendServerError(error) {
console.error('Error in getting user by email:', error);
res.status(500).send('Internal Server Error');
}

module.export = { UserController };
11 changes: 11 additions & 0 deletions routers/UserRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require('express');
const userRouter = express.Router();
const userController = require('../controller/UserContoller');

router.post('/signup', userController.signup);
router.post('/login', userController.login);
router.get('/check-email', userController.isEmailReapeated);
router.post('/logout', userController.logout);
router.patch('/', userController.modifyPassword);

module.exports = userRouter;