Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/controller/admin_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,10 @@
request: Request,
skip: int = Query(0, ge=0, description="Number of records to skip"),
limit: int = Query(10, ge=1, le=100, description="Max records to return"),
email: str = Query(None, description="Filter admins by email"),
):
"""
Retrieve all admins from the database. Requires admin session.
"""
service.get_current_session_admin(request)
return service.get_admins(skip=skip, limit=limit)
return service.get_admins(skip=skip, limit=limit, email=email)

Check warning on line 283 in src/app/controller/admin_controller.py

View check run for this annotation

Codecov / codecov/patch

src/app/controller/admin_controller.py#L283

Added line #L283 was not covered by tests
15 changes: 10 additions & 5 deletions src/app/service/admin_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from app.db.db import db
from app.models.admin import AdminCreate, AdminLogin
from app.schemas.admins import admins_entity

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -94,10 +93,16 @@

return session["email"]

def get_admins(self, skip: int = 0, limit: int = 10):
admins = admins_entity(self.admins_collection.find().skip(skip).limit(limit))
logger.info(f"[SUCCESSFUL] GET: get_admins.\n\tFetched {len(admins)} admins.")
total = self.admins_collection.count_documents({})
def get_admins(self, skip=0, limit=10, email=None):
query = {}

Check warning on line 97 in src/app/service/admin_service.py

View check run for this annotation

Codecov / codecov/patch

src/app/service/admin_service.py#L97

Added line #L97 was not covered by tests
if email:
query["email"] = {"$regex": email, "$options": "i"} # busqueda no-exacta
admins_cursor = self.admins_collection.find(query).skip(skip).limit(limit)
admins = []

Check warning on line 101 in src/app/service/admin_service.py

View check run for this annotation

Codecov / codecov/patch

src/app/service/admin_service.py#L99-L101

Added lines #L99 - L101 were not covered by tests
for admin in admins_cursor:
admin["_id"] = str(admin["_id"]) # <- conversión
admins.append(admin)
total = self.admins_collection.count_documents(query)

Check warning on line 105 in src/app/service/admin_service.py

View check run for this annotation

Codecov / codecov/patch

src/app/service/admin_service.py#L103-L105

Added lines #L103 - L105 were not covered by tests
return {"total": total, "admins": admins}

@staticmethod
Expand Down