diff --git a/mvc/3tier_raf/business_logic.py b/mvc/3tier_raf/business_logic.py new file mode 100644 index 0000000..5e3ab44 --- /dev/null +++ b/mvc/3tier_raf/business_logic.py @@ -0,0 +1,13 @@ +# business_logic.py + +import data_layer + +def initialize_app(): + data_layer.initialize_database() + +def add_task(task_description): + data_layer.add_task_to_db(task_description) + +def get_all_tasks(): + return data_layer.get_all_tasks_from_db() + diff --git a/mvc/3tier_raf/data_layer.py b/mvc/3tier_raf/data_layer.py new file mode 100644 index 0000000..60640e3 --- /dev/null +++ b/mvc/3tier_raf/data_layer.py @@ -0,0 +1,28 @@ +# data_layer.py + +import sqlite3 + +def get_connection(): + conn = sqlite3.connect('tasks.db') + return conn + +def initialize_database(): + conn = get_connection() + cursor = conn.cursor() + cursor.execute(''' + CREATE TABLE IF NOT EXISTS tasks ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + description TEXT NOT NULL + ) + ''') + conn.commit() + conn.close() + +def add_task_to_db(task_description): + conn = get_connection() + cursor = conn.cursor() + cursor.execute('INSERT INTO tasks (description) VALUES (?)', (task_description,)) + conn.commit() + conn.close() + + diff --git a/mvc/3tier_raf/presentation.py b/mvc/3tier_raf/presentation.py new file mode 100644 index 0000000..d835b8c --- /dev/null +++ b/mvc/3tier_raf/presentation.py @@ -0,0 +1,34 @@ +# presentation.py + +import business_logic + +def display_menu(): + print("\nTo-Do List Menu:") + print("1. Add Task") + print("2. List Tasks") + print("3. Exit") + +def main(): + business_logic.initialize_app() + while True: + display_menu() + choice = input("Choose an option: ") + + if choice == '1': + task = input("Enter a new task: ") + business_logic.add_task(task) + print("Task added!") + elif choice == '2': + tasks = business_logic.get_all_tasks() + print("\nYour Tasks:") + for idx, task in enumerate(tasks, start=1): + print(f"{idx}. {task[1]}") + elif choice == '3': + print("Goodbye!") + break + else: + print("Invalid option. Try again.") + +if __name__ == "__main__": + main() + diff --git a/mvc/mvc_raf/model.py b/mvc/mvc_raf/model.py new file mode 100644 index 0000000..3b0e6ab --- /dev/null +++ b/mvc/mvc_raf/model.py @@ -0,0 +1,17 @@ +# model.py + +import business_logic + +class TaskModel: + def __init__(self): + pass + + def initialize_app(self): + business_logic.initialize_app() + + def add_task(self, task_description): + business_logic.add_task(task_description) + + def get_all_tasks(self): + return business_logic.get_all_tasks() +