Skip to content

Commit

Permalink
Merge pull request #43 from fga-eps-mds/develop
Browse files Browse the repository at this point in the history
new release v1.1.0
  • Loading branch information
SamuelNoB authored Aug 28, 2022
2 parents 880ff53 + df10cea commit 4eebfd7
Show file tree
Hide file tree
Showing 11 changed files with 636 additions and 3 deletions.
32 changes: 31 additions & 1 deletion database/01_create_database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,34 @@ CREATE TABLE "public"."problem" (
REFERENCES "public"."category" ("id")
ON DELETE RESTRICT

);
);

CREATE TABLE "public"."request" (
id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY(start 1),
attendant_name VARCHAR(250),
applicant_name VARCHAR(250),
applicant_phone VARCHAR(20),
place VARCHAR(250),
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
workstation_id INTEGER,
CONSTRAINT "PK_id_request" PRIMARY KEY ("id")
);

CREATE TYPE "public"."priority" AS ENUM ('low', 'normal', 'hight', 'urgent');
CREATE TYPE "public"."status" AS ENUM ('pending', 'in_progress', 'not_solved', 'outsourced', 'solved');

CREATE TABLE "public"."has" (
problem_id INTEGER,
request_id INTEGER,
request_status "public"."status" NOT NULL DEFAULT 'pending',
event_date TIMESTAMP,
is_event BOOLEAN NOT NULL DEFAULT FALSE,
priority "public"."priority" NOT NULL DEFAULT 'normal',
CONSTRAINT "FK_problem_id" FOREIGN KEY ("problem_id")
REFERENCES "public"."problem" ("id")
ON DELETE RESTRICT,
CONSTRAINT "FK_request_id" FOREIGN KEY ("request_id")
REFERENCES request ("id")
ON DELETE SET NULL
);
6 changes: 5 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware

from routers import category, problem
from routers import category, problem, request

app = FastAPI()

app.include_router(request.router)
app.include_router(problem.router)
app.include_router(category.router)

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
Expand Down
61 changes: 60 additions & 1 deletion src/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
from sqlalchemy import TIMESTAMP, Boolean, Column, ForeignKey, Integer, String
import enum

from sqlalchemy import (TIMESTAMP, Boolean, Column, Enum, ForeignKey, Integer,
String, Table, Text)
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func

from database import Base


class EnumStatus(str, enum.Enum):
pending = "pending"
in_progress = "in_progress"
not_solved = "not_solved"
outsourced = "outsourced"
solved = "solved"


class EnumPriority(str, enum.Enum):
low = "low"
normal = "normal"
hight = "hight"
urgent = "urgent"


has = Table(
"has",
Base.metadata,
Column("problem_id", Integer, ForeignKey("problem.id")),
Column("request_id", Integer, ForeignKey("request.id")),
Column("is_event", Boolean, nullable=True),
Column("event_date", TIMESTAMP, nullable=True),
Column(
"request_status",
Enum(EnumStatus),
default=EnumStatus.pending,
nullable=False,
),
Column(
"priority",
Enum(EnumPriority),
default=EnumPriority.normal,
nullable=False,
),
)


class Category(Base):
__tablename__ = "category"
id = Column(Integer, primary_key=True)
Expand All @@ -29,3 +70,21 @@ class Problem(Base):
onupdate=func.current_timestamp(),
)
category_id = Column(Integer, ForeignKey(Category.id))
requests = relationship(
"Request", secondary=has, back_populates="problems"
)


class Request(Base):
__tablename__ = "request"
id = Column(Integer, primary_key=True)
attendant_name = Column(String(250), nullable=False)
applicant_name = Column(String(250), nullable=False)
applicant_phone = Column(String(20), nullable=False)
place = Column(String(250), nullable=False)
description = Column(Text, nullable=True)
created_at = Column(TIMESTAMP, server_default=func.current_timestamp())
workstation_id = Column(Integer, nullable=False)
problems = relationship(
"Problem", secondary=has, back_populates="requests"
)
Loading

0 comments on commit 4eebfd7

Please sign in to comment.