CRUD finished
This commit is contained in:
@ -1,18 +1,12 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from uuid import UUID
|
||||
|
||||
from litestar import Controller, get
|
||||
from litestar import Controller, get, post, put
|
||||
from litestar.contrib.repository.filters import LimitOffset, SearchFilter
|
||||
from litestar.di import Provide
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.domain.city import (
|
||||
City,
|
||||
CityReadDTO,
|
||||
CityWriteDTO,
|
||||
Repository,
|
||||
Service,
|
||||
)
|
||||
from app.domain.city import City, CityReadDTO, CityWriteDTO, Repository, Service
|
||||
from app.lib.responses import ObjectListResponse, ObjectResponse
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -55,9 +49,24 @@ class CityController(Controller):
|
||||
content = await service.list(*filters)
|
||||
return ObjectListResponse(content=content)
|
||||
|
||||
@get(DETAIL_ROUTE)
|
||||
async def get_city(
|
||||
self, service: Service, city_id: UUID
|
||||
@post()
|
||||
async def create_city(
|
||||
self,
|
||||
data: City,
|
||||
service: Service,
|
||||
) -> ObjectResponse[City]:
|
||||
content = await service.create(data)
|
||||
return ObjectResponse(content=content)
|
||||
|
||||
@get(DETAIL_ROUTE)
|
||||
async def get_city(self, service: Service, city_id: UUID) -> ObjectResponse[City]:
|
||||
content = await service.get(city_id)
|
||||
return ObjectResponse(content=content)
|
||||
|
||||
@put(DETAIL_ROUTE)
|
||||
async def update_city(
|
||||
self, data: City, service: Service, city_id: UUID
|
||||
) -> ObjectResponse[City]:
|
||||
data.id = city_id
|
||||
content = await service.update(city_id, data)
|
||||
return ObjectResponse(content=content)
|
||||
|
||||
@ -1,18 +1,12 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from uuid import UUID
|
||||
|
||||
from litestar import Controller, get
|
||||
from litestar import Controller, get, post, put
|
||||
from litestar.contrib.repository.filters import LimitOffset, SearchFilter
|
||||
from litestar.di import Provide
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.domain.user import (
|
||||
User,
|
||||
UserReadDTO,
|
||||
UserWriteDTO,
|
||||
Repository,
|
||||
Service,
|
||||
)
|
||||
from app.domain.user import Repository, Service, User, UserReadDTO, UserWriteDTO
|
||||
from app.lib.responses import ObjectListResponse, ObjectResponse
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -55,9 +49,26 @@ class UserController(Controller):
|
||||
content = await service.list(*filters)
|
||||
return ObjectListResponse(content=content)
|
||||
|
||||
@get(DETAIL_ROUTE)
|
||||
async def get_user(
|
||||
self, service: Service, user_id: UUID
|
||||
@post()
|
||||
async def create_user(
|
||||
self,
|
||||
data: User,
|
||||
service: Service,
|
||||
) -> ObjectResponse[User]:
|
||||
print(data)
|
||||
content = await service.create(data)
|
||||
return ObjectResponse(content=content)
|
||||
|
||||
@get(DETAIL_ROUTE)
|
||||
async def get_user(self, service: Service, user_id: UUID) -> ObjectResponse[User]:
|
||||
content = await service.get(user_id)
|
||||
return ObjectResponse(content=content)
|
||||
|
||||
|
||||
@put(DETAIL_ROUTE)
|
||||
async def update_user(
|
||||
self, data: User, service: Service, user_id: UUID
|
||||
) -> ObjectResponse[User]:
|
||||
data.id = user_id
|
||||
content = await service.update(user_id, data)
|
||||
return ObjectResponse(content=content)
|
||||
|
||||
Reference in New Issue
Block a user