Browse Source

Merge pull request #1 from yigitcolakoglu/efe

Efe
pull/2/head
Yiğit Çolakoğlu 6 years ago
committed by GitHub
parent
commit
d7a2cd5508
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 0 deletions
  1. +12
    -0
      server_side/api/requirements.txt
  2. +43
    -0
      server_side/api/voting_system/app.py

+ 12
- 0
server_side/api/requirements.txt View File

@ -0,0 +1,12 @@
aniso8601==6.0.0
Click==7.0
dnspython==1.16.0
Flask==1.0.2
Flask-RESTful==0.3.7
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.1
pymongo==3.7.2
pytz==2018.9
six==1.12.0
Werkzeug==0.14.1

+ 43
- 0
server_side/api/voting_system/app.py View File

@ -0,0 +1,43 @@
import ssl
from flask import Flask
from flask_restful import Resource, Api, reqparse, abort
from pymongo import MongoClient
from bson.objectid import ObjectId
app = Flask(__name__)
api = Api(app)
client = MongoClient("mongodb+srv://mycity:mycity123@mycity-3v9y3.mongodb.net/test?retryWrites=true", ssl_cert_reqs=ssl.CERT_NONE)
db = client.voting_system
collection = db.votings
class Votings(Resource):
def get(self):
votings = [
{
'id' : str(doc['_id']),
'name': doc['name'],
'desc': doc['desc'],
'img' : doc['img']
}
for doc in collection.find({})
]
return votings
class Vote(Resource):
def get(self, voting_id):
try:
doc = collection.find_one({'_id': ObjectId(voting_id)})
doc['_id'] = str(doc['_id'])
return doc
except:
abort(404, error="Voting {} doesn't exist".format(voting_id))
api.add_resource(Votings, '/votings')
api.add_resource(Vote, '/votings/<voting_id>')
if __name__ == '__main__':
app.run(debug=True)

Loading…
Cancel
Save