Skip to content

Commit

Permalink
feat: #52 update models
Browse files Browse the repository at this point in the history
- re-design the models to adapt new workflow
  • Loading branch information
miguelcsx committed Aug 31, 2024
1 parent 95276ef commit f50b4cd
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 122 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: local
hooks:
- id: run-pylint
name: Run Pylint
entry: ./scripts/run_pylint.sh
language: system
pass_filenames: false
45 changes: 0 additions & 45 deletions app/api/v_1/endpoints.py

This file was deleted.

88 changes: 43 additions & 45 deletions app/database/models.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# app/database/models.py

from enum import Enum
from sqlalchemy import (
Column,
Integer,
String,
ForeignKey,
Text,
)
from sqlalchemy.orm import relationship
from app.database.session import Base


class ActivityType(Enum):
question = "question"


class User(Base):
__tablename__ = "users"

Expand All @@ -21,68 +25,62 @@ class User(Base):
created_at = Column(String)
updated_at = Column(String)

courses = relationship("Course", back_populates="creator")
topics = relationship("Topic", back_populates="created_by")
study_sessions = relationship("StudySession", back_populates="user")
activities = relationship("Activity", back_populates="user")
questions = relationship("Question", back_populates="user")
answers = relationship("Answer", back_populates="user")


class Course(Base):
__tablename__ = "courses"
class StudySession(Base):
__tablename__ = "study_sessions"

id: Column = Column(Integer, primary_key=True, index=True)
title: Column = Column(String, index=True)
description: Column = Column(Text)
creator_id: Column = Column(Integer, ForeignKey("users.id"))
created_at = Column(String)
updated_at = Column(String)
user_id: Column = Column(Integer, ForeignKey("users.id"))
start_time: Column = Column(String)
end_time: Column = Column(String)

creator = relationship("User", back_populates="courses")
topics = relationship("Topic", back_populates="course")
user = relationship("User", back_populates="study_sessions")
activities = relationship("Activity", back_populates="study_session")


class Topic(Base):
__tablename__ = "topics"
class Activity(Base):
__tablename__ = "activities"

id: Column = Column(Integer, primary_key=True, index=True)
title: Column = Column(String, index=True)
description: Column = Column(Text)
course_id: Column = Column(Integer, ForeignKey("courses.id"), nullable=True)
creator_id: Column = Column(Integer, ForeignKey("users.id"))
created_at: Column = Column(String)
updated_at: Column = Column(String)
user_id: Column = Column(Integer, ForeignKey("users.id"))
study_session_id: Column = Column(Integer, ForeignKey("study_sessions.id"))
type: Column = Column(Enum(ActivityType), nullable=False)
activity: Column = Column(String)
created_at = Column(String)

course = relationship("Course", back_populates="topics")
created_by = relationship("User", back_populates="topics")
resources = relationship("Resource", back_populates="topic")
study_sessions = relationship("StudySession", back_populates="topic")
user = relationship("User", back_populates="activities")
study_session = relationship("StudySession", back_populates="activities")

question = relationship("Question", back_populates="activity", uselist=False)

class Resource(Base):
__tablename__ = "resources"

id: Column = Column(Integer, primary_key=True, index=True)
title: Column = Column(String, index=True)
description: Column = Column(Text)
type_of: Column = Column(String)
url: Column = Column(String)
topic_id: Column = Column(Integer, ForeignKey("topics.id"))
creator_id: Column = Column(Integer, ForeignKey("users.id"))
created_at: Column = Column(String)
updated_at: Column = Column(String)
class Question(Base):
__tablename__ = "questions"

topic = relationship("Topic", back_populates="resources")
creator = relationship("User")
id: Column = Column(Integer, primary_key=True, index=True)
user_id: Column = Column(Integer, ForeignKey("users.id"))
activity_id: Column = Column(Integer, ForeignKey("activities.id"))
question: Column = Column(String)

user = relationship("User", back_populates="questions")
answers = relationship("Answer", back_populates="question")
activity = relationship("Activity", back_populates="question")


class StudySession(Base):
__tablename__ = "study_sessions"
class Answer(Base):
__tablename__ = "answers"

id: Column = Column(Integer, primary_key=True, index=True)
user_id: Column = Column(Integer, ForeignKey("users.id"))
topic_id: Column = Column(Integer, ForeignKey("topics.id"))
start_time: Column = Column(String)
end_time: Column = Column(String)
technique: Column = Column(String)
question_id: Column = Column(Integer, ForeignKey("questions.id"))
answer: Column = Column(String)

user = relationship("User", back_populates="study_sessions")
topic = relationship("Topic", back_populates="study_sessions")
user = relationship("User", back_populates="answers")
question = relationship("Question", back_populates="answers")
parent_answer = relationship("Answer", remote_side=[id], back_populates="child_answers")
child_answers = relationship("Answer", back_populates="parent_answer", cascade="all, delete-orphan")
13 changes: 0 additions & 13 deletions app/repositories/course_repository.py

This file was deleted.

17 changes: 0 additions & 17 deletions app/schemas/course.py

This file was deleted.

2 changes: 0 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import uvicorn
from app.api.endpoints import (
user,
courses,
)
from app.database.session import (
Base,
Expand All @@ -18,7 +17,6 @@
Base.metadata.create_all(bind=engine)

app.include_router(user.router)
app.include_router(courses.router)

def get_session():
db = Session(bind=engine)
Expand Down
Empty file removed scripts/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions scripts/run_pylint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

# Set up Python environment (assuming Python 3.10 is already installed)
python_version="3.10"

# Optionally create and activate a virtual environment
# python -m venv venv
# source venv/bin/activate

# Upgrade pip and install dependencies
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pylint

# Run pylint
pylint --rcfile=.pylintrc $(git ls-files '*.py')

0 comments on commit f50b4cd

Please sign in to comment.