v.0.1.3 - Create your own CRUD service and call an existing one
You can now :
- request the service of an existing CRUDRouter router
- create your own CRUDRouterService to save time
from fastapi_crudrouter_mongodb import CRUDRouterService
"""
The rest of your code should be here
This is an example on how to use the service added to the lib
👇
"""
@app.get("/get_one/{id}")
async def get_one(id: str):
# Assuming you already have a users_router CRUDRouter instance
return await users_router.service.get_one(id)
# Create your own CRUDRouterService with all the CRUD methods provided
class TestModel(MongoModel):
id: Annotated[ObjectId, MongoObjectId] | None = None
name: str
service = CRUDRouterService(TestModel, db, "test")
@app.get("/test")
async def test():
return await service.get_all()