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
/* | |
Code examples from the article: S.O.L.I.D The first 5 priciples of Object Oriented Design with JavaScript | |
https://medium.com/@cramirez92/s-o-l-i-d-the-first-5-priciples-of-object-oriented-design-with-javascript-790f6ac9b9fa#.7uj4n7rsa | |
*/ | |
const shapeInterface = (state) => ({ | |
type: 'shapeInterface', | |
area: () => state.area(state) | |
}) |
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
#%RAML 1.0 | |
title: cinema | |
version: v1 | |
baseUri: / | |
types: | |
Movie: | |
properties: | |
id: string | |
title: string |
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
// repository.js | |
'use strict' | |
// factory function, that holds an open connection to the db, | |
// and exposes some functions for accessing the data. | |
const repository = (db) => { | |
// since this is the movies-service, we already know | |
// that we are going to query the `movies` collection | |
// in all of our functions. | |
const collection = db.collection('movies') |
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
'use strict' | |
const express = require('express') | |
const morgan = require('morgan') | |
const helmet = require('helmet') | |
const movieAPI = require('../api/movies') | |
const start = (options) => { | |
return new Promise((resolve, reject) => { | |
// we need to verify if we have a repository added and a server port | |
if (!options.repo) { |
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
'use strict' | |
const status = require('http-status') | |
module.exports = (app, options) => { | |
const {repo} = options | |
// here we get all the movies | |
app.get('/movies', (req, res, next) => { | |
repo.getAllMovies().then(movies => { | |
res.status(status.OK).json(movies) |
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
/* eslint-env mocha */ | |
const request = require('supertest') | |
const server = require('../server/server') | |
describe('Movies API', () => { | |
let app = null | |
let testMovies = [{ | |
'id': '3', | |
'title': 'xXx: Reactivado', | |
'format': 'IMAX', |
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
const MongoClient = require('mongodb') | |
// here we create the url connection string that the driver needs | |
const getMongoURL = (options) => { | |
const url = options.servers | |
.reduce((prev, cur) => prev + `${cur.ip}:${cur.port},`, 'mongodb://') | |
return `${url.substr(0, url.length - 1)}/${options.db}` | |
} |
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
// simple configuration file | |
// database parameters | |
const dbSettings = { | |
db: process.env.DB || 'movies', | |
user: process.env.DB_USER || 'cristian', | |
pass: process.env.DB_PASS || 'cristianPassword2017', | |
repl: process.env.DB_REPLS || 'rs1', | |
servers: (process.env.DB_SERVERS) ? process.env.DB_SERVERS.split(' ') : [ | |
'192.168.99.100:27017', |
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
'use strict' | |
// we load all the depencies we need | |
const {EventEmitter} = require('events') | |
const server = require('./server/server') | |
const repository = require('./repository/repository') | |
const config = require('./config/') | |
const mediator = new EventEmitter() | |
// verbose logging when we are starting the server | |
console.log('--- Movies Service ---') |
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
/* eslint-env mocha */ | |
const supertest = require('supertest') | |
describe('movies-service', () => { | |
const api = supertest('http://192.168.99.100:3000') | |
it('returns a 200 for a collection of movies', (done) => { | |
api.get('/movies/premiers') |
OlderNewer