-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from JNU-econovation/feature/Issue-53
Feature/issue 53
- Loading branch information
Showing
31 changed files
with
4,032 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
COOKIE_SECRET=cookiesecret | ||
NODE_ENV=test | ||
S3_ACCESS_KEY=AKIAQWGLZ6TSBFMZV4XC | ||
S3_SECRET_KEY=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 | ||
S3_REGION=ap-northeast-2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const express = require("express"); | ||
const cookieParser = require("cookie-parser"); | ||
const morgan = require("morgan"); | ||
const path = require("path"); | ||
const session = require("express-session"); | ||
const nunjucks = require("nunjucks"); | ||
const dotenv = require("dotenv"); | ||
const passport = require("passport"); | ||
dotenv.config(); | ||
const pageRouter = require("./routes/page"); | ||
const authRouter = require("./routes/auth"); | ||
const postRouter = require("./routes/post"); | ||
const { sequelize } = require("./models"); | ||
const passportConfig = require("./passport"); | ||
const cors = require("cors"); | ||
|
||
const app = express(); | ||
passportConfig(); | ||
app.set("port", process.env.PORT || 8001); | ||
app.set("view engine", "html"); | ||
nunjucks.configure("views", { | ||
express: app, | ||
watch: true, | ||
}); | ||
sequelize | ||
.sync({ force: false }) //sequelize가 초기화 될 때 DB에 필요한 테이블 생성 | ||
.then(() => { | ||
console.log("데이터베이스 연결 성공"); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
}); | ||
|
||
app.use(morgan("dev")); | ||
app.use(express.static(path.join(__dirname, "public"))); | ||
app.use("/img", express.static(path.join(__dirname, "uploads"))); | ||
app.use(cors()); | ||
|
||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(cookieParser(process.env.COOKIE_SECRET)); | ||
app.use( | ||
session({ | ||
resave: false, | ||
saveUninitialized: false, | ||
secret: process.env.COOKIE_SECRET, | ||
cookie: { | ||
httpOnly: true, | ||
secure: false, | ||
}, | ||
}) | ||
); | ||
app.use(passport.initialize()); | ||
app.use(passport.session()); | ||
app.use("/", pageRouter); | ||
app.use("/auth", authRouter); | ||
app.use("/post", postRouter); | ||
|
||
app.use((req, res, next) => { | ||
const error = new Error(`${req.method} ${req.url} 라우터가 없습니다.`); | ||
error.status = 404; | ||
next(error); | ||
}); | ||
|
||
app.use((err, req, res, next) => { | ||
res.locals.message = err.message; | ||
res.locals.error = process.env.NODE_ENV !== "production" ? err : {}; | ||
res.status(err.status || 500); | ||
res.render("error"); | ||
}); | ||
|
||
app.listen(app.get("port"), () => { | ||
console.log(app.get("port"), "번 포트에서 대기중"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"development": { | ||
"username": "root", | ||
"password": "daaeda", | ||
"database": "collusic", | ||
"host": "127.0.0.1", | ||
"dialect": "mysql" | ||
}, | ||
"test": { | ||
"username": "collusic", | ||
"password": "collusic3717", | ||
"database": "collusic", | ||
"host": "54.180.156.26", | ||
"dialect": "mysql" | ||
}, | ||
"production": { | ||
"username": "root", | ||
"password": null, | ||
"database": "database_production", | ||
"host": "127.0.0.1", | ||
"dialect": "mysql" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const router = require("express"); | ||
const { | ||
isLoggedIn, | ||
isNotLoggedIn, | ||
upload_commit, | ||
} = require("../../routes/middlewares"); | ||
const { Post, User, Comment } = require("../../models"); | ||
//field값 | ||
|
||
const createContriProjectAPI = async (req, res) => { | ||
let id = req.params.id; | ||
const commentpost = await Comment.create({ | ||
c_description: req.body.description, | ||
c_audioFile: req.file.filename, | ||
c_lyrics_text: req.body.lyrics_text, | ||
pid: id, | ||
selected_status: false, | ||
}); | ||
if (!commentpost) { | ||
res.status(400).json({ | ||
success: false, | ||
}); | ||
} else { | ||
res.status(200).json({ | ||
success: true, | ||
commentpost: commentpost, | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
createContriProjectAPI: createContriProjectAPI, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// const express = require("express"); | ||
// const router = express.Router(); | ||
|
||
// const userInformationAPI = (req, res) => { | ||
// try { | ||
// const myinfo = await User.findOne({ | ||
// attributes: ["email", "introduce"], | ||
// where: { | ||
// email: req.user.email, | ||
// }, | ||
// }); | ||
// res.status(200).json({ | ||
// email: myinfo, | ||
// }); | ||
// } catch (err) { | ||
// res.status(400).json({ | ||
// error: err, | ||
// }); | ||
// } | ||
// }; | ||
|
||
const createContributeProjectAPI = (req, res) => {}; | ||
const readRequestProjectsAPI = (req, res) => {}; | ||
const readContributeProjectsAPI = (req, res) => { | ||
if (!id) { | ||
res.status(400).json({ error: "you don't send requestProject Id!" }); | ||
} | ||
|
||
res.status(200).json({ contributeProject: projects }); | ||
}; | ||
module.exports = { | ||
userInformationAPI, | ||
createContributeProjectAPI, | ||
readRequestProjectsAPI, | ||
readContributeProjectsAPI, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const { isLoggedIn, isNotLoggedIn } = require("../../routes/middlewares"); | ||
const { Post, User } = require("../../models"); | ||
//field값 | ||
const readMyPageAPI = async (req, res, next) => { | ||
try { | ||
const myinfo = await User.findOne({ | ||
attributes: ["email", "introduce"], | ||
where: { | ||
email: req.user.email, | ||
}, | ||
}); | ||
res.status(200).json({ | ||
email: myinfo, | ||
}); | ||
} catch (err) { | ||
res.status(400).json({ error: err }); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
readMyPageAPI: readMyPageAPI, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
const router = require("express"); | ||
const { | ||
isLoggedIn, | ||
isNotLoggedIn, | ||
upload, | ||
} = require("../../routes/middlewares"); | ||
const { Post, User, Comment } = require("../../models"); | ||
//field값 | ||
|
||
const createProjectAPI = async (req, res) => { | ||
if (req.file) { | ||
const post = await Post.create({ | ||
title: req.body.title, | ||
description: req.body.description, | ||
genre: req.body.genre, | ||
mood: req.body.mood, | ||
lyrics_text: req.body.lyrics_text, | ||
audioFile: req.file.location, | ||
music_field: Boolean(req.body.music_field), | ||
lyrics_field: Boolean(req.body.lyrics_field), | ||
instrument_field: Boolean(req.body.instrument_field), | ||
}); | ||
if (!post) { | ||
res.status(400).json({ | ||
success: false, | ||
post: post, | ||
}); | ||
} else { | ||
const post = await Post.create({ | ||
title: req.body.title, | ||
description: req.body.description, | ||
genre: req.body.genre, | ||
mood: req.body.mood, | ||
lyrics_text: req.body.lyrics_text, | ||
music_field: req.body.music_field, | ||
lyrics_field: req.body.lyrics_field, | ||
instrument_field: req.body.instrument_field, | ||
uid: req.user.id, | ||
}); | ||
} | ||
if (!post) { | ||
res.status(400).json({ | ||
sucess: false, | ||
}); | ||
} else { | ||
res.status(200).json({ | ||
sucess: true, | ||
post: post, | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
const mainInfoAPI = async (req, res) => { | ||
const maininfo = await Post.findAll({ | ||
attributes: [ | ||
"email", | ||
"pid", | ||
"title", | ||
"music_field", | ||
"lyrics_field", | ||
"instrument_field", | ||
"genre", | ||
"mood", | ||
"audioFile", | ||
"lyrics_text", | ||
], | ||
}); | ||
if (!maininfo) { | ||
res.status(400).json({ | ||
success: false, | ||
}); | ||
} else { | ||
res.status(200).json({ maininfo: maininfo }); | ||
} | ||
}; | ||
|
||
const commentsAPI = async (req, res, next) => { | ||
let id = req.params.id; | ||
try { | ||
const comments = await Comment.findAll({ | ||
include: { | ||
model: Post, | ||
where: { id: id }, | ||
}, | ||
}); | ||
const project = await Post.findAll({ | ||
where: { id: id }, | ||
}); | ||
res.status(200).json({ comments, project }); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
createProjectAPI: createProjectAPI, | ||
mainInfoAPI: mainInfoAPI, | ||
commentsAPI: commentsAPI, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// const express = require("express"); | ||
// const router = express.Router(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const Sequelize = require("sequelize"); | ||
|
||
module.exports = class Comment extends Sequelize.Model { | ||
static init(sequelize) { | ||
return super.init( | ||
{ | ||
c_description: { | ||
type: Sequelize.TEXT, | ||
allowNull: false, | ||
}, | ||
c_audioFile: { | ||
type: Sequelize.STRING(140), | ||
allowNull: false, | ||
}, | ||
c_lyrics_text: { | ||
type: Sequelize.TEXT, | ||
allowNull: true, | ||
}, | ||
selected_status: { | ||
type: Sequelize.BOOLEAN, | ||
allowNull: false, | ||
}, | ||
}, | ||
{ | ||
sequelize, | ||
timestamps: true, | ||
underscored: false, | ||
modelName: "Comment", | ||
tableName: "comment", | ||
paranoid: false, | ||
charset: "utf8mb4", | ||
collate: "utf8mb4_general_ci", | ||
} | ||
); | ||
} | ||
|
||
static associate(db) { | ||
db.Comment.belongsTo(db.Post, { foreignKey: "pid", sourceKey: "id" }); | ||
db.Comment.belongsTo(db.User, { foreignKey: "uid", sourceKey: "id" }); | ||
} | ||
}; | ||
//requestid 외래키 | ||
//uid 외래키 | ||
//constraint uid foreign key uid references user.uid on delete cascade on update cascade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const Sequelize = require("sequelize"); | ||
const env = "test" || "development"; //config.json의 development 가져오기 | ||
const config = require("../config/config")[env]; //config.json의 development 가져오기 | ||
const User = require("./user"); | ||
const Post = require("./post"); | ||
const Comment = require("./comment"); | ||
|
||
const db = {}; | ||
const sequelize = new Sequelize( | ||
config.database, | ||
config.username, | ||
config.password, | ||
config | ||
); | ||
|
||
db.sequelize = sequelize; | ||
db.User = User; | ||
db.Post = Post; | ||
db.Comment = Comment; | ||
//사람과 게시글은 1:1관계, 게시글과 해시태그는 1:N 관계 | ||
User.init(sequelize); | ||
Post.init(sequelize); | ||
Comment.init(sequelize); | ||
|
||
User.associate(db); | ||
Post.associate(db); | ||
Comment.associate(db); | ||
|
||
module.exports = db; |
Oops, something went wrong.