← back to kkrlosdev__tasks_api

Function bodies 57 total

All specs Real LLM only Function bodies
update_task_service method · python · L54-L70 (17 LOC)
src/app/services/tasks_service.py
    def update_task_service(self,  id: int, name: str, begin_date: str, end_date: str, short_description: str, long_description: str, status: int):
        if not validate_date(begin_date):
            raise ValueError("Fecha de inicio inválida.")
        if not validate_date(end_date):
            raise ValueError("Fecha de finalización inválida.")

        if len(short_description) > 100:
            raise ValueError("Longitud de la descripción corta excede los 100 carácteres.")

        if status not in (0, 1, 2):
            raise ValueError("Estado inválido.")

        exists = self.repo.get_task_by_id(id)
        if not exists:
            raise NotFoundError("Tarea no encontrada en la base de datos.")

        return self.repo.update_task(id, name, begin_date, end_date, short_description, long_description, status)
fetch_all function · python · L4-L20 (17 LOC)
src/app/utils/fetch_all.py
def fetch_all(cursor) -> list[dict]:
    columns = [desc[0] for desc in cursor.description]
    rows = cursor.fetchall()
    
    def serialize(value):
        if isinstance(value, (datetime, date)):
            return value.strftime('%Y-%m-%d')
        if isinstance(value, Decimal):
            return float(value)
        if isinstance(value, str):
            return value.strip()
        return value

    return [
        {col: serialize(val) for col, val in zip(columns, row)}
        for row in rows
    ]
fetch_one function · python · L1-L8 (8 LOC)
src/app/utils/fetch_one.py
def fetch_one(cursor) -> dict | None:
    columns = [desc[0] for desc in cursor.description]
    row = cursor.fetchone()

    if row is None:
        return None

    return {col: val for col, val in zip(columns, row)}
validate_date function · python · L3-L19 (17 LOC)
src/app/utils/validate_date.py
def validate_date(value: str) -> bool:
    if not value or not isinstance(value, str):
        return False

    formats = [
        "%d-%m-%Y",
        "%d-%m-%Y %H:%M:%S"
    ]

    for format in formats:
        try:
            datetime.strptime(value, format)
            return True
        except ValueError:
            continue

    return False
connect function · python · L7-L12 (6 LOC)
src/db/connection.py
def connect():
    try:
        conn = sqlite3.connect(DB_PATH, timeout=10)
        return conn
    except Exception as e:
        raise Exception(f"Could not connect to database: {e}")
create_tasks_table function · python · L5-L31 (27 LOC)
src/db/scripts/setup.py
def create_tasks_table():
    try:
        conn = connect()
    except Exception as e:
        raise Exception(f"Could not connect to database during table creation: {e}")

    if conn is not None:
        cursor = conn.cursor()

    try:
        cursor.execute("""
                    CREATE TABLE IF NOT EXISTS tasks(
                                        id INTEGER PRIMARY KEY,
                                        name TEXT NOT NULL,
                                        begin_date DATETIME,
                                        end_date DATETIME,
                                        short_description VARCHAR(100),
                                        long_description TEXT,
                                        status INT
                    );
                    """)
        print("Table 'tasks' created successfully!")
    except Exception as e:
        raise Exception(f"Could not create table: {e}")
    finally:
        cursor.close()
        conn.close()
drop_table function · python · L33-L49 (17 LOC)
src/db/scripts/setup.py
def drop_table(table_name: str):
    try:
        conn = connect()
    except Exception as e:
        raise Exception(f"Could not connect to database during DROP TABLE operation: {e}")

    if conn is not None:
        cursor = conn.cursor()

    try:
        cursor.execute(f"DROP TABLE {table_name};")
        print(f"Table {table_name} dropped successfully.")
    except Exception as e:
        raise Exception(f"Could not drop table '{table_name}': {e}")
    finally:
        cursor.close()
        conn.close()
‹ prevpage 2 / 2