@@ -60,30 +60,73 @@ def create_accounts():
6060######################################################################
6161# LIST ALL ACCOUNTS
6262######################################################################
63+ @app .route ("/accounts" , methods = ["GET" ])
64+ def list_accounts ():
65+ """
66+ List all Accounts
67+ This endpoint will list all Accounts
68+ """
69+ app .logger .info ("Request to list Accounts" )
6370
64- # ... place you code here to LIST accounts ...
71+ accounts = Account .all ()
72+ account_list = [account .serialize () for account in accounts ]
6573
74+ app .logger .info ("Returning [%s] accounts" , len (account_list ))
75+ return jsonify (account_list ), status .HTTP_200_OK
6676
6777######################################################################
6878# READ AN ACCOUNT
6979######################################################################
7080
71- # ... place you code here to READ an account ...
81+ @app .route ("/accounts/<int:account_id>" , methods = ["GET" ])
82+ def get_accounts (account_id ):
83+ """
84+ Reads an Account
85+ This endpoint will read an Account based the account_id that is requested
86+ """
87+ app .logger .info ("Request to read an Account with id: %s" , account_id )
88+ account = Account .find (account_id )
89+ if not account :
90+ abort (status .HTTP_404_NOT_FOUND , f"Account with id [{ account_id } ] could not be found." )
91+ return account .serialize (), status .HTTP_200_OK
7292
7393
7494######################################################################
7595# UPDATE AN EXISTING ACCOUNT
7696######################################################################
97+ @app .route ("/accounts/<int:account_id>" , methods = ["PUT" ])
98+ def update_accounts (account_id ):
99+ """
100+ Update an Account
101+ This endpoint will update an Account based on the posted data
102+ """
103+ app .logger .info ("Request to update an Account with id: %s" , account_id )
104+
105+ account = Account .find (account_id )
106+ if not account :
107+ abort (status .HTTP_404_NOT_FOUND , f"Account with id [{ account_id } ] could not be found." )
77108
78- # ... place you code here to UPDATE an account ...
109+ account .deserialize (request .get_json ())
110+ account .update ()
79111
112+ return account .serialize (), status .HTTP_200_OK
80113
81114######################################################################
82115# DELETE AN ACCOUNT
83116######################################################################
117+ @app .route ("/accounts/<int:account_id>" , methods = ["DELETE" ])
118+ def delete_accounts (account_id ):
119+ """
120+ Delete an Account
121+ This endpoint will delete an Account based on the account_id that is requested
122+ """
123+ app .logger .info ("Request to delete an Account with id: %s" , account_id )
84124
85- # ... place you code here to DELETE an account ...
125+ account = Account .find (account_id )
126+ if account :
127+ account .delete ()
86128
129+ return "" , status .HTTP_204_NO_CONTENT
87130
88131######################################################################
89132# U T I L I T Y F U N C T I O N S
0 commit comments