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

oop, aang #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions movies/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const express = require('express')
const bodyParser = require('body-parser')
const app = express()

const cast = require('./routes/cast')

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

app.set('views', './views')
app.set('view engine', 'ejs')

app.use('/casts', cast)
app.get('/', function(req, res){
res.send('adsdsad')
})

app.listen(3000)
9 changes: 9 additions & 0 deletions movies/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"development": {
"username": "postgres",
"password": "postgres",
"database": "MOvie",
"host": "127.0.0.1",
"dialect": "postgres"
}
}
36 changes: 36 additions & 0 deletions movies/migrations/20171109031447-create-cast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Casts', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
first_name: {
type: Sequelize.STRING
},
last_name: {
type: Sequelize.STRING
},
birth_year: {
type: Sequelize.STRING
},
gender: {
type: Sequelize.STRING
},
createdAt: {
allowNull: true,
type: Sequelize.DATE
},
updatedAt: {
allowNull: true,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Casts');
}
};
33 changes: 33 additions & 0 deletions movies/migrations/20171109031646-create-movie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Movies', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.STRING
},
released_year: {
type: Sequelize.STRING
},
genre: {
type: Sequelize.STRING
},
createdAt: {
allowNull: true,
type: Sequelize.DATE
},
updatedAt: {
allowNull: true,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Movies');
}
};
30 changes: 30 additions & 0 deletions movies/migrations/20171109031951-create-movie-cast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('MovieCasts', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
MovieId: {
type: Sequelize.INTEGER
},
role: {
type: Sequelize.STRING
},
createdAt: {
allowNull: true,
type: Sequelize.DATE
},
updatedAt: {
allowNull: true,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('MovieCasts');
}
};
20 changes: 20 additions & 0 deletions movies/models/cast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
module.exports = (sequelize, DataTypes) => {
var Cast = sequelize.define('Cast', {
first_name: DataTypes.STRING,
last_name: DataTypes.STRING,
birth_year: DataTypes.STRING,
gender: DataTypes.STRING
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});

Cast.prototype.getFullname = function() {
return [this.first_name, this.last_name].join(' ');
};
return Cast;
};
36 changes: 36 additions & 0 deletions movies/models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

var fs = require('fs');
var path = require('path');
var Sequelize = require('sequelize');
var basename = path.basename(__filename);
var env = process.env.NODE_ENV || 'development';
var config = require(__dirname + '/../config/config.json')[env];
var db = {};

if (config.use_env_variable) {
var sequelize = new Sequelize(process.env[config.use_env_variable]);
} else {
var sequelize = new Sequelize(config.database, config.username, config.password, config);
}

fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
var model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});

Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
16 changes: 16 additions & 0 deletions movies/models/movie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
module.exports = (sequelize, DataTypes) => {
var Movie = sequelize.define('Movie', {
name: DataTypes.STRING,
released_year: DataTypes.STRING,
genre: DataTypes.STRING,

}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return Movie;
};
14 changes: 14 additions & 0 deletions movies/models/moviecast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
module.exports = (sequelize, DataTypes) => {
var MovieCast = sequelize.define('MovieCast', {
MovieId: DataTypes.INTEGER,
role: DataTypes.STRING
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return MovieCast;
};
Loading