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

Unit5 유서현 #46

Open
wants to merge 14 commits into
base: dbtjgus
Choose a base branch
from
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
고다은

# General
A, B, C, ...
유서현, ...
```

<br>
Expand Down
3 changes: 1 addition & 2 deletions Unit4/unit4.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ ex) MySQL / Oracle / Maria-DB 등

3. ERD 설계하기
- 2번에서 진행한 내용을 바탕으로 직적 ERD 제작 툴을 사용해 작성해봅시다. (완성 후 캡쳐본 올리기)
![무신사 _erd (2)](https://github.com/dbtjgus6988/2023-Server-Study/assets/144633320/218c034e-2284-4d1b-92ea-140ea859ab1c)

![무신사 _erd (3)](https://github.com/dbtjgus6988/2023-Server-Study/assets/144633320/18ad6fc1-6a9c-474a-89a9-f8f1161b216e)

<br/>

Expand Down
30 changes: 23 additions & 7 deletions Unit5/unit5.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,60 @@
## ❗️ 강의 수강 여부
수강한 강의에 체크표시 해주세요~

- [ ] 데이터베이스 실습
- [ ] 데이터베이스 실습 2
- [ ] SQL
- [x] 데이터베이스 실습
- [x] 데이터베이스 실습 2
- [x] SQL

<br>

## ❗️ notion에 키워드 정리 완료 여부
내가 notion에 키워드를 정리를 완료한 경우 체크표시 해주세요~

- [ ] 키워드 정리 완료
- [x] 키워드 정리 완료

<br>

## ❗️ 5주차 과제
1. ERD export해서 구축된 RDS에 반영하기
(완료된 내용 켬쳐본 올리기)

<img width="1470" alt="스크린샷 2023-11-01 오후 10 40 16" src="https://github.com/dbtjgus6988/2023-Server-Study/assets/144633320/954ae276-9f49-4b2c-8b67-296a49c69ac2">

https://velog.io/@xxoznge/RDS-ERD-export-%EC%A0%81%EC%9A%A9-%EC%BF%BC%EB%A6%AC-%EC%9E%91%EC%84%B1

<br/>

2. 데이터그립을 통해서 RDS에 접근하기
(완료된 내용 켬쳐본 올리기)
<img width="780" alt="스크린샷 2023-11-01 오후 10 35 19" src="https://github.com/dbtjgus6988/2023-Server-Study/assets/144633320/3d0b8f88-6ab7-4341-ac34-0f483869bea0">

<br/>

3. 접근된 RDS에 쿼리 작성하기
(완료된 내용 켬쳐본 올리기)
<img width="1470" alt="스크린샷 2023-11-01 오후 10 34 46" src="https://github.com/dbtjgus6988/2023-Server-Study/assets/144633320/81816379-c59e-4d46-8840-a48499b0ddee">

https://velog.io/@msung99/Server-5%EC%A3%BC%EC%B0%A8-%EC%8B%A4%EC%8A%B5

<br/>

4. RDS에 더미데이터 반영하기
(완료된 내용 켬쳐본 올리기)

<img width="1470" alt="스크린샷 2023-11-01 오후 10 37 12" src="https://github.com/dbtjgus6988/2023-Server-Study/assets/144633320/06bb4b9c-c9d1-44b7-a606-85ef621306bc">

https://velog.io/@leesomyoung/MySQL-%ED%94%84%EB%A1%9C%EC%8B%9C%EC%A0%80%EB%A1%9C-%EB%8D%94%EB%AF%B8%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%82%BD%EC%9E%85%ED%95%98%EA%B8%B0


<br/>

5. 화면 최소 3개 이상 쿼리 작성하기
(완료된 내용 켬쳐본 올리기)

<img width="1470" alt="스크린샷 2023-11-01 오후 10 46 19" src="https://github.com/dbtjgus6988/2023-Server-Study/assets/144633320/44afb388-7eac-417d-93f3-205c774e2fe5">
<img width="1470" alt="스크린샷 2023-11-01 오후 10 27 47" src="https://github.com/dbtjgus6988/2023-Server-Study/assets/144633320/4b273e60-2f66-479d-ab1b-0dcd902d36f3">
<img width="1470" alt="스크린샷 2023-11-01 오후 10 28 35" src="https://github.com/dbtjgus6988/2023-Server-Study/assets/144633320/4952ccc6-6aca-4c7a-afbd-127acc9b518f">
<img width="1470" alt="스크린샷 2023-11-01 오후 10 31 45" src="https://github.com/dbtjgus6988/2023-Server-Study/assets/144633320/722c1647-fa1e-4144-b387-53f4e69c3f93">
<img width="1470" alt="스크린샷 2023-11-01 오후 10 34 18" src="https://github.com/dbtjgus6988/2023-Server-Study/assets/144633320/fc275cb1-2f50-4860-890d-3b7c67c9605c">



<br/>

Expand Down
42 changes: 42 additions & 0 deletions Unit6/unit6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
### ⭐️ 6주차 과제 제출 ⭐️

## ❗️ 강의 수강 여부
수강한 강의에 체크표시 해주세요~

- [ ] HTTP 통신
- [ ] API
- [ ] 데이터 포맷 - CSV, JSON, XML

<br>

## ❗️ notion에 키워드 정리 완료 여부
내가 notion에 키워드를 정리를 완료한 경우 체크표시 해주세요~

- [ ] 키워드 정리 완료

<br>

## ❗️ 6주차 과제
1. 개발환경 구축하기 - nodejs 설치 및 사전에 올려둔 템플릿 적용하기
(완료된 내용 켬쳐본 올리기)

<br/>

2. 자신이 설계한 DB와 연동해서 API설계 (CRUD)
(완료된 내용 켬쳐본 올리기)

<br/>

3. Postman으로 API 테스트
(완료된 내용 켬쳐본 올리기)

<br/>

4. API Sheet 작성
(완료된 내용 켬쳐본 올리기)


<br/>



5 changes: 5 additions & 0 deletions server_nodejs_templete/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea/*
node_modules/*
package-lock.json
log/*
.DS_Store
1 change: 1 addition & 0 deletions server_nodejs_templete/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Node.js Template
49 changes: 49 additions & 0 deletions server_nodejs_templete/config/baseResponseStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = {

// Success
SUCCESS : { "isSuccess": true, "code": 1000, "message":"성공" },

// Common
TOKEN_EMPTY : { "isSuccess": false, "code": 2000, "message":"JWT 토큰을 입력해주세요." },
TOKEN_VERIFICATION_FAILURE : { "isSuccess": false, "code": 3000, "message":"JWT 토큰 검증 실패" },
TOKEN_VERIFICATION_SUCCESS : { "isSuccess": true, "code": 1001, "message":"JWT 토큰 검증 성공" }, // ?

//Request error
SIGNUP_EMAIL_EMPTY : { "isSuccess": false, "code": 2001, "message":"이메일을 입력해주세요" },
SIGNUP_EMAIL_LENGTH : { "isSuccess": false, "code": 2002, "message":"이메일은 30자리 미만으로 입력해주세요." },
SIGNUP_EMAIL_ERROR_TYPE : { "isSuccess": false, "code": 2003, "message":"이메일을 형식을 정확하게 입력해주세요." },
SIGNUP_PASSWORD_EMPTY : { "isSuccess": false, "code": 2004, "message": "비밀번호를 입력 해주세요." },
SIGNUP_PASSWORD_LENGTH : { "isSuccess": false, "code": 2005, "message":"비밀번호는 6~20자리를 입력해주세요." },
SIGNUP_NICKNAME_EMPTY : { "isSuccess": false, "code": 2006, "message":"닉네임을 입력 해주세요." },
SIGNUP_NICKNAME_LENGTH : { "isSuccess": false,"code": 2007,"message":"닉네임은 최대 20자리를 입력해주세요." },

SIGNIN_EMAIL_EMPTY : { "isSuccess": false, "code": 2008, "message":"이메일을 입력해주세요" },
SIGNIN_EMAIL_LENGTH : { "isSuccess": false, "code": 2009, "message":"이메일은 30자리 미만으로 입력해주세요." },
SIGNIN_EMAIL_ERROR_TYPE : { "isSuccess": false, "code": 2010, "message":"이메일을 형식을 정확하게 입력해주세요." },
SIGNIN_PASSWORD_EMPTY : { "isSuccess": false, "code": 2011, "message": "비밀번호를 입력 해주세요." },

USER_USERID_EMPTY : { "isSuccess": false, "code": 2012, "message": "userId를 입력해주세요." },
USER_USERID_NOT_EXIST : { "isSuccess": false, "code": 2013, "message": "해당 회원이 존재하지 않습니다." },

USER_USEREMAIL_EMPTY : { "isSuccess": false, "code": 2014, "message": "이메일을 입력해주세요." },
USER_USEREMAIL_NOT_EXIST : { "isSuccess": false, "code": 2015, "message": "해당 이메일을 가진 회원이 존재하지 않습니다." },
USER_ID_NOT_MATCH : { "isSuccess": false, "code": 2016, "message": "유저 아이디 값을 확인해주세요" },
USER_NICKNAME_EMPTY : { "isSuccess": false, "code": 2017, "message": "변경할 닉네임 값을 입력해주세요" },

USER_STATUS_EMPTY : { "isSuccess": false, "code": 2018, "message": "회원 상태값을 입력해주세요" },

// Response error
SIGNUP_REDUNDANT_EMAIL : { "isSuccess": false, "code": 3001, "message":"중복된 이메일입니다." },
SIGNUP_REDUNDANT_NICKNAME : { "isSuccess": false, "code": 3002, "message":"중복된 닉네임입니다." },

SIGNIN_EMAIL_WRONG : { "isSuccess": false, "code": 3003, "message": "아이디가 잘못 되었습니다." },
SIGNIN_PASSWORD_WRONG : { "isSuccess": false, "code": 3004, "message": "비밀번호가 잘못 되었습니다." },
SIGNIN_INACTIVE_ACCOUNT : { "isSuccess": false, "code": 3005, "message": "비활성화 된 계정입니다. 고객센터에 문의해주세요." },
SIGNIN_WITHDRAWAL_ACCOUNT : { "isSuccess": false, "code": 3006, "message": "탈퇴 된 계정입니다. 고객센터에 문의해주세요." },

//Connection, Transaction 등의 서버 오류
DB_ERROR : { "isSuccess": false, "code": 4000, "message": "데이터 베이스 에러"},
SERVER_ERROR : { "isSuccess": false, "code": 4001, "message": "서버 에러"},


}
15 changes: 15 additions & 0 deletions server_nodejs_templete/config/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const mysql = require('mysql2/promise');
const {logger} = require('./winston');

// TODO: 본인의 DB 계정 입력
const pool = mysql.createPool({
host: '',
user: '',
port: '3306',
password: '',
database: ''
});

module.exports = {
pool: pool
};
24 changes: 24 additions & 0 deletions server_nodejs_templete/config/express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const express = require('express');
const compression = require('compression');
const methodOverride = require('method-override');
var cors = require('cors');
module.exports = function () {
const app = express();

app.use(compression());

app.use(express.json());

app.use(express.urlencoded({extended: true}));

app.use(methodOverride());

app.use(cors());
// app.use(express.static(process.cwd() + '/public'));

/* App (Android, iOS) */
// 도메인을 추가할 경우 이곳에 Route를 추가
require('../src/app/User/userRoute')(app);

return app;
};
38 changes: 38 additions & 0 deletions server_nodejs_templete/config/jwtMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const jwt = require('jsonwebtoken');
const secret_config = require('./secret');
const { response } = require("./response")
const { errResponse } = require("./response")
const baseResponse = require("./baseResponseStatus");


const jwtMiddleware = (req, res, next) => {
// read the token from header or url
const token = req.headers['x-access-token'] || req.query.token;
// token does not exist
if(!token) {
return res.send(errResponse(baseResponse.TOKEN_EMPTY))
}

// create a promise that decodes the token
const p = new Promise(
(resolve, reject) => {
jwt.verify(token, secret_config.jwtsecret , (err, verifiedToken) => {
if(err) reject(err);
resolve(verifiedToken)
})
}
);

// if it has failed to verify, it will return an error message
const onError = (error) => {
return res.send(errResponse(baseResponse.TOKEN_VERIFICATION_FAILURE))
};
// process the promise
p.then((verifiedToken)=>{
//비밀 번호 바뀌었을 때 검증 부분 추가 할 곳
req.verifiedToken = verifiedToken;
next();
}).catch(onError)
};

module.exports = jwtMiddleware;
18 changes: 18 additions & 0 deletions server_nodejs_templete/config/response.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const response = ({isSuccess, code, message}, result) => {
return {
isSuccess: isSuccess,
code: code,
message: message,
result: result
}
};

const errResponse = ({isSuccess, code, message}) => {
return {
isSuccess: isSuccess,
code: code,
message: message
}
};

module.exports = { response, errResponse };
5 changes: 5 additions & 0 deletions server_nodejs_templete/config/secret.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// 해당 KEY 값들을 꼭 바꿔서 사용하기!
// 반드시 .gitignore에 추가하기!
module.exports = {
'jwtsecret' : '',
};
48 changes: 48 additions & 0 deletions server_nodejs_templete/config/winston.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { createLogger, format, transports } = require('winston');
require('winston-daily-rotate-file');
const fs = require('fs');

const env = process.env.NODE_ENV || 'development';
const logDir = 'log';

// Javascript winston logger 이용하기
// https://lovemewithoutall.github.io/it/winston-example/
// Create the log directory if it does not exist
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir)
}

const dailyRotateFileTransport = new transports.DailyRotateFile({
level: 'debug',
filename: `${logDir}/%DATE%-smart-push.log`,
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
});

const logger = createLogger({
level: env === 'development' ? 'debug' : 'info',
format: format.combine(
format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
format.json()
),
transports: [
new transports.Console({
level: 'info',
format: format.combine(
format.colorize(),
format.printf(
info => `${info.timestamp} ${info.level}: ${info.message}`
)
)
}),
dailyRotateFileTransport
]
});

module.exports = {
logger: logger
};
6 changes: 6 additions & 0 deletions server_nodejs_templete/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const express = require('./config/express');
const {logger} = require('./config/winston');

const port = 3000;
express().listen(port);
logger.info(`${process.env.NODE_ENV} - API Server Start At Port ${port}`);
30 changes: 30 additions & 0 deletions server_nodejs_templete/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "api-server-node",
"version": "1.0.0",
"description": "Node.js API Server",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "NODE_ENV=development node index.js",
"prod": "NODE_ENV=production node index.js"
},
"repository": {
"type": "git",
"url": "[email protected]:softsquared/template/api-server-node.git"
},
"author": "",
"license": "ISC",
"dependencies": {
"compression": "^1.7.4",
"cors": "^2.8.5",
"crypto": "^1.0.1",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"method-override": "^3.0.0",
"mysql2": "^2.0.0",
"nodemon": "^2.0.7",
"regex-email": "^1.0.2",
"winston": "^3.2.1",
"winston-daily-rotate-file": "^4.2.1"
}
}
Loading