forked from fylein/fyle-interview-intern-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New code challenge and add SQL tests (fylein#14)
- Loading branch information
1 parent
e97b4d1
commit d066d7d
Showing
22 changed files
with
435 additions
and
28 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from .student import student_assignments_resources | ||
from .teacher import teacher_assignments_resources |
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
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
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,34 @@ | ||
from flask import Blueprint | ||
from core import db | ||
from core.apis import decorators | ||
from core.apis.responses import APIResponse | ||
from core.models.assignments import Assignment | ||
|
||
from .schema import AssignmentSchema, AssignmentGradeSchema | ||
teacher_assignments_resources = Blueprint('teacher_assignments_resources', __name__) | ||
|
||
|
||
@teacher_assignments_resources.route('/assignments', methods=['GET'], strict_slashes=False) | ||
@decorators.authenticate_principal | ||
def list_assignments(p): | ||
"""Returns list of assignments""" | ||
teachers_assignments = Assignment.get_assignments_by_teacher(p.teacher_id) | ||
teachers_assignments_dump = AssignmentSchema().dump(teachers_assignments, many=True) | ||
return APIResponse.respond(data=teachers_assignments_dump) | ||
|
||
|
||
@teacher_assignments_resources.route('/assignments/grade', methods=['POST'], strict_slashes=False) | ||
@decorators.accept_payload | ||
@decorators.authenticate_principal | ||
def grade_assignment(p, incoming_payload): | ||
"""Grade an assignment""" | ||
grade_assignment_payload = AssignmentGradeSchema().load(incoming_payload) | ||
|
||
graded_assignment = Assignment.mark_grade( | ||
_id=grade_assignment_payload.id, | ||
grade=grade_assignment_payload.grade, | ||
auth_principal=p | ||
) | ||
db.session.commit() | ||
graded_assignment_dump = AssignmentSchema().dump(graded_assignment) | ||
return APIResponse.respond(data=graded_assignment_dump) |
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
Empty file.
Empty file.
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
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,46 @@ | ||
"""principals | ||
Revision ID: 52a401750a76 | ||
Revises: 2087a1db8595 | ||
Create Date: 2024-01-07 19:15:22.771993 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
from core import db | ||
from core.models.users import User | ||
from core.models.principals import Principal | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '52a401750a76' | ||
down_revision = '2087a1db8595' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('principals', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('user_id', sa.Integer(), nullable=True), | ||
sa.Column('created_at', sa.TIMESTAMP(timezone=True), nullable=False), | ||
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), nullable=False), | ||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
principal_user = User(email='principal@fylebe.com', username='principal') | ||
db.session.add(principal_user) | ||
|
||
principal = Principal(user_id=User.get_by_email('principal@fylebe.com').id) | ||
|
||
db.session.add(principal) | ||
db.session.commit() | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('principals') | ||
# ### end Alembic commands ### |
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
Oops, something went wrong.