Skip to content

Commit 620afd0

Browse files
committed
Implement week 1 practical
1 parent 97c5271 commit 620afd0

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

endpoints.http

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@baseUrl = http://localhost:6400
2+
### Health
3+
GET {{baseUrl}}/api/v1/health
4+
5+
### List All Todos
6+
GET {{baseUrl}}/api/v1/todos
7+
8+
### Get a specific Todo
9+
GET {{baseUrl}}/api/v1/todos/1
10+
11+
### Create a Todo
12+
POST {{baseUrl}}/api/v1/todos
13+
Content-Type: application/json
14+
15+
{
16+
"title": "An example Todo",
17+
"description": "This is an example todo",
18+
}
19+
20+
### Update a Todo
21+
PUT {{baseUrl}}/api/v1/todos/1
22+
Content-Type: application/json
23+
24+
{
25+
"title": "updated title",
26+
}
27+
### Delete a Todo
28+
DELETE {{baseUrl}}/api/v1/todos/1

pyproject.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[project]
2+
name = "practical01"
3+
version = "0.1.0"
4+
description = ""
5+
authors = [
6+
{name = "MinhQuocLe",email = "223570603+MinhQuocLe@users.noreply.github.com"}
7+
]
8+
readme = "README.md"
9+
requires-python = ">=3.12"
10+
dependencies = [
11+
"flask (>=3.1.3,<4.0.0)"
12+
]
13+
14+
15+
[build-system]
16+
requires = ["poetry-core>=2.0.0,<3.0.0"]
17+
build-backend = "poetry.core.masonry.api"

todo/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from flask import Flask
2+
3+
def create_app():
4+
app = Flask(__name__)
5+
from .views.routes import api
6+
app.register_blueprint(api)
7+
8+
return app

todo/views/__init__.py

Whitespace-only changes.

todo/views/routes.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from flask import Blueprint, jsonify
2+
3+
api = Blueprint('api', __name__, url_prefix='/api/v1')
4+
5+
@api.route('/health')
6+
def health():
7+
return jsonify({"status": "ok"})
8+
9+
@api.route('/todos', methods=['GET'])
10+
def get_todos():
11+
return jsonify([{
12+
"id": 1,
13+
"title": "Watch CSSE6400 Lecture",
14+
"description": "Watch the CSSE6400 lecture on ECHO360 for week 1",
15+
"completed": True,
16+
"deadline_at": "2026-02-27T18:00:00",
17+
"created_at": "2026-02-20T14:00:00",
18+
"updated_at": "2026-02-20T14:00:00"
19+
}])
20+
21+
@api.route('/todos/<int:id>', methods=['GET'])
22+
def get_todo(id):
23+
return jsonify({
24+
"id": id,
25+
"title": "Watch CSSE6400 Lecture",
26+
"description": "Watch the CSSE6400 lecture on ECHO360 for week 1",
27+
"completed": True,
28+
"deadline_at": "2026-02-27T18:00:00",
29+
"created_at": "2026-02-20T14:00:00",
30+
"updated_at": "2026-02-20T14:00:00"
31+
})
32+
33+
34+
@api.route('/todos', methods=['POST'])
35+
def create_todo():
36+
return jsonify({
37+
"id": 1,
38+
"title": "Watch CSSE6400 Lecture",
39+
"description": "Watch the CSSE6400 lecture on ECHO360 for week 1",
40+
"completed": True,
41+
"deadline_at": "2026-02-27T18:00:00",
42+
"created_at": "2026-02-20T14:00:00",
43+
"updated_at": "2026-02-20T14:00:00"
44+
}), 201
45+
46+
@api.route('/todos/<int:id>', methods=['PUT'])
47+
def update_todo(id):
48+
return jsonify({
49+
"id": id,
50+
"title": "Watch CSSE6400 Lecture",
51+
"description": "Watch the CSSE6400 lecture on ECHO360 for week 1",
52+
"completed": True,
53+
"deadline_at": "2026-02-27T18:00:00",
54+
"created_at": "2026-02-20T14:00:00",
55+
"updated_at": "2026-02-20T14:00:00"
56+
})
57+
58+
@api.route('/todos/<int:id>', methods=['DELETE'])
59+
def delete_todo(id):
60+
return jsonify({
61+
"id": id,
62+
"title": "Watch CSSE6400 Lecture",
63+
"description": "Watch the CSSE6400 lecture on ECHO360 for week 1",
64+
"completed": True,
65+
"deadline_at": "2026-02-27T18:00:00",
66+
"created_at": "2026-02-20T14:00:00",
67+
"updated_at": "2026-02-20T14:00:00"
68+
})

0 commit comments

Comments
 (0)