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

haha #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

haha #11

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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# entertainme
# entertainme

Get Data

| No Cache (ms) | Cache|
| --------------| ---- |
| 138ms | 49ms |
| 15ms | 5ms |
| 16ms | 4ms |
| 28ms | 6ms |
| 29ms | 4ms |
| 26ms | 8ms |

99 changes: 99 additions & 0 deletions movies/Controller/index.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
const Movies = require('../Model/Movies.Model')
const Tag = require('../Model/Tag.Model')

const getAllMovies = async (req, res) => {
const allmovies = await Movies.find()
if (allmovies) {
res.status(200).json(allmovies)
}
}

const addMovies = async (req, res) => {
const { overview, title, poster_path, popularity } = req.body
const newMovie = new Movies({
overview, title, poster_path, popularity: Number(popularity)
})
try {
const adding = await newMovie.save()
if (adding) {
const getMovie = await Movies.find()
if (getMovie) {
res.status(200).json({
result: adding,
newData: getMovie
})
} else {
res.status(500).send('Error om')
}
} else {
res.status(500).send('Error om')
}
} catch (err) {
res.status(500).send('Error om')
}
}

const addTag = async (req, res) => {
const { name } = req.body
const newTag = new Tag({
name
})
try {
const adding = await newTag.save()
if (adding) {
res.status(200).json(adding)
} else {
res.status(500).send('Error om')
}
} catch (err) {
res.status(500).send('Error om')
}
}

const inputTag = async (req, res) => {
const {movie, tag} = req.body
const editmovie = await Movies.update({_id: movie},{'$push':{tag: tag}})
if (editmovie) {
const getMovie = await Movies.find()
if (getMovie) {
res.status(200).json({
result: editmovie,
newData: getMovie
})
} else {
res.status(500).send('Error om')
}
} else {
res.status(500).send('Error om')
}
}

const deleteMovie = async (req, res) => {
const movieid = req.params.movieid
try {
const deleteMov = await Movies.remove({'_id': movieid})
if (deleteMov) {
const getMovie = await Movies.find()
if (getMovie) {
res.status(200).json({
result: deleteMov,
newData: getMovie
})
} else {
res.status(500).send('Error om')
}
} else {
res.status(500).json('Error om')
}
} catch (err) {
res.status(500).json('Error om')
}
}

module.exports = {
getAllMovies,
addMovies,
addTag,
inputTag,
deleteMovie
}
14 changes: 14 additions & 0 deletions movies/Model/Movies.Model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const mongoose = require('mongoose'),
Schema = mongoose.Schema,
movieSchema = ({
poster_path: String,
overview: String,
title: String,
popularity: Number,
tag: [{
type: Schema.Types.ObjectId,
ref: 'Tag'
}],
})
Movies = mongoose.model('Movies', movieSchema)
module.exports = Movies
7 changes: 7 additions & 0 deletions movies/Model/Tag.Model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const mongoose = require('mongoose'),
Schema = mongoose.Schema,
tagSchema = ({
name: String,
})
Tag = mongoose.model('Tag', tagSchema)
module.exports = Tag
26 changes: 26 additions & 0 deletions movies/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const mongoose = require('mongoose')

var app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// Mongoose
const dbURL = `mongodb://localhost/Movies`
mongoose.connect(dbURL, (err) => {
err ? console.log(`Upps database movies ada error`) : console.log('Database movies is connected')
})

// Router
const index = require('./routes/movies.routes')

app.use('/', index)

module.exports = app;
90 changes: 90 additions & 0 deletions movies/bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('movies:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3001');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
15 changes: 15 additions & 0 deletions movies/helper/redis.movie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const redis = require("redis");
const client = redis.createClient();

const setCache = (payload) => {
client.set('entertainme_data', JSON.stringify(payload), 'ex', 1800);
}

const setMovieCache = (payload) => {
client.set('movie', JSON.stringify(payload), 'ex', 1800)
}

module.exports = {
setCache,
setMovieCache
}
1 change: 1 addition & 0 deletions movies/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions movies/node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading