diff --git a/server_side/api/modules/databases/ratings.json b/server_side/api/modules/databases/ratings.json index ef98f5e..391b0b2 100644 --- a/server_side/api/modules/databases/ratings.json +++ b/server_side/api/modules/databases/ratings.json @@ -16,6 +16,12 @@ "rater": "9vard12ty0ad2yvwp3q53rsf3h43r2vq", "score": 10, "note": null + }, + { + "id": 3, + "rater": "9vard12ty0ad2yvwp3q53rsf3h43r2vq", + "score": 5, + "note": null } ] } diff --git a/server_side/api/modules/databases/users.json b/server_side/api/modules/databases/users.json index 83a5e71..b5019a8 100644 --- a/server_side/api/modules/databases/users.json +++ b/server_side/api/modules/databases/users.json @@ -1,5 +1,5 @@ { - "efe":{ + "efe": { "id": "9vard12ty0ad2yvwp3q53rsf3h43r2vq", "realname": "Efe Aydın", "avatar": "/img/user1.png", diff --git a/server_side/api/modules/rating_system.py b/server_side/api/modules/rating_system.py index 2410675..877eed5 100644 --- a/server_side/api/modules/rating_system.py +++ b/server_side/api/modules/rating_system.py @@ -1,4 +1,5 @@ import os +import copy import json from api.modules import utils @@ -57,9 +58,8 @@ class Ratings(Resource): class Rating(Resource): def get(self, rating_id): try: - rating = ratings[rating_id - 1] + rating = copy.deepcopy(ratings[rating_id - 1]) del rating['rates'] - del rating['raters'] return rating except: abort(404, error="Rating {} doesn't exist".format(rating_id)) @@ -74,7 +74,7 @@ class Rate(Resource): note=& # ADDITIONAL rater_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']) score = int(request.args['score']) if 0 >= score >= 10: diff --git a/server_side/api/modules/user_info.py b/server_side/api/modules/user_info.py index 31f74de..fc76082 100644 --- a/server_side/api/modules/user_info.py +++ b/server_side/api/modules/user_info.py @@ -1,4 +1,5 @@ import os +import copy import json from api.modules import utils @@ -35,6 +36,7 @@ class Users(Resource): 'bus_usage_month': 0, 'bus_usage_year': 0 }, + 'daily_electricity_usage': [], 'points': 0 } @@ -48,7 +50,7 @@ class Users(Resource): class User(Resource): def get(self, user_id): try: - user = utils.find_by_id( users, user_id ) + user = utils.find_by_id( users.values(), user_id ) if not user: raise Exception('User not found!') del user['password'] @@ -66,20 +68,17 @@ class Login(Resource): #Password for efe is 12345 args = request.form username = args['username'] - passsword = utils.md5( args[ 'password' ] ) + password = utils.md5( args[ 'password' ] ) 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: - return [False,{}] - - - + return [False, {}] if __name__ == '__main__': api.add_resource(Users, '/users', '/users/') diff --git a/server_side/api/modules/voting_system.py b/server_side/api/modules/voting_system.py index e6e4e19..3c79f8f 100644 --- a/server_side/api/modules/voting_system.py +++ b/server_side/api/modules/voting_system.py @@ -1,4 +1,5 @@ import os +import copy import json from api.modules import utils @@ -46,6 +47,7 @@ class Votings(Resource): """ args = request.form + args = request.form voting_id = len(votings) + 1 voting = { 'id': voting_id, @@ -75,10 +77,10 @@ class Votings(Resource): class Voting(Resource): def get(self, voting_id): try: - voting = votings[voting_id - 1].copy() + voting = copy.deepcopy(votings[voting_id - 1]) 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 except: @@ -93,9 +95,9 @@ class Vote(Resource): voter_id = request.form['voter_id'] 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']: - 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]['voters'].append(voter_id) with open(db_path, 'w') as f: