Coverage for /usr/lib/python3.10/site-packages/hyd/backend/project/models.py: 100%
25 statements
« prev ^ index » next coverage.py v7.0.3, created at 2023-01-05 15:47 +0000
« prev ^ index » next coverage.py v7.0.3, created at 2023-01-05 15:47 +0000
1import datetime as dt
2from typing import TypedDict
4from fastapi import status
5from sqlalchemy import Column, Integer, String
6from sqlalchemy.orm import Mapped, relationship
8from hyd.backend.db import EXTEND_EXISTING, DeclarativeMeta
9from hyd.backend.util.const import MAX_LENGTH_STR_ID
10from hyd.backend.util.models import (
11 BASE_API_RESPONSE_SCHEMA,
12 DETAIL_STR,
13 NameStr,
14 PrimaryKey,
15 TimeStampMixin,
16)
18####################################################################################################
19#### SQLAlchemy table definitions
20####################################################################################################
23class ProjectEntry(DeclarativeMeta, TimeStampMixin):
24 __tablename__ = "project_table"
25 __table_args__ = {"extend_existing": EXTEND_EXISTING}
27 id: Mapped[PrimaryKey] = Column(Integer, primary_key=True)
28 name: Mapped[NameStr] = Column(String(length=MAX_LENGTH_STR_ID), unique=True)
30 version_entries: Mapped[list["VersionEntry"]] = relationship(
31 "VersionEntry", back_populates="project_entry"
32 ) # no cascade="delete" because delete has to be done manually to remove files from disc
34 tag_entries: Mapped[list["TagEntry"]] = relationship(
35 "TagEntry", back_populates="project_entry", cascade="all,delete"
36 )
39####################################################################################################
40#### Response schema
41####################################################################################################
44class ProjectResponseSchema(TypedDict):
45 id: PrimaryKey
46 name: NameStr
47 created_at: dt.datetime
48 versions: list[NameStr]
49 tags: list[NameStr]
52####################################################################################################
53#### OpenAPI definitions
54####################################################################################################
57API_V1_CREATE__POST = {
58 **BASE_API_RESPONSE_SCHEMA,
59 status.HTTP_200_OK: {"model": ProjectResponseSchema},
60 status.HTTP_400_BAD_REQUEST: DETAIL_STR,
61}
64API_V1_LIST__GET = {
65 **BASE_API_RESPONSE_SCHEMA,
66 status.HTTP_200_OK: {"model": list[ProjectResponseSchema]},
67}
70API_V1_GET__GET = {
71 **BASE_API_RESPONSE_SCHEMA,
72 status.HTTP_200_OK: {"model": ProjectResponseSchema},
73 status.HTTP_400_BAD_REQUEST: DETAIL_STR,
74}
77API_V1_DELETE__DELETE = {
78 **BASE_API_RESPONSE_SCHEMA,
79 status.HTTP_200_OK: {"model": ProjectResponseSchema},
80 status.HTTP_400_BAD_REQUEST: DETAIL_STR,
81}