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

feat: Add Pagination Support to GET /api/v1/activity-log Endpoint #1197 #1223

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open
41 changes: 0 additions & 41 deletions .env.sample
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this deleted, revert it

This file was deleted.

32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,35 @@ cython_debug/
#.idea/

alembic/versions

# Ignore environment files
.env
.env.*
.ven
.venv
env
alembic/env.py

# Ignore environment and virtual environment files
.env
.env.*
.ven
.venv
env
alembic/env.py

# Ignore environment and virtual environment files
.env
.env.*
.ven
.venv
env
alembic/env.py

# Ignore environment and virtual environment files
.env
.env.*
.ven
.venv
env
alembic/env.py
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the repitions??

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ GRANT ALL PRIVILEGES ON DATABASE hng_fast_api TO user;

**Starting the database**
after cloning the database, dont run
`alembic revision --autogenerate -m 'initial migration'`
`embic revision --autogenerate -m al'initial migration'`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this

but run
`alembic upgrade head`

Expand Down
16 changes: 11 additions & 5 deletions api/v1/routes/activity_logs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter, Depends, status, HTTPException
from fastapi import APIRouter, Depends, status, HTTPException, Query
from fastapi.encoders import jsonable_encoder
from sqlalchemy.orm import Session
from api.v1.models.user import User
Expand Down Expand Up @@ -30,11 +30,17 @@ async def create_activity_log(
)



@activity_logs.get("", response_model=list[ActivityLogResponse])
async def get_all_activity_logs(current_user: User = Depends(user_service.get_current_super_admin), db: Session = Depends(get_db)):
'''Get all activity logs'''

activity_logs = activity_log_service.fetch_all(db=db)
async def get_all_activity_logs(
page: int = Query(1, ge=1),
limit: int = Query(10, le=100),
current_user: User = Depends(user_service.get_current_super_admin),
db: Session = Depends(get_db)
):

"""Get paginated activity logs"""
activity_logs = activity_log_service.fetch_all(db=db, page=page, limit=limit)
Comment on lines +42 to +43
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just passing the page and page limits doesn't mean it's reflected in the implementation.


return success_response(
status_code=200,
Expand Down
3 changes: 2 additions & 1 deletion api/v1/services/activity_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def fetch_all(self, db: Session, **query_params: Optional[Any]):

return query.all()

def delete_activity_log_by_id(self, db: Session, log_id: str):
def delete_activity_log_by_id(self, db: Session, log_id: str) -> bool:
"""Delete an activity log by ID with error handling"""
log = db.query(ActivityLog).filter(ActivityLog.id == log_id).first()

if not log:
Expand Down