Skip to content

Commit 7b2fbb8

Browse files
Initial Commit
1 parent 6bd8864 commit 7b2fbb8

File tree

10 files changed

+629
-0
lines changed

10 files changed

+629
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
lint-results
2+
*.egg-info
3+
test-results
4+
.mypy_cache
5+
.pytest_cache
6+
**/__pycache__/*
7+
.DS_Store
8+
yarn-error.log
9+
__pycache__

README.rst

Whitespace-only changes.

authenticator/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = '0.1.0'

authenticator/adapters/db/api.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from flask_pymongo import PyMongo
2+
from flask import jsonify
3+
4+
5+
class MongoAdapters(object):
6+
def __init__(self, app):
7+
self.client = PyMongo(app)
8+
self.db = self.client.db['nomad']
9+
10+
def get_all_users(self):
11+
collection = self.client.db['users']
12+
output = []
13+
for user in collection.find():
14+
output.append({'name': user['name'], 'email': user['email']})
15+
return jsonify({'result': output})
16+
17+
def add_users(self, name, email):
18+
try:
19+
collection = self.client.db['users']
20+
collection_id = collection.insert({'name': name, 'email': email})
21+
return jsonify({'result': collection_id})
22+
except Exception:
23+
print("ISSUE")

authenticator/app.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from flask import Flask
2+
from flask import jsonify
3+
from flask import request
4+
5+
from authenticator.adapters.db import api as db_api
6+
from authenticator import config
7+
8+
app = Flask(__name__)
9+
10+
app.config['MONGO_DBNAME'] = config.DATABASE
11+
app.config['MONGO_URI'] = f'mongodb://{config.DB_HOST}:{config.DB_PORT}/{config.DATABASE}'
12+
13+
db_obj = db_api.MongoAdapters(app)
14+
15+
16+
@app.route('/users', methods=['GET'])
17+
def get_users():
18+
return db_obj.get_all_users()
19+
20+
21+
@app.route('/add', methods=['POST'])
22+
def add_users():
23+
name = request.json['name']
24+
email = request.json['email']
25+
return db_obj.add_users(name, email)
26+
27+
28+
if __name__ == '__main__':
29+
app.run(debug=True)

authenticator/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DATABASE = "nomad"
2+
DB_HOST = "localhost"
3+
DB_PORT = 27017

0 commit comments

Comments
 (0)