From e1a79ba7a61d2ec04d8abd446d44311318c9c2b2 Mon Sep 17 00:00:00 2001 From: catarak Date: Fri, 17 Jun 2016 14:11:52 -0400 Subject: [PATCH] start to add create project --- server/controllers/project.controller.js | 21 ++++++++++++++ server/models/file.js | 10 ------- server/models/project.js | 9 ++++-- server/routes/project.routes.js | 8 +++++ server/server.js | 2 ++ shared/components/Nav/Nav.jsx | 18 ++++++++++-- shared/containers/IDEView/IDEView.jsx | 4 ++- shared/redux/actions/index.js | 37 ++++++++++++++++++++++++ shared/redux/constants/constants.js | 5 ++++ shared/redux/reducers/project.js | 4 +++ styles/abstracts/_placeholders.scss | 8 +++++ styles/components/_nav.scss | 15 ++++++++-- 12 files changed, 124 insertions(+), 17 deletions(-) create mode 100644 server/controllers/project.controller.js delete mode 100644 server/models/file.js create mode 100644 server/routes/project.routes.js diff --git a/server/controllers/project.controller.js b/server/controllers/project.controller.js new file mode 100644 index 00000000..b93c2e95 --- /dev/null +++ b/server/controllers/project.controller.js @@ -0,0 +1,21 @@ +import Project from '../models/project' + +export function createProject(req, res) { + if (req.user) { + Project.create({ + user: req.user._id, + file: {} + }, function(err, newProject) { + if (err) { return res.json({success: false}) } + return res.json({ + name: newProject.name, + file: { + name: newProject.file.name, + content: newProject.file.content + } + }); + }); + } else { + res.json({success: false}); + } +} \ No newline at end of file diff --git a/server/models/file.js b/server/models/file.js deleted file mode 100644 index 53bbc3f1..00000000 --- a/server/models/file.js +++ /dev/null @@ -1,10 +0,0 @@ -import mongoose from 'mongoose'; -const Schema = mongoose.Schema; - -const fileSchema = new Schema({ - name: {type: String, default: 'sketch.js'}, - project: {type: Schema.Types.ObjectId, ref: 'Project'}, - content: {type: String} -}, {timestamps: true}); - -export default mongoose.model('File', fileSchema); \ No newline at end of file diff --git a/server/models/project.js b/server/models/project.js index 9d5c8677..046b4bae 100644 --- a/server/models/project.js +++ b/server/models/project.js @@ -1,10 +1,15 @@ import mongoose from 'mongoose'; const Schema = mongoose.Schema; +const fileSchema = new Schema({ + name: {type: String, default: 'sketch.js'}, + content: {type: String} +}, {timestamps: true}); + const projectSchema = new Schema({ - name: {type: String, default: 'Hello p5.js'}, + name: {type: String, default: "Hello p5.js, it's the server"}, user: {type: Schema.Types.ObjectId, ref: 'User'}, - file: {type: Schema.Types.ObjectId, ref: 'File'} + file: {type: fileSchema} }, {timestamps: true}); export default mongoose.model('Project', projectSchema); \ No newline at end of file diff --git a/server/routes/project.routes.js b/server/routes/project.routes.js new file mode 100644 index 00000000..3649b359 --- /dev/null +++ b/server/routes/project.routes.js @@ -0,0 +1,8 @@ +import { Router } from 'express'; +import * as ProjectController from '../controllers/project.controller'; + +const router = new Router(); + +router.route('/projects').post(ProjectController.createProject); + +export default router; \ No newline at end of file diff --git a/server/server.js b/server/server.js index 95fcc565..5623a943 100644 --- a/server/server.js +++ b/server/server.js @@ -24,6 +24,7 @@ app.use(webpackHotMiddleware(compiler)); import serverConfig from './config'; import users from './routes/user.routes'; import sessions from './routes/session.routes'; +import projects from './routes/project.routes'; //Body parser, cookie parser, sessions, serve public assets @@ -50,6 +51,7 @@ app.use(passport.initialize()); app.use(passport.session()); app.use('/', users); app.use('/', sessions); +app.use('/', projects); const passportConfig = require('./config/passport'); diff --git a/shared/components/Nav/Nav.jsx b/shared/components/Nav/Nav.jsx index d458674a..f529ea3b 100644 --- a/shared/components/Nav/Nav.jsx +++ b/shared/components/Nav/Nav.jsx @@ -5,8 +5,22 @@ class Nav extends React.Component { render() { return (