1- # filepath: server/app.py
21import os
3- from flask import Flask , jsonify
2+ from typing import Dict , List , Any , Optional
3+ from flask import Flask , jsonify , Response
44from 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__ )
1010app .config ['SQLALCHEMY_DATABASE_URI' ] = f'sqlite:///{ os .path .join (base_dir , "dogshelter.db" )} '
1111app .config ['SQLALCHEMY_TRACK_MODIFICATIONS' ] = False
1212
1313# Initialize the database with the app
1414init_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