Skip to content

Commit 6c5436b

Browse files
committed
finish week1 API endpoints
1 parent 4be5530 commit 6c5436b

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

endpoints.http

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@baseUrl = http://localhost:6400
2+
3+
### Health
4+
GET {{baseUrl}}/api/v1/health
5+
6+
7+
### List All Todos
8+
GET {{baseUrl}}/api/v1/todos
9+
10+
11+
### Get a specific Todo
12+
GET {{baseUrl}}/api/v1/todos/1
13+
14+
15+
### Create a Todo
16+
POST {{baseUrl}}/api/v1/todos
17+
Content-Type: application/json
18+
19+
{
20+
"title": "An example Todo",
21+
"description": "This is an example todo"
22+
}
23+
24+
25+
### Update a Todo
26+
PUT {{baseUrl}}/api/v1/todos/1
27+
Content-Type: application/json
28+
29+
{
30+
"title": "updated title"
31+
}
32+
33+
34+
### Delete a Todo
35+
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 = "2026-p1-yang-zhenyuan"
3+
version = "0.1.0"
4+
description = ""
5+
authors = [
6+
{name = "Z.Yang",email = "z.yang2020@outlook.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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
return app

todo/views/routes.py

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

0 commit comments

Comments
 (0)