Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add routes of APIRouter to easy auth api router #99

Open
aghure opened this issue Apr 27, 2023 · 2 comments
Open

How to add routes of APIRouter to easy auth api router #99

aghure opened this issue Apr 27, 2023 · 2 comments

Comments

@aghure
Copy link

aghure commented Apr 27, 2023

I am trying to use easy auth with fast api class base view.
To do the same , i need to have APIRouter.routes type property to easyAuthAPIRouter.
Is there any way to add the same to EasyAuthAPIRouter.

@codemation
Copy link
Owner

Hello @aghure , every EasyAuthAPIRouter has an api_router attribute which is a direct reference to the APIRouter instance created, perhaps you can reference the routes property here? If that does not work for you, I would need a more substantial code example of what you are trying to accomplish along with additional context.

@aghure
Copy link
Author

aghure commented Apr 28, 2023

Hi @codemation I am trying to use the EasyAuthAPIRouter with class base views. Adding example below about what i am trying to do and adding sample output below.


import logging
from sqlalchemy.orm import  Session
from fastapi import APIRouter, Request, Body ,Depends
from fastapi.responses import JSONResponse

from fastapi_utils.cbv import cbv
from ml_app.core import  get_db
from easyauth.router import  EasyAuthAPIRouter
logger = logging.getLogger(__name__)
test_cbv_router = EasyAuthAPIRouter.create(prefix='/finance', tags=['finance'])
@cbv(test_cbv_router.server)  # Step 2: Create and decorate a class to hold the endpoints
class TestCBV:
   
    db_session : Session = Depends(get_db)
    @test_cbv_router.post("/test")
    def test_url(self,request: Request):
        return  JSONResponse({'status':'ok'})
@test_cbv_router.get("/existing")
def existing_contact(request: Request,db_session: Session = Depends(get_db)):

    result = dict()
    result["result_data"] = ["contact_list"]
    result["tmpl_name"] = "existing.html"
    return  result


image

The @cbv is class base view router of https://github.com/dmontagu/fastapi-utils, it needs APIRouter() instance to add the routes in the app.
We want to use EasyAuthAPIRouter with class base views.
So with EasyAuthAPIRouter.server we get APIRouter() , but CBV is adding it in base app .
Here I have highlighted the URL issues happening because of the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants