-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Crocodily-3-0/develop
Develop
- Loading branch information
Showing
70 changed files
with
3,216 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,9 @@ __pycache__/ | |
*.pyc | ||
*.pyo | ||
*.pyd | ||
*.local | ||
*.local | ||
|
||
# database | ||
test.db | ||
pre-production.db | ||
production.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from fastapi import APIRouter | ||
from .client_account.routers import client_router as client_router | ||
from .developer_account.routers import developer_router | ||
|
||
accounts_router = APIRouter() | ||
|
||
accounts_router.include_router(client_router, prefix='/clients', tags=['Client']) | ||
accounts_router.include_router(developer_router, prefix='/developers', tags=['Developer']) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, sql | ||
|
||
from ...db.db import Base | ||
|
||
|
||
class Client(Base): | ||
__tablename__ = 'client' | ||
|
||
id = Column(Integer, primary_key=True, index=True, unique=True) | ||
name = Column(String, nullable=False) | ||
avatar = Column(String, nullable=True) | ||
is_active = Column(Boolean, default=False, nullable=False) | ||
date_create = Column(DateTime(timezone=True), server_default=sql.func.now()) | ||
date_block = Column(DateTime, default=None, nullable=True) | ||
owner_id = Column(String, ForeignKey('user.id'), nullable=False) | ||
|
||
|
||
clients = Client.__table__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from fastapi import APIRouter, Depends, status, HTTPException | ||
from pydantic.types import UUID4 | ||
|
||
from .schemas import ClientDB, Client, ClientUpdate, ClientAndOwnerCreate, ClientsPage | ||
from .services import add_client, update_client, get_clients_page, get_client_page, \ | ||
block_client, get_dev_client_page, get_client_info | ||
from src.users.models import UserTable | ||
from src.users.logic import developer_user, any_user, get_owner_with_superuser, get_client_users, default_uuid | ||
from ..employee_account.routers import employee_router | ||
|
||
client_router = APIRouter() | ||
|
||
|
||
@client_router.get("/", response_model=ClientsPage, status_code=status.HTTP_200_OK) | ||
async def clients_list(user: UserTable = Depends(developer_user), last_id: int = 0, limit: int = 9): | ||
return await get_clients_page(last_id, limit) | ||
|
||
|
||
@client_router.post("/", response_model=ClientDB, status_code=status.HTTP_201_CREATED) | ||
async def create_client(item: ClientAndOwnerCreate, user: UserTable = Depends(developer_user)): | ||
return await add_client(item) | ||
|
||
|
||
@client_router.get("/{id}", status_code=status.HTTP_200_OK) | ||
async def client(id: int, user: UserTable = Depends(any_user), last_id: UUID4 = default_uuid, limit: int = 9): | ||
if user.is_superuser: | ||
return await get_dev_client_page(id, last_id, limit) | ||
elif await get_client_users(id, user): | ||
return await get_client_page(id, last_id, limit) | ||
else: | ||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN) | ||
|
||
|
||
@client_router.get("/{id}/info", response_model=Client, status_code=status.HTTP_200_OK) | ||
async def client_info(id: int, user: UserTable = Depends(any_user)): | ||
user = await get_owner_with_superuser(id, user) | ||
return await get_client_info(id) | ||
|
||
|
||
@client_router.patch("/{id}/info", response_model=ClientDB, status_code=status.HTTP_201_CREATED) | ||
async def update_client_by_id(id: int, item: ClientUpdate, user: UserTable = Depends(any_user)): | ||
# TODO разделить изменение аватарки владельцем и изменение владельца владельцем или разработчиком | ||
user = await get_owner_with_superuser(id, user) | ||
return await update_client(id, item) | ||
|
||
|
||
@client_router.patch("/{id}/block", response_model=ClientDB, status_code=status.HTTP_201_CREATED) | ||
async def block_client_by_id(id: int, user: UserTable = Depends(developer_user)): | ||
return await block_client(id) | ||
|
||
|
||
client_router.include_router(employee_router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from datetime import datetime | ||
from typing import Optional, List | ||
|
||
from pydantic import BaseModel, EmailStr, validator | ||
|
||
from ...reference_book.schemas import LicenceDB, SoftwareDB, Licence | ||
from ...users.schemas import UserDB, generate_pwd, Employee, EmployeeList | ||
|
||
|
||
class ClientBase(BaseModel): | ||
name: str | ||
avatar: str | ||
|
||
|
||
class ClientCreate(ClientBase): | ||
name: Optional[str] | ||
owner_id: Optional[str] | ||
|
||
|
||
class ClientAndOwnerCreate(ClientCreate): | ||
owner_name: str | ||
surname: str | ||
patronymic: Optional[str] | ||
email: EmailStr | ||
password: str = generate_pwd() | ||
avatar: Optional[str] | ||
owner_avatar: Optional[str] | ||
is_active: Optional[bool] = True | ||
is_superuser: Optional[bool] = False | ||
is_verified: Optional[bool] = False | ||
owner_licence: int | ||
licences_list: List[int] | ||
|
||
@validator('password') | ||
def valid_password(cls, v: str): | ||
if len(v) < 6: | ||
raise ValueError('Password should be at least 6 characters') | ||
return v | ||
|
||
|
||
class ClientUpdate(ClientBase): # TODO доработать изменение заказчика | ||
name: Optional[str] | ||
owner_id: Optional[str] | ||
avatar: Optional[str] | ||
|
||
|
||
class ClientDB(ClientBase): | ||
id: int | ||
is_active: bool | ||
avatar: str | ||
date_create: datetime | ||
date_block: Optional[datetime] | ||
owner_id: str | ||
|
||
|
||
class ClientShort(ClientDB): | ||
is_active: bool | ||
owner: UserDB | ||
count_employees: int = 0 | ||
|
||
|
||
class Client(ClientBase): | ||
id: int | ||
is_active: bool | ||
date_create: datetime | ||
owner: Employee | ||
licences: List[Licence] | ||
|
||
|
||
class ClientPage(BaseModel): | ||
client: Client | ||
employees_list: List[EmployeeList] | ||
licences_list: List[Licence] | ||
|
||
|
||
class DevClientPage(BaseModel): | ||
client: Client | ||
employees_list: List[EmployeeList] = [] | ||
software_list: List[SoftwareDB] | ||
|
||
|
||
class ClientsPage(BaseModel): | ||
clients_list: List[ClientShort] | ||
licences_list: List[LicenceDB] | ||
|
||
|
||
class EmployeePage(BaseModel): | ||
employee: Employee | ||
client: Client | ||
licences: List[Licence] | ||
|
Oops, something went wrong.