pepkit / pepdbagent

Database for storing sample metadata
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

pepdbagent 0.3.0 #58

Closed khoroshevskyi closed 1 year ago

khoroshevskyi commented 1 year ago

What has been done

nleroy917 commented 1 year ago

Does include stuff for count, limit, and offset?

Example, if I call this:

projects = db.get_projects_in_namespace(
        user=user, namespace=namespace, limit=limit, offset=offset
    )

Do I get a count value back?

khoroshevskyi commented 1 year ago

Do I get a count value back? what do you mean by count value?

khoroshevskyi commented 1 year ago

This are models that you search functions are returning: image

nleroy917 commented 1 year ago

I see, that makes sense thank you. What about just for getting namespace info? Example, this is the /api/v1/{namespace}/projects endpoint:

@namespace.get("/projects", summary="Fetch all projects inside a particular namespace.")
async def get_namespace_projects(
    namespace: str,
    db: Connection = Depends(get_db),
    limit: int = 100,
    offset: int = 0,
    user=Depends(get_user_from_session_info),
):
    """Fetch the projects for a particular namespace"""
    projects = db.get_projects_in_namespace(
        user=user, namespace=namespace, limit=limit, offset=offset
    )
    return JSONResponse(
        content={
            "limit": limit,
            "offset": offset,
            "items": [p.to_dict() for p in projects],
            "count": len(projects), # <-- this should be the total projects in the database for this namespace
        }
    )

Does that make sense? I guess I should look for a ProjectsResult model

Edit: Here I can see that the function is returning List[peppy.Project]. So, I am wondering how I can convey to the UI (or a user using the API) that there might be 10,000 projects, the limit they requested is 100 and the offset is 3. If that makes sense. Maybe this endpoint doesn't need that?

khoroshevskyi commented 1 year ago

This is for projects:

image

This is for namespaces:

image

I should probably change it to pydantic model

khoroshevskyi commented 1 year ago

Do you want to get more then one project in one request? I think we need peppy object only when we are on project page, so API can call get_project() before returning the project page. It will be more efficient, as we are not loading all projects to memory

nleroy917 commented 1 year ago

I see, that makes sense thank you. What about just for getting namespace info? Example, this is the /api/v1/{namespace}/projects endpoint:

@namespace.get("/projects", summary="Fetch all projects inside a particular namespace.")
async def get_namespace_projects(
    namespace: str,
    db: Connection = Depends(get_db),
    limit: int = 100,
    offset: int = 0,
    user=Depends(get_user_from_session_info),
):
    """Fetch the projects for a particular namespace"""
    projects = db.get_projects_in_namespace(
        user=user, namespace=namespace, limit=limit, offset=offset
    )
    return JSONResponse(
        content={
            "limit": limit,
            "offset": offset,
            "items": [p.to_dict() for p in projects],
            "count": len(projects), # <-- this should be the total projects in the database for this namespace
        }
    )

Does that make sense? I guess I should look for a ProjectsResult model

Edit: Here I can see that the function is returning List[peppy.Project]. So, I am wondering how I can convey to the UI (or a user using the API) that there might be 10,000 projects, the limit they requested is 100 and the offset is 3. If that makes sense. Maybe this endpoint doesn't need that?

So, for this example here, this is will be used for serverside pagination... so I guess it'd be nice to have it here since this is the endpoint I was going to call on the UI to fetch the data on page load.

On the UI, I will call something like

function fetchProjectsForNamespace {
  fetch(`/api/v1/{namespace}/projects`)
  .then(res => // use response to populate HTML
  )
}

So it would be nice to have count somewhere to be able to conditionally render the logic for pagination.