Skip to content

Commit f751fd9

Browse files
authored
Merge pull request #2 from JustinQ-DNHS/Weston
mergin Weston into Main
2 parents 5eb6e8c + b8df90e commit f751fd9

File tree

9 files changed

+345
-513
lines changed

9 files changed

+345
-513
lines changed

api/binaryLearningGame.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from flask import Blueprint, request, jsonify, g
22
from flask_restful import Api, Resource # used for REST API building
33
from api.jwt_authorize import token_required
4-
from model.binaryLearningGame import binaryLearningGameScores
4+
from model.binaryLearningGame import BinaryLearningGameScores
55

66
"""
77
This Blueprint object is used to define APIs for the Post model.
@@ -28,28 +28,44 @@ class BinaryLearningGameScoresAPI:
2828
- delete: delete a post
2929
"""
3030
class _CRUD(Resource):
31+
3132
@token_required()
3233
def post(self):
3334
# Obtain the current user from the token
3435
current_user = g.current_user
3536
# Obtain the request data sent by the RESTful client API
3637
data = request.get_json()
3738
# Create a new post object using the data from the request
38-
post = binaryLearningGameScores(data['username'], current_user.id, data['score'], data['difficulty'])
39+
post = BinaryLearningGameScores(data['username'], current_user.id, data['score'], data['difficulty'])
3940
# Save the post object using the ORM method defined in the model
4041
post.create()
4142
# Return response to the client in JSON format
4243
return jsonify(post.read())
43-
44+
45+
@token_required()
4446
def get(self):
4547
# Obtain the current user
4648
# current_user = g.current_user
4749
# Find all the posts by the current user
48-
posts = binaryLearningGameScores.query.all()
50+
posts = BinaryLearningGameScores.query.all()
4951
# Prepare a JSON list of all the posts, uses for loop shortcut called list comprehension
5052
json_ready = [post.read() for post in posts]
5153
# Return a JSON list, converting Python dictionaries to JSON format
5254
return jsonify(json_ready)
55+
56+
@token_required("Admin")
57+
def put(self):
58+
"""
59+
Update a section.
60+
"""
61+
# Obtain the request data sent by the RESTful client API
62+
data = request.get_json()
63+
# Find the section to update
64+
updatedScoreData = BinaryLearningGameScores.query.get(data['id'])
65+
# Save the section object using the Object Relational Mapper (ORM) method defined in the model
66+
updatedScoreData.update({'user_score': data['user_score'], 'user_difficulty': data['user_difficulty']})
67+
# Return a JSON restful response to the client
68+
return jsonify(updatedScoreData.read())
5369

5470
@token_required()
5571
def delete(self):
@@ -58,7 +74,7 @@ def delete(self):
5874
# Obtain the request data
5975
data = request.get_json()
6076
# Find the current post from the database table(s)
61-
post = binaryLearningGameScores.query.get(data['id'])
77+
post = BinaryLearningGameScores.query.get(data['id'])
6278
# Delete the post using the ORM method defined in the model
6379
post.delete()
6480
# Return response

api/carChat.py

Lines changed: 0 additions & 211 deletions
This file was deleted.

0 commit comments

Comments
 (0)