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

Backend/feature/db models #19

Merged
merged 36 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e7778ed
Basic db definition in flask
JibrilExe Feb 20, 2024
12c3641
main.py
JibrilExe Feb 20, 2024
ef77e3b
Defined official db model in SQLalchemy
JibrilExe Feb 21, 2024
dfc8da0
db model definitions in sqlalchemy
JibrilExe Feb 21, 2024
fbee136
flask_sqlalchemy in requirements
JibrilExe Feb 21, 2024
6ab22a4
foutje
JibrilExe Feb 21, 2024
71830fc
fixed db_uri
JibrilExe Feb 21, 2024
bf8d988
db initialization inside create_app
JibrilExe Feb 21, 2024
3e95b1f
db_uri and code clean
JibrilExe Feb 21, 2024
fe2ff03
import order fix
JibrilExe Feb 21, 2024
2035e4a
database uri added
warreprovoost Feb 21, 2024
a57c9f9
.env added to ignore
JibrilExe Feb 22, 2024
16a0d38
Merge branch 'backend/feature/db-models' of https://github.com/SELab-…
JibrilExe Feb 22, 2024
ba36b8a
Updated docs and .gitignore
JibrilExe Feb 22, 2024
a54e712
A first succesfull test for user model
JibrilExe Feb 22, 2024
3214d65
Doc cleanup and test function for courses and course_relations models…
JibrilExe Feb 23, 2024
70a1232
Project and submission test added
JibrilExe Feb 23, 2024
35656a6
added psycopg to dependencies
AronBuzogany Feb 23, 2024
e8d0c5f
dockerized tests to host postgres server
AronBuzogany Feb 23, 2024
bbbb9e7
created test script
AronBuzogany Feb 23, 2024
0802c3d
created test directory to test models
AronBuzogany Feb 23, 2024
88757ae
Merge branch 'backend/feature/db-models' of github.com:SELab-2/UGent-…
AronBuzogany Feb 23, 2024
4b443f7
waiting for postgres service to start before running test scripts and…
AronBuzogany Feb 23, 2024
aa2edcd
changed github action to run test script instead
AronBuzogany Feb 23, 2024
2312254
constructing pytests for models
JibrilExe Feb 23, 2024
7913d7a
running test script with sudo
AronBuzogany Feb 23, 2024
1dbabf2
adding bash to run script
AronBuzogany Feb 23, 2024
763ec84
Merge branch 'backend/feature/db-models' of https://github.com/SELab-…
JibrilExe Feb 23, 2024
b162def
fixing pytest
JibrilExe Feb 23, 2024
f91ce9d
pytests fixed, 1 warning left
JibrilExe Feb 23, 2024
ad43b13
warning fix
JibrilExe Feb 23, 2024
5c18e3d
fixed: run github action job on self-hosted runner
AronBuzogany Feb 23, 2024
43a9f37
fixed: no longer running test script with privileges
AronBuzogany Feb 23, 2024
05a655e
added: installing docker-compose to run our backend tests
AronBuzogany Feb 23, 2024
769e77e
fixed: no longer running compose install with permissions
AronBuzogany Feb 23, 2024
df0d112
using ubuntu-latest runner until docker-compose is installed on our s…
AronBuzogany Feb 23, 2024
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
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ __pycache__/
htmlcov/
docs/_build/
dist/
venv/
venv/
JibrilExe marked this conversation as resolved.
Show resolved Hide resolved
*.env
2 changes: 2 additions & 0 deletions backend/environment.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DB_HOST=postgresql://postgres:postgres@localhost:5432/sel3_db
JibrilExe marked this conversation as resolved.
Show resolved Hide resolved

14 changes: 12 additions & 2 deletions backend/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@
This file is the base of the Flask API. It contains the basic structure of the API.
"""

from flask import Flask, jsonify
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from .endpoints.index import index_bp

db = SQLAlchemy()

def create_app():
"""
Create a Flask application instance.
Returns:
Flask -- A Flask application instance
"""
app = Flask(__name__)

app = Flask(__name__)
app.register_blueprint(index_bp)

return app

def init_db(db_uri):
JibrilExe marked this conversation as resolved.
Show resolved Hide resolved
"""Initialize the database with the given uri"""
JibrilExe marked this conversation as resolved.
Show resolved Hide resolved
app = create_app()
app.config["SQLALCHEMY_DATABASE_URI"] = db_uri
db.init_app(app)
return app
7 changes: 5 additions & 2 deletions backend/project/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""Main entry point for the application."""
from sys import path
from os import getenv
from dotenv import load_dotenv
from project import init_db

path.append(".")

if __name__ == "__main__":
from project import create_app
app = create_app()
load_dotenv(dotenv_path='environment.env')
JibrilExe marked this conversation as resolved.
Show resolved Hide resolved
app = init_db(getenv("DB_HOST"))
app.run(debug=True)
10 changes: 8 additions & 2 deletions backend/project/endpoints/index.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
"""Index api point"""
from flask import Blueprint
from flask_restful import Resource

index_bp = Blueprint("index", __name__)


class Index(Resource):
"""Temporary"""

def get(self):
"""Hello world"""
JibrilExe marked this conversation as resolved.
Show resolved Hide resolved
return {"Message": "Hello World!"}

index_bp.add_url_rule("/", view_func=Index.as_view("index"))


index_bp.add_url_rule("/", view_func=Index.as_view("index"))
Empty file.
24 changes: 24 additions & 0 deletions backend/project/models/course_relations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Models for relation between users and courses"""
# pylint: disable=too-few-public-methods

from sqlalchemy import Integer, Column, ForeignKey, PrimaryKeyConstraint, String
from project import db

class BaseCourseRelation(db.Model):
"""Base class for course relation models"""

__abstract__ = True

course_id = Column(Integer, ForeignKey('Courses.course_id'), nullable=False)
uid = Column(String(255), ForeignKey("Users.uid"), nullable=False)
__table_args__ = PrimaryKeyConstraint("course_id", "uid")

class CourseAdmins(BaseCourseRelation):
"""Admin to course relation model"""

__tablename__ = "course_admins"

class CourseStudents(BaseCourseRelation):
"""Student to course relation model"""

__tablename__ = "course_students"
14 changes: 14 additions & 0 deletions backend/project/models/courses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""The Courses model"""
# pylint: disable=too-few-public-methods
from sqlalchemy import Integer, Column, ForeignKey, String
from project import db


class Courses(db.Model):
"""Course model"""

__tablename__ = "courses"
course_id = Column(Integer, primary_key=True)
name = Column(String(50), nullable=False)
ufora_id = Column(String(50), nullable=True)
teacher = Column(String(255), ForeignKey("Users.uid"), nullable=False)
20 changes: 20 additions & 0 deletions backend/project/models/projects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Model for projects"""
# pylint: disable=too-few-public-methods
from sqlalchemy import ARRAY, Boolean, Column, DateTime, ForeignKey, Integer, String, Text
from project import db

class Projects(db.Model):
"""Project model"""

__tablename__ = "projects"
project_id = Column(Integer, primary_key=True)
title = Column(String(50), nullable=False, unique=False)
descriptions = Column(Text, nullable=False)
assignment_file = Column(String(50))
deadline = Column(DateTime(timezone=True))
course_id = Column(Integer, ForeignKey("Courses.course_id"), nullable=False)
visible_for_students = Column(Boolean, nullable=False)
archieved = Column(Boolean, nullable=False)
test_path = Column(String(50))
script_name = Column(String(50))
regex_expressions = Column(ARRAY(String(50)))
16 changes: 16 additions & 0 deletions backend/project/models/submissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Model for submissions"""
# pylint: disable=too-few-public-methods
from sqlalchemy import Column,String,ForeignKey,Integer,CheckConstraint,DateTime,Boolean
from project import db

class Submissions(db.Model):
"""Submission model"""

__tablename__ = "submissions"
submission_id = Column(Integer, nullable=False, primary_key=True)
uid = Column(String(255), ForeignKey("Users.uid"), nullable=False)
project_id = Column(Integer, ForeignKey("Projects.project_id"), nullable=False)
grading = Column(Integer, CheckConstraint("grading >= 0 AND grading <= 20"))
submission_time = Column(DateTime(timezone=True), nullable=False)
submission_path = Column(String(50), nullable=False)
submission_status = Column(Boolean, nullable=False)
13 changes: 13 additions & 0 deletions backend/project/models/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Model for users"""
# pylint: disable=too-few-public-methods
from sqlalchemy import Boolean, Column, String
from project import db


class Users(db.Model):
"""User model"""

__tablename__ = "users"
uid = Column(String(255), primary_key=True)
is_teacher = Column(Boolean)
is_admin = Column(Boolean)
2 changes: 2 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
flask
flask-restful
flask-sqlalchemy
python-dotenv
Loading