Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add concurrent student sync, instructor sync, assignment sync. sync students and instructors simultaneously #77

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions app/api/api_v1/endpoints/student_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ async def list_students(
students = await StudentService(db).list_students()
return students

@router.post("/students", response_model=StudentSchema)
async def create_student_with_autogen_password(
*,
db: Session = Depends(get_db),
perm: None = Depends(PermissionDependency(StudentCreatePermission)),
student_body: CreateStudentBody
):
student = await StudentService(db).create_student(
**student_body.dict()
)
return student
# @router.post("/students", response_model=StudentSchema)
frostyfan109 marked this conversation as resolved.
Show resolved Hide resolved
# async def create_student_with_autogen_password(
# *,
# db: Session = Depends(get_db),
# perm: None = Depends(PermissionDependency(StudentCreatePermission)),
# student_body: CreateStudentBody
# ):
# student = await StudentService(db).create_student(
# **student_body.dict()
# )
# return student

@router.put("/students/self/fork_cloned", response_model=None)
async def mark_fork_as_cloned(
Expand Down
3 changes: 2 additions & 1 deletion app/core/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
from .ldap import *
from .appstore import *
from .lms import *
from .grading import *
from .grading import *
from .gitea import *
5 changes: 5 additions & 0 deletions app/core/exceptions/assignment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from .base import CustomException

class AssignmentAlreadyExistsException(CustomException):
code = 400
error_code = "ASSIGNMENT__ALREADY_EXISTS"
message = "assignment id or name already in use"

class AssignmentDueBeforeOpenException(CustomException):
code = 400
error_code = "ASSIGNMENT__DUE_BEFORE_OPEN"
Expand Down
45 changes: 45 additions & 0 deletions app/core/exceptions/gitea.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from __future__ import annotations
from httpx import Request, Response, HTTPStatusError
from .base import CustomException

class GiteaBackendException(CustomException):
code = 500
error_code = "GITEA__SERVICE_EXCEPTION"
message = "An error occurred while interacting with Gitea"
response: Response | None = None

def __init__(self, message: str | None = None, request: Request | None = None, response: Response | None = None):
super().__init__(message)
self.request = request
self.response = response

@property
def status_code(self) -> int | None:
if self.response: return self.response.status_code
return None

@classmethod
def from_exception(cls, exc: HTTPStatusError) -> GiteaBackendException:
if exc.response.status_code == 401:
cls = GiteaUnauthorizedException
elif exc.response.status_code == 403:
cls = GiteaForbiddenException
elif exc.response.status_code == 404:
cls = GiteaNotFoundException

return cls(exc.response.text, exc.request, exc.response)

class GiteaUnauthorizedException(GiteaBackendException):
code = 401
error_code = "GITEA__NOT_AUTHORIZED"
message = "gitea backend encountered a 401"

class GiteaForbiddenException(GiteaBackendException):
code = 403
error_code = "GITEA__FORBIDDEN"
message = "gitea backend encountered a 403"

class GiteaNotFoundException(GiteaBackendException):
code = 404
error_code = "GITEA__NOT_FOUND"
message = "gitea backend encountered a 404"
7 changes: 6 additions & 1 deletion app/core/exceptions/lms.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ class LMSBackendException(CustomException):

def __init__(self, message: str | None = None, response: Response | None = None):
super().__init__(message)
self.response = response
self.response = response

@property
def status_code(self) -> int | None:
if self.response: return self.response.status_code
return None
2 changes: 1 addition & 1 deletion app/core/exceptions/user.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .base import CustomException

class UserAlreadyExistsException(CustomException):
code = 409
code = 400
frostyfan109 marked this conversation as resolved.
Show resolved Hide resolved
error_code = "USER__ONYEN_OR_EMAIL_ALREADY_EXISTS"
message = "onyen or email is already in use by another user"

Expand Down
2 changes: 1 addition & 1 deletion app/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy.orm import sessionmaker
from app.core.config import settings

engine = create_engine(settings.SQLALCHEMY_DATABASE_URI, pool_pre_ping=True)
engine = create_engine(settings.SQLALCHEMY_DATABASE_URI, pool_pre_ping=True, executemany_mode="batch")
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()
3 changes: 2 additions & 1 deletion app/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
from .jwt import *
from .commit import *
from .settings import *
from .grade_report import *
from .grade_report import *
from .gitea import *
9 changes: 9 additions & 0 deletions app/schemas/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class AssignmentSchema(BaseModel):
class Config:
orm_mode = True

class CreateAssignmentSchema(BaseModel):
id: int
name: str
directory_path: str
max_attempts: PositiveInt | None
available_date: datetime | None
due_date: datetime | None
is_published: bool

class UpdateAssignmentSchema(BaseModel):
name: str = UNSET
directory_path: str = UNSET
Expand Down
22 changes: 22 additions & 0 deletions app/schemas/gitea.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Optional
from enum import Enum
from pydantic import BaseModel

class CollaboratorPermission(str, Enum):
READ = "read"
WRITE = "write"
ADMIN = "admin"

class FileOperationType(str, Enum):
CREATE = "create"
UPDATE = "update"
DELETE = "delete"

class FileOperation(BaseModel):
# File content
content: str
# Path to file
path: str
# Rename an existing file
from_path: Optional[str]
operation: FileOperationType
10 changes: 5 additions & 5 deletions app/schemas/user/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .user import UserSchema
from .student import StudentSchema
from .instructor import InstructorSchema
from .user_role import UserRoleSchema
from .user_permission import UserPermissionSchema
from .user import *
from .student import *
from .instructor import *
from .user_role import *
from .user_permission import *
8 changes: 7 additions & 1 deletion app/schemas/user/instructor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from pydantic import BaseModel
from datetime import datetime
from .user import UserSchema

class InstructorSchema(UserSchema):
class Config:
orm_mode = True
orm_mode = True

class CreateInstructorSchema(BaseModel):
onyen: str
name: str
email: str
8 changes: 7 additions & 1 deletion app/schemas/user/student.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from pydantic import BaseModel
from datetime import datetime
from .user import UserSchema

class StudentSchema(UserSchema):
fork_remote_url: str
fork_cloned: bool
join_date: datetime
exit_date: datetime | None
exit_date: datetime | None

class CreateStudentSchema(BaseModel):
onyen: str
name: str
email: str
1 change: 1 addition & 0 deletions app/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .ldap_service import *
from .assignment_service import *
from .submission_service import *
from .canvas_service import *
from .course_service import *
from .gitea_service import *
from .appstore_service import *
Expand Down
Loading