Browse Source

Merge remote-tracking branch 'origin/efe' into yigit

old
Yiğit Çolakoğlu 6 years ago
parent
commit
61f083730a
5 changed files with 27 additions and 20 deletions
  1. +6
    -0
      server_side/api/modules/databases/ratings.json
  2. +1
    -1
      server_side/api/modules/databases/users.json
  3. +3
    -3
      server_side/api/modules/rating_system.py
  4. +10
    -11
      server_side/api/modules/user_info.py
  5. +7
    -5
      server_side/api/modules/voting_system.py

+ 6
- 0
server_side/api/modules/databases/ratings.json View File

@ -16,6 +16,12 @@
"rater": "9vard12ty0ad2yvwp3q53rsf3h43r2vq", "rater": "9vard12ty0ad2yvwp3q53rsf3h43r2vq",
"score": 10, "score": 10,
"note": null "note": null
},
{
"id": 3,
"rater": "9vard12ty0ad2yvwp3q53rsf3h43r2vq",
"score": 5,
"note": null
} }
] ]
} }

+ 1
- 1
server_side/api/modules/databases/users.json View File

@ -1,5 +1,5 @@
{ {
"efe":{
"efe": {
"id": "9vard12ty0ad2yvwp3q53rsf3h43r2vq", "id": "9vard12ty0ad2yvwp3q53rsf3h43r2vq",
"realname": "Efe Aydın", "realname": "Efe Aydın",
"avatar": "/img/user1.png", "avatar": "/img/user1.png",


+ 3
- 3
server_side/api/modules/rating_system.py View File

@ -1,4 +1,5 @@
import os import os
import copy
import json import json
from api.modules import utils from api.modules import utils
@ -57,9 +58,8 @@ class Ratings(Resource):
class Rating(Resource): class Rating(Resource):
def get(self, rating_id): def get(self, rating_id):
try: try:
rating = ratings[rating_id - 1]
rating = copy.deepcopy(ratings[rating_id - 1])
del rating['rates'] del rating['rates']
del rating['raters']
return rating return rating
except: except:
abort(404, error="Rating {} doesn't exist".format(rating_id)) abort(404, error="Rating {} doesn't exist".format(rating_id))
@ -74,7 +74,7 @@ class Rate(Resource):
note=<note>& # ADDITIONAL note=<note>& # ADDITIONAL
rater_id=<user_id> rater_id=<user_id>
""" """
if utils.find_by_id( users, request.args[ 'rater_id' ] ):
if utils.find_by_id( users.values(), request.args[ 'rater_id' ] ):
rating_id = int(request.args['rating_id']) rating_id = int(request.args['rating_id'])
score = int(request.args['score']) score = int(request.args['score'])
if 0 >= score >= 10: if 0 >= score >= 10:


+ 10
- 11
server_side/api/modules/user_info.py View File

@ -1,4 +1,5 @@
import os import os
import copy
import json import json
from api.modules import utils from api.modules import utils
@ -35,6 +36,7 @@ class Users(Resource):
'bus_usage_month': 0, 'bus_usage_month': 0,
'bus_usage_year': 0 'bus_usage_year': 0
}, },
'daily_electricity_usage': [],
'points': 0 'points': 0
} }
@ -48,7 +50,7 @@ class Users(Resource):
class User(Resource): class User(Resource):
def get(self, user_id): def get(self, user_id):
try: try:
user = utils.find_by_id( users, user_id )
user = utils.find_by_id( users.values(), user_id )
if not user: if not user:
raise Exception('User not found!') raise Exception('User not found!')
del user['password'] del user['password']
@ -66,20 +68,17 @@ class Login(Resource):
#Password for efe is 12345 #Password for efe is 12345
args = request.form args = request.form
username = args['username'] username = args['username']
passsword = utils.md5( args[ 'password' ] )
password = utils.md5( args[ 'password' ] )
if not username in users: if not username in users:
return [False,{}]
return [False, {}]
user = (users[username]).copy()
if user['password'] == passsword:
user.pop("password")
return [True,json.dumps(user)]
user = copy.deepcopy(users[username])
if user['password'] == password:
del user["password"]
return [True, json.dumps(user)]
else: else:
return [False,{}]
return [False, {}]
if __name__ == '__main__': if __name__ == '__main__':
api.add_resource(Users, '/users', '/users/') api.add_resource(Users, '/users', '/users/')


+ 7
- 5
server_side/api/modules/voting_system.py View File

@ -1,4 +1,5 @@
import os import os
import copy
import json import json
from api.modules import utils from api.modules import utils
@ -46,6 +47,7 @@ class Votings(Resource):
""" """
args = request.form args = request.form
args = request.form
voting_id = len(votings) + 1 voting_id = len(votings) + 1
voting = { voting = {
'id': voting_id, 'id': voting_id,
@ -75,10 +77,10 @@ class Votings(Resource):
class Voting(Resource): class Voting(Resource):
def get(self, voting_id): def get(self, voting_id):
try: try:
voting = votings[voting_id - 1].copy()
voting = copy.deepcopy(votings[voting_id - 1])
for i in range(len(voting['votes'])): for i in range(len(voting['votes'])):
voting['votes'][str(i + 1)]['votes'] = None
voting['voters'] = None
del voting['votes'][str(i + 1)]['votes']
del voting['voters']
return voting return voting
except: except:
@ -93,9 +95,9 @@ class Vote(Resource):
voter_id = request.form['voter_id'] voter_id = request.form['voter_id']
voting_id = int(request.form['voting_id']) - 1 voting_id = int(request.form['voting_id']) - 1
if utils.find_by_id( users, voter_id ):
if utils.find_by_id( users.values(), voter_id ):
if voter_id not in votings[voting_id]['voters']: if voter_id not in votings[voting_id]['voters']:
vote_id = int(request.args['vote_id'])
vote_id = int(request.form['vote_id'])
votings[voting_id]['votes'][str(vote_id)]['votes'] += 1 votings[voting_id]['votes'][str(vote_id)]['votes'] += 1
votings[voting_id]['voters'].append(voter_id) votings[voting_id]['voters'].append(voter_id)
with open(db_path, 'w') as f: with open(db_path, 'w') as f:


Loading…
Cancel
Save