forked from joerunde/edx-adapt
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
174 additions
and
32 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import edx_adapt.api.adapt_api | ||
|
||
edx_adapt.api.adapt_api.run() |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from flask import Flask | ||
from flask.ext.cors import CORS | ||
from flask_restful import Api | ||
|
||
# import API resources | ||
import resources.course_resources as CR | ||
# import data module | ||
import edx_adapt.data.mockRepository as mock | ||
|
||
app = Flask(__name__) | ||
CORS(app) | ||
api = Api(app) | ||
|
||
# TODO: load from settings | ||
base = '/api/v1' | ||
|
||
data = mock.MockRepository() | ||
|
||
api.add_resource(CR.Courses, base + '/course', | ||
resource_class_kwargs={'data': data}) | ||
api.add_resource(CR.Skills, base + '/course/<str:course_id>/skill', | ||
resource_class_kwargs={'data': data}) | ||
api.add_resource(CR.Users, base + '/course/<str:course_id>/user', | ||
resource_class_kwargs={'data': data}) | ||
api.add_resource(CR.Problems, base + '/course/<str:course_id>', base + '/course/<str:course_id>/skill/<str:skill_name>', | ||
resource_class_kwargs={'data': data}) | ||
|
||
|
||
def run(): | ||
app.run() | ||
|
||
if __name__ == '__main__': | ||
app.run() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
""" This file contains api resource classes dealing with course information. | ||
For example, CRUDding courses, users, problems, skills... | ||
""" | ||
|
||
from flask_restful import Resource, abort, reqparse | ||
|
||
from edx_adapt.data import DataException | ||
|
||
course_parser = reqparse.RequestParser() | ||
course_parser.add_argument('course_id', type=str, required=True, help="Please supply a course ID") | ||
|
||
|
||
class Courses(Resource): | ||
def __init__(self, **kwargs): | ||
self.repo = kwargs['data'] | ||
"""@type repo: DataInterface""" | ||
|
||
def get(self): | ||
courses = [] | ||
try: | ||
courses = self.repo.get_course_ids() | ||
except DataException as e: | ||
abort(500, message=e.message) | ||
return {'course_ids': courses}, 200 | ||
|
||
def post(self): | ||
args = course_parser.parse_args() | ||
try: | ||
self.repo.post_course(args['course_id']) | ||
except DataException as e: | ||
abort(500, message=e.message) | ||
|
||
return {'success': True}, 200 | ||
|
||
|
||
skill_parser = reqparse.RequestParser() | ||
skill_parser.add_argument('skill_name', type=str, required=True, help="Please supply the name of a skill") | ||
|
||
|
||
class Skills(Resource): | ||
def __init__(self, **kwargs): | ||
self.repo = kwargs['data'] | ||
"""@type repo: DataInterface""" | ||
|
||
def get(self, course_id): | ||
skills = [] | ||
try: | ||
skills = self.repo.get_skills(course_id) | ||
except DataException as e: | ||
abort(500, message=e.message) | ||
|
||
return {'skills': skills}, 200 | ||
|
||
def post(self, course_id): | ||
args = skill_parser.parse_args() | ||
try: | ||
self.repo.post_skill(course_id, args['skill_name']) | ||
except DataException as e: | ||
abort(500, message=e.message) | ||
|
||
return {'success': True}, 200 | ||
|
||
|
||
user_parser = reqparse.RequestParser() | ||
user_parser.add_argument('user_id', type=str, required=True, help="Please supply a user ID") | ||
|
||
|
||
class Users(Resource): | ||
def __init__(self, **kwargs): | ||
self.repo = kwargs['data'] | ||
"""@type repo: DataInterface""" | ||
|
||
def get(self, course_id): | ||
finished_users = [] | ||
progress_users = [] | ||
try: | ||
finished_users = self.repo.get_finished_users(course_id) | ||
progress_users = self.repo.get_in_progress_users(course_id) | ||
except DataException as e: | ||
abort(500, message=e.message) | ||
|
||
return {'users': {'finished': finished_users, 'in_progress': progress_users}}, 200 | ||
|
||
def post(self, course_id): | ||
args = user_parser.parse_args() | ||
try: | ||
self.repo.enroll_user(course_id, args['user_id']) | ||
except DataException as e: | ||
abort(500, message=e.message) | ||
|
||
return {'success': True}, 200 | ||
|
||
|
||
problem_parser = reqparse.RequestParser() | ||
problem_parser.add_argument('problem_name', type=str, required=True, help="Please supply a problem name") | ||
problem_parser.add_argument('tutor_url', type=str, required=True, | ||
help="Please supply a link to the problem's page in your tutor") | ||
problem_parser.add_argument('skills', type=list, required=True, | ||
help="Please supply a list of skills that this problem teaches") | ||
problem_parser.add_argument('pretest', type=bool, | ||
help="Set True if this is a pretest problem. Mutually exclusive with posttest") | ||
problem_parser.add_argument('posttest', type=bool, | ||
help="Set True if this is a posttest problem. Mutually exclusive with pretest") | ||
|
||
class Problems(Resource): | ||
def __init__(self, **kwargs): | ||
self.repo = kwargs['data'] | ||
"""@type repo: DataInterface""" | ||
|
||
def get(self, course_id, skill_name): | ||
problems = [] | ||
try: | ||
problems = self.repo.get_problems(course_id, skill_name) | ||
except DataException as e: | ||
abort(500, message=e.message) | ||
|
||
return {'problems': problems}, 200 | ||
|
||
def post(self, course_id): | ||
args = problem_parser.parse_args() | ||
try: | ||
if args['pretest']: | ||
self.repo.post_pretest_problem(course_id, args['skills'], args['problem_name'], args['tutor_url']) | ||
elif args['posttest']: | ||
self.repo.post_posttest_problem(course_id, args['skills'], args['problem_name'], args['tutor_url']) | ||
else: | ||
self.repo.post_problem(course_id, args['skills'], args['problem_name'], args['tutor_url']) | ||
except DataException as e: | ||
abort(500, message=e.message) | ||
|
||
return {'success': True}, 200 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.