Skip to content

Commit 92c048b

Browse files
committed
Refactor DogList component and enhance type annotations in server app
1 parent 526d884 commit 92c048b

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

client/src/components/DogList.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
let loading = true;
1212
let error: string | null = null;
1313
14-
async function fetchDogs() {
14+
const fetchDogs = async () => {
1515
loading = true;
1616
try {
1717
const response = await fetch('/api/dogs');
@@ -25,7 +25,7 @@
2525
} finally {
2626
loading = false;
2727
}
28-
}
28+
};
2929
3030
onMount(() => {
3131
fetchDogs();

server/app.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# filepath: server/app.py
21
import os
3-
from flask import Flask, jsonify
2+
from typing import Dict, List, Any, Optional
3+
from flask import Flask, jsonify, Response
44
from models import init_db, db, Dog, Breed
55

66
# Get the server directory path
7-
base_dir = os.path.abspath(os.path.dirname(__file__))
7+
base_dir: str = os.path.abspath(os.path.dirname(__file__))
88

9-
app = Flask(__name__)
9+
app: Flask = Flask(__name__)
1010
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{os.path.join(base_dir, "dogshelter.db")}'
1111
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
1212

1313
# Initialize the database with the app
1414
init_db(app)
1515

1616
@app.route('/api/dogs', methods=['GET'])
17-
def get_dogs():
17+
def get_dogs() -> Response:
1818
query = db.session.query(
1919
Dog.id,
2020
Dog.name,
@@ -24,7 +24,7 @@ def get_dogs():
2424
dogs_query = query.all()
2525

2626
# Convert the result to a list of dictionaries
27-
dogs_list = [
27+
dogs_list: List[Dict[str, Any]] = [
2828
{
2929
'id': dog.id,
3030
'name': dog.name,
@@ -36,7 +36,7 @@ def get_dogs():
3636
return jsonify(dogs_list)
3737

3838
@app.route('/api/dogs/<int:id>', methods=['GET'])
39-
def get_dog(id):
39+
def get_dog(id: int) -> tuple[Response, int] | Response:
4040
# Query the specific dog by ID and join with breed to get breed name
4141
dog_query = db.session.query(
4242
Dog.id,
@@ -53,7 +53,7 @@ def get_dog(id):
5353
return jsonify({"error": "Dog not found"}), 404
5454

5555
# Convert the result to a dictionary
56-
dog = {
56+
dog: Dict[str, Any] = {
5757
'id': dog_query.id,
5858
'name': dog_query.name,
5959
'breed': dog_query.breed,

0 commit comments

Comments
 (0)