Skip to content

Commit 9c5146a

Browse files
committed
Day 30 - Final Project
1 parent d6933d6 commit 9c5146a

7 files changed

Lines changed: 137 additions & 0 deletions

File tree

Day 30 - Final Project/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Day 30: Final Project
2+
3+
## What You'll Learn:
4+
- Integrated frontend/backend development
5+
- REST API design
6+
- Database integration
7+
- User authentication
8+
- Deployment considerations
9+
10+
## Files:
11+
1. `app/` - Flask backend
12+
2. `templates/` - Frontend HTML templates
13+
3. `static/` - CSS/JavaScript files
14+
4. `requirements.txt` - Dependencies
15+
5. `database.py` - SQLAlchemy models
16+
17+
## Exercises:
18+
1. Extend the application to:
19+
- Add user registration/login functionality
20+
- Implement email notifications
21+
- Add search/filter capabilities
22+
2. Deploy the application to:
23+
- Cloud platform (Heroku/DigitalOcean)
24+
- Configure production database
25+
- Set up CI/CD pipeline

Day 30 - Final Project/Running.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```bash
2+
# Install dependencies
3+
pip install -r requirements.txt
4+
5+
# Start application
6+
python app.py
7+
8+
# Access at http://localhost:5000
9+
```

Day 30 - Final Project/app.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from flask import Flask, render_template, jsonify, request
2+
from database import db, Task
3+
4+
app = Flask(__name__)
5+
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///tasks.db'
6+
db.init_app(app)
7+
8+
@app.route('/')
9+
def home():
10+
return render_template('index.html')
11+
12+
@app.route('/api/tasks', methods=['GET', 'POST'])
13+
def tasks():
14+
if request.method == 'POST':
15+
new_task = Task(
16+
title=request.json['title'],
17+
description=request.json.get('description', '')
18+
)
19+
db.session.add(new_task)
20+
db.session.commit()
21+
return jsonify({"message": "Task created"}), 201
22+
23+
tasks = Task.query.all()
24+
return jsonify([{
25+
"id": task.id,
26+
"title": task.title,
27+
"description": task.description
28+
} for task in tasks])
29+
30+
if __name__ == '__main__':
31+
with app.app_context():
32+
db.create_all()
33+
app.run(debug=True)

Day 30 - Final Project/database.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from sqlalchemy import create_engine, Column, Integer, String, Text
2+
from sqlalchemy.orm import declarative_base
3+
4+
Base = declarative_base()
5+
6+
class Task(Base):
7+
__tablename__ = 'tasks'
8+
id = Column(Integer, primary_key=True)
9+
title = Column(String(100), nullable=False)
10+
description = Column(Text)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Flask==2.3.2
2+
SQLAlchemy==2.0.20
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
document.addEventListener('DOMContentLoaded', () => {
2+
const form = document.getElementById('taskForm');
3+
const taskList = document.getElementById('taskList');
4+
5+
// Load tasks on startup
6+
fetch('/api/tasks')
7+
.then(res => res.json())
8+
.then(tasks => renderTasks(tasks));
9+
10+
form.addEventListener('submit', (e) => {
11+
e.preventDefault();
12+
const newTask = {
13+
title: document.getElementById('title').value,
14+
description: document.getElementById('description').value
15+
};
16+
17+
fetch('/api/tasks', {
18+
method: 'POST',
19+
headers: {'Content-Type': 'application/json'},
20+
body: JSON.stringify(newTask)
21+
})
22+
.then(() => location.reload());
23+
});
24+
25+
function renderTasks(tasks) {
26+
taskList.innerHTML = tasks.map(task => `
27+
<div class="task">
28+
<h3>${task.title}</h3>
29+
<p>${task.description}</p>
30+
<button onclick="deleteTask(${task.id})">Complete</button>
31+
</div>
32+
`).join('');
33+
}
34+
});
35+
36+
function deleteTask(id) {
37+
fetch(`/api/tasks/${id}`, { method: 'DELETE' })
38+
.then(() => location.reload());
39+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Task Manager</title>
5+
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
6+
</head>
7+
<body>
8+
<div class="container">
9+
<h1>Task Manager</h1>
10+
<form id="taskForm">
11+
<input type="text" id="title" placeholder="Task title" required>
12+
<textarea id="description" placeholder="Description"></textarea>
13+
<button type="submit">Add Task</button>
14+
</form>
15+
<div id="taskList"></div>
16+
</div>
17+
<script src="{{ url_for('static', filename='app.js') }}"></script>
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)