Skip to content

Commit

Permalink
привел api системы обращений в соответствие с прототипом
Browse files Browse the repository at this point in the history
  • Loading branch information
Puzanovim committed May 30, 2021
1 parent ca77a52 commit 74ac0e5
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 116 deletions.
14 changes: 0 additions & 14 deletions src/desk/dev_routes.py

This file was deleted.

2 changes: 2 additions & 0 deletions src/desk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ class Appeal(Base):
responsible_id = Column(String, ForeignKey('user.id'), nullable=True)
status = Column(Enum(StatusTasks), default=StatusTasks.new)
date_create = Column(DateTime(timezone=True), server_default=sql.func.now())
date_edit = Column(DateTime, default=None)
date_processing = Column(DateTime, default=None)
software_id = Column(Integer, ForeignKey('software.id'), nullable=False)
module_id = Column(Integer, ForeignKey('module.id'), nullable=False)
importance = Column(Integer, default=1)
# attachments


Expand Down
40 changes: 13 additions & 27 deletions src/desk/routes.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from fastapi import APIRouter, status, Depends, Response
from typing import List
from fastapi import APIRouter, status, Depends, Response, HTTPException
from typing import List, Union

from pydantic.types import UUID4

from .services import get_all_appeals, get_appeals, get_appeal, get_comments, get_comment, \
add_appeal, add_comment, update_appeal, update_comment, delete_comment, update_attachments
from .services import get_all_appeals, get_appeal, get_comments, get_comment, \
add_appeal, add_comment, update_appeal, update_comment, delete_comment, get_appeals_page
from .schemas import Appeal, CommentShort, Comment, AppealCreate, CommentCreate, CommentDB, \
AppealUpdate, AppealDB, AppealShort, CommentUpdate, DevAppeal
from ..users.models import UserTable
Expand All @@ -17,36 +15,24 @@
async def appeals_list(user: UserTable = Depends(any_user)):
if user.is_superuser:
return await get_all_appeals()
return await get_appeals(user)


@router.get("/{id}", status_code=status.HTTP_200_OK)
async def appeal(id: int, user: UserTable = Depends(employee)):
return await get_appeal(id, user)
return await get_appeals_page(user)


# @router.get("/{id}", response_model=DevAppeal, status_code=status.HTTP_200_OK)
# async def appeal(id: int, user: UserTable = Depends(developer_user)):
# print("WINDOW OF DEVELOPER")
# print(user.is_superuser)
# return await get_appeal(id, user)
@router.get("/{id}", response_model=Union[Appeal, DevAppeal], status_code=status.HTTP_200_OK)
async def appeal(appeal_id: int, user: UserTable = Depends(any_user)):
return await get_appeal(appeal_id, user)


@router.post("/", response_model=AppealDB, status_code=status.HTTP_201_CREATED)
async def create_appeal(item: AppealCreate, user: UserTable = Depends(employee)):
# TODO сделать проверку на не разработчика
if user.is_superuser is True:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
return await add_appeal(item, user)


# @router.patch("/{id}", status_code=status.HTTP_201_CREATED)
# async def update_attachments_on_appeal(id: int, item: AppealUpdate, user: UserTable = Depends(employee)):
# pass
# return await update_attachments(id, item, user)


@router.patch("/{id}", response_model=AppealDB, status_code=status.HTTP_201_CREATED)
async def update_appeal_by_id(id: int, item: AppealUpdate, user: UserTable = Depends(developer_user)):
return await update_appeal(id, item, user)
@router.patch("/{id}", response_model=AppealDB, status_code=status.HTTP_201_CREATED) # TODO сделать изменение обращения пользователем
async def update_appeal_by_id(appeal_id: int, item: AppealUpdate, user: UserTable = Depends(developer_user)):
return await update_appeal(appeal_id, item, user)


@router.get("/{id}/comments", response_model=List[CommentShort], status_code=status.HTTP_200_OK)
Expand Down
101 changes: 66 additions & 35 deletions src/desk/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,55 @@
from .models import StatusTasks
from pydantic import BaseModel

from ..accounts.client_account.schemas import ClientDB
from ..reference_book.schemas import SoftwareDB, ModuleShort
from ..accounts.client_account.schemas import ClientDB, Client
from ..reference_book.schemas import SoftwareDB, ModuleDB
from ..users.schemas import UserDB


class CommentBase(BaseModel):
text: str


class CommentCreate(CommentBase):
pass


class CommentUpdate(CommentCreate):
pass


class Comment(CommentBase):
id: int
appeal_id: int
author: UserDB
date_create: datetime


class CommentDB(CommentBase):
id: int
appeal_id: int
author_id: str
date_create: datetime


class CommentShort(CommentBase):
id: int
author_id: str
date_create: datetime


class AppealBase(BaseModel):
topic: str
text: str
importance: int
date_edit: Optional[datetime]


class AppealCreate(AppealBase):
text: str
software_id: int
module_id: int
date_create: datetime = datetime.utcnow()
importance: Optional[int] = 1


class AppealUpdate(AppealBase):
Expand All @@ -26,15 +62,19 @@ class AppealUpdate(AppealBase):
software_id: Optional[int]
module_id: Optional[int]
responsible_id: Optional[str]
importance: Optional[int]
date_edit: datetime = datetime.utcnow()


class AppealShort(AppealBase):
id: int
text: str
status: StatusTasks


class AppealDB(AppealBase):
id: int
text: str
client_id: int
author_id: str
status: StatusTasks
Expand All @@ -45,51 +85,42 @@ class AppealDB(AppealBase):
module_id: int


class CommentBase(BaseModel):
text: str


class CommentCreate(CommentBase):
pass


class CommentUpdate(CommentCreate):
pass


class Comment(CommentBase):
class AppealList(AppealBase):
id: int
appeal_id: int
importance: int
title: str
author: UserDB
client: ClientDB
date_create: datetime


class CommentDB(CommentBase):
id: int
appeal_id: int
author_id: str
date_create: datetime


class CommentShort(CommentBase):
id: int
author_id: str
date_create: datetime
responsible: UserDB
status: StatusTasks
software: SoftwareDB
module: ModuleDB


class Appeal(AppealBase):
id: int
client: ClientDB
author: UserDB
responsible: Optional[UserDB]
text: str
status: StatusTasks
date_create: datetime
date_processing: Optional[datetime]
client: ClientDB
author: UserDB
responsible: Optional[UserDB]
software: SoftwareDB
module: ModuleShort
comment: Optional[List[CommentShort]]
module: ModuleDB
comments: Optional[List[CommentShort]]


class AppealsPage(BaseModel):
appeals: List[AppealList]
client: Client
software_list: List[SoftwareDB]
modules_list: List[ModuleDB]


class DevAppeal(Appeal):
software_list: List[SoftwareDB]
modules_list: List[ModuleDB]
developers: List[UserDB]
allowed_statuses: List[StatusTasks]
Loading

0 comments on commit 74ac0e5

Please sign in to comment.