Skip to content

Febin K Joseph : Challenge 2016 Solution #189

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

Open
wants to merge 8 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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
docker-compose.env
docker-compose.yml
Dockerfile
node_modules
test
.vscode
35 changes: 35 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]

# Change these settings to your own preference
indent_style = tab
indent_size = 4
space_after_anon_function = true

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
indent_style = space
indent_size = 4

[{package,bower}.json]
indent_style = space
indent_size = 2

[*.{yml,yaml}]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2

[*.js]
quote_type = "single"
43 changes: 43 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = {
"root": true,
"env": {
"node": true,
"commonjs": true,
"es6": true,
"jquery": false,
"jest": true,
"jasmine": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": "2018"
},
"rules": {
"indent": [
"warn",
"tab",
{ "SwitchCase": 1 }
],
"quotes": [
"warn",
"double"
],
"semi": [
"error",
"always"
],
"no-var": [
"error"
],
"no-console": [
"off"
],
"no-unused-vars": [
"warn"
],
"no-mixed-spaces-and-tabs": [
"warn"
]
}
};
64 changes: 64 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

# JetBrains IDE
.idea
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "node",
"request": "launch",
"name": "Debug",
"program": "${workspaceRoot}/node_modules/moleculer/bin/moleculer-runner.js",
"cwd": "${workspaceRoot}",
"args": [
"services"
]
},
{
"type": "node",
"request": "launch",
"name": "Jest",
"program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js",
"args": ["--runInBand"],
"cwd": "${workspaceRoot}",
"runtimeArgs": [
"--nolazy"
]
}
]
}
39 changes: 39 additions & 0 deletions API-DOC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## API Documentation

Challenge2016 is built using Node.js & Moleculer.js as Node.js framework

I have developed Restful APIs for this challenge.

To Run this program first install Node.js

```
https://nodejs.org/en/download
```
After installing Node.js run this command

```npm install```

```npm run dev```

open this open api link in browser

```
http://localhost:3000/api/openapi/ui#/
```

APIs under ```v1.film``` used for film CURD operation

For ease of test I have added a film use ```GET``` ```/api/v1/film``` for list films

```GET``` ```/api/v1/distribution``` for getting list of distributors

> **_NOTE:_** use ```id``` field of film and distributor for authorize distribution and check permission

> **_NOTE:_** ```/api/v1/distribution/authorize-distribution``` to authorize api, ``include`` and ``exclude`` field supports array i.e You can add multiple regions at once
> ``update`` & ``delete`` is not developed

> ***_NOTE:_*** I have set distributor ```Qube``` as the admin use this id as rightsOwner for initial authorization ```zr8Yf8Rf9PkT56LY```

## Thanks for the opportunity

```Febin K Joseph : [email protected]```
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:16-alpine

ENV NODE_ENV=production

RUN mkdir /app
WORKDIR /app

COPY package.json package-lock.json ./

RUN npm install --production

COPY challenge2016 .

CMD ["npm", "start"]
4 changes: 4 additions & 0 deletions data/distribution.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"distributorName":"dist1","_id":"AbMrkis3QaYZDKVM"}
{"distributorName":"dist3","_id":"TYVslAlZx2osAWBx"}
{"distributorName":"dist2","_id":"insTnN5kNSP2rOGx"}
{"distributorName":"qube","_id":"zr8Yf8Rf9PkT56LY"}
1 change: 1 addition & 0 deletions data/film.db
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"filmName":"premam","_id":"XAN4Ijz6PgkvgJbT"}
Empty file added data/permission.db
Empty file.
9 changes: 9 additions & 0 deletions docker-compose.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
NAMESPACE=
LOGGER=true
LOGLEVEL=info
SERVICEDIR=services

TRANSPORTER=nats://nats:4222


MONGO_URI=mongodb://mongo/challenge2016
78 changes: 78 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
version: "3.3"

services:

api:
build:
context: challenge2016
image: challenge2016
env_file: docker-compose.env
environment:
SERVICES: api
PORT: 3000
depends_on:
- nats
labels:
- "traefik.enable=true"
- "traefik.http.routers.api-gw.rule=PathPrefix(`/`)"
- "traefik.http.services.api-gw.loadbalancer.server.port=3000"
networks:
- internal

greeter:
build:
context: challenge2016
image: challenge2016
env_file: docker-compose.env
environment:
SERVICES: greeter
depends_on:
- nats
networks:
- internal

products:
build:
context: challenge2016
image: challenge2016
env_file: docker-compose.env
environment:
SERVICES: products
depends_on:
- mongo
- nats
networks:
- internal

mongo:
image: mongo:4
volumes:
- data:/data/db
networks:
- internal

nats:
image: nats:2
networks:
- internal

traefik:
image: traefik:v2.4
command:
- "--api.insecure=true" # Don't do that in production!
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
ports:
- 3000:80
- 3001:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- internal
- default

networks:
internal:

volumes:
data:
Loading