Skip to content

Commit

Permalink
Get classes route and small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
abbudao committed Oct 31, 2019
1 parent dcb81d6 commit 04946fe
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 13 deletions.
6 changes: 5 additions & 1 deletion models/classroom.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import datetime
from .base import Base
from sqlalchemy import Column, String, Integer, ForeignKey, UniqueConstraint
from sqlalchemy import (Column, String, Integer, ForeignKey, UniqueConstraint,
DateTime)
from sqlalchemy.orm import relationship


Expand All @@ -11,6 +13,8 @@ class Class(Base):
owner = Column(String, ForeignKey('users.email'))
name = Column(String, nullable=False)
invite_token = Column(String, nullable=False)
created_at = Column(DateTime, default=datetime.utcnow,
nullable=False)
students = relationship("User", secondary='users_classes_association',
back_populates="classes")
tracks = relationship("Track", secondary='tracks_classes_association',
Expand Down
2 changes: 1 addition & 1 deletion models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class User(Base):
email = Column(String, primary_key=True)
name = Column(String, nullable=False)
nickname = Column(String, nullable=False)
is_teacher = Column(Boolean, default=False)
is_teacher = Column(Boolean, default=True)
token = Column(String, nullable=False)
github_token = Column(String, nullable=False)
avatar_url = Column(String, nullable=True)
Expand Down
2 changes: 0 additions & 2 deletions server/static/js/2.c9ea58f0.chunk.js

This file was deleted.

1 change: 0 additions & 1 deletion server/static/js/2.c9ea58f0.chunk.js.map

This file was deleted.

2 changes: 2 additions & 0 deletions server/static/js/2.ee937940.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions server/static/js/2.ee937940.chunk.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions server/static/js/main.5369998a.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions server/static/js/main.5369998a.chunk.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions server/static/js/main.d13865bf.chunk.js

This file was deleted.

1 change: 0 additions & 1 deletion server/static/js/main.d13865bf.chunk.js.map

This file was deleted.

8 changes: 4 additions & 4 deletions server/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
};
</script>
{% if debug %}

<script src="http://localhost:3000/static/js/bundle.js""></script>
<script src="http://localhost:3000/static/js/main.chunk.js"></script>
<script src="http://localhost:3000/static/js/0.chunk.js"></script>
{% else %}
<script type="text/javascript" src="static/js/runtime-main.dee1a991.js"></script>
<script type="text/javascript" src="/static/js/2.c9ea58f0.chunk.js"></script>
<script type="text/javascript" src="static/js/main.d13865bf.chunk.js"></script>
<script type="text/javascript" src="static/js/2.ee937940.chunk.js"></script>
<script type="text/javascript" src="static/js/main.5369998a.chunk.js"></script>
{% endif %}
</body>
</html>
</html>
31 changes: 30 additions & 1 deletion server/views/classes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
from flask import Blueprint, Response
from flask import Blueprint, Response, jsonify
from models import Class, Track
from server.utils import extract_token, extract_user, handle_validation_error
from uuid import uuid4


def extract_class_data(classroom):
return {
"name": classroom.name,
"created_at": classroom.created_at.isoformat(),
"members": len(classroom.students),
"tracks": len(classroom.tracks_classes),
}


def create_classes_blueprint(db_session, request):
classes = Blueprint('classes', __name__)

@classes.route('/', methods=['GET'])
@handle_validation_error
def get_all_classes():
token = extract_token(request)
user = extract_user(db_session, token)

if not user.is_teacher:
return Response(response="Only teachers can see classes.",
status=403)

existing_classes = db_session\
.query(Class)\
.filter_by(owner=user.email)\
.all()

classes_data = [extract_class_data(classroom)
for classroom in existing_classes]

return jsonify(classes_data)

@classes.route('/<name>', methods=['POST'])
@handle_validation_error
def create_class(name):
Expand Down

0 comments on commit 04946fe

Please sign in to comment.