Skip to content

Commit

Permalink
basic enrollment API
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumukh committed Jan 17, 2016
1 parent 9ea6b6c commit 478a727
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
39 changes: 32 additions & 7 deletions server/controllers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def can(object, user, course, action):


class PublicResource(Resource):
method_decorators = [check_version]
method_decorators = []


class v3Info(Resource):
class v3Info(PublicResource):
def get(self, user):
return {
'version': API_VERSION,
Expand Down Expand Up @@ -266,6 +266,28 @@ class SubmissionSchema(BackupSchema):
'created': fields.DateTime(dt_format='rfc822')
}

class CourseSchema(APISchema):
get_fields = {
'id': fields.Integer,
'name': fields.String,
'display_name': fields.String,
'active': fields.Boolean,
}


class ParticipationSchema(APISchema):
get_fields = {
'course_id': fields.Integer,
'role': fields.String,
'course': fields.Nested(CourseSchema.get_fields),
}

class EnrollmentSchema(APISchema):

get_fields = {
'courses': fields.List(fields.Nested(ParticipationSchema.get_fields))
}


class Backup(Resource):
""" Submission retreival resource.
Expand Down Expand Up @@ -345,18 +367,21 @@ def post(self, user):
return {'id': score.id, 'backup': 1}


class Enrollment(Resource):
class Enrollment(PublicResource):
""" View what courses students are enrolled in.
Authenticated. Permissions: >= User
Used by: Ok Client Auth
"""
model = models.Participant
schema = EnrollmentSchema()

def get(self, email, user):
@marshal_with(schema.get_fields)
def get(self, email):
course = request.args.get('course', '') # TODO use reqparse
if course:
return {'created': str(datetime.datetime.now())}
return {}
user = models.User.lookup(email)
if course and user:
return {'courses': user.participations}
return {'courses': []}

api.add_resource(v3Info, '/v3')

Expand Down
1 change: 0 additions & 1 deletion server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

db = SQLAlchemy()


class TimestampMixin(object):
created = db.Column(db.DateTime, server_default=db.func.now())

Expand Down

0 comments on commit 478a727

Please sign in to comment.