feat(api+testing): select todo by member_id and id
- Added test code coverage with `pytest-cov` - Added comments for member model functions
This commit is contained in:
		@@ -91,6 +91,11 @@ async def insert_member(
 | 
			
		||||
async def update_member_password(
 | 
			
		||||
    db: AsyncConnectionPool, id: int, password_hash: str
 | 
			
		||||
) -> bool:
 | 
			
		||||
    """
 | 
			
		||||
    Updates a member's password (their password_hash to be exact)
 | 
			
		||||
 | 
			
		||||
    Returns a bool, True if successful and False if not
 | 
			
		||||
    """
 | 
			
		||||
    async with db.connection() as conn:
 | 
			
		||||
        async with conn.cursor(row_factory=class_row(Member)) as curr:
 | 
			
		||||
            query = sql.SQL(
 | 
			
		||||
@@ -113,6 +118,11 @@ async def update_member_password(
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def update_member_email_verified(db: AsyncConnectionPool, id: int) -> bool:
 | 
			
		||||
    """
 | 
			
		||||
    Updates a member's email verified status
 | 
			
		||||
 | 
			
		||||
    Returns a bool, True if successful and False if not
 | 
			
		||||
    """
 | 
			
		||||
    async with db.connection() as conn:
 | 
			
		||||
        async with conn.cursor(row_factory=class_row(Member)) as curr:
 | 
			
		||||
            query = sql.SQL(
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,11 @@ class Todo:
 | 
			
		||||
async def select_todos(
 | 
			
		||||
    db: AsyncConnectionPool, member_id: int, complete: bool | None = None
 | 
			
		||||
) -> list[Todo]:
 | 
			
		||||
    """
 | 
			
		||||
    Select multiple Todo(s) from a member_id
 | 
			
		||||
 | 
			
		||||
    Return a list of Todos (can be empty list)
 | 
			
		||||
    """
 | 
			
		||||
    async with db.connection() as conn:
 | 
			
		||||
        async with conn.cursor(row_factory=class_row(Todo)) as curr:
 | 
			
		||||
 | 
			
		||||
@@ -43,3 +48,27 @@ async def select_todos(
 | 
			
		||||
            todos = await curr.fetchall()
 | 
			
		||||
 | 
			
		||||
            return todos
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def select_todo(db: AsyncConnectionPool, id: int, member_id: int) -> Todo | None:
 | 
			
		||||
    """
 | 
			
		||||
    Find exactly one todo task that matches id and member_id
 | 
			
		||||
    in todos list in PostgreSQL database
 | 
			
		||||
 | 
			
		||||
    Return a Todo object or None
 | 
			
		||||
    """
 | 
			
		||||
    async with db.connection() as conn:
 | 
			
		||||
        async with conn.cursor(row_factory=class_row(Todo)) as curr:
 | 
			
		||||
            query = sql.SQL(
 | 
			
		||||
                """
 | 
			
		||||
                SELECT id, complete, due, task
 | 
			
		||||
                    FROM todos
 | 
			
		||||
                    WHERE id = (%s) AND member_id = (%s)
 | 
			
		||||
                """
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
            await curr.execute(query, (id, member_id))
 | 
			
		||||
 | 
			
		||||
            member = await curr.fetchone()
 | 
			
		||||
 | 
			
		||||
            return None if member is None else member
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user