6
6
from consts import DB_FILE
7
7
from book import Search , Checkout , Checkin
8
8
from fines import FinesAll , FinesUpdate , FinesPayment
9
+ from borrower import BorrowerCreate
9
10
10
11
app = Flask (__name__ )
11
12
api = Api (app )
@@ -24,27 +25,6 @@ def style(path):
24
25
def scripts (path ):
25
26
return send_from_directory ('./public/scripts' , path )
26
27
27
- # @TODO: Move to Own File
28
- @app .route ('/borrower/create' , methods = ['POST' ])
29
- def create_borrower ():
30
-
31
- args = {'ssn' :request .args .get ('ssn' , '' ), 'bname' :request .args .get ('bname' , '' ), 'address' :request .args .get ('address' , '' ), 'phone' :request .args .get ('phone' , 'NULL' )}
32
-
33
- with sql .connect (DB_FILE ) as conn :
34
- conn .row_factory = sql .Row
35
- c = conn .cursor ()
36
-
37
- # Check for existing SSN and return useful error if it already exists
38
- if c .execute ("SELECT * FROM BORROWER WHERE Ssn = :ssn" , args ).fetchone ():
39
- return {"message" : "Only one borrower card per person. Ssn must be unique." }, 409
40
-
41
- # Create borrower
42
- command = "INSERT INTO BORROWER (Ssn, Bname, Address, Phone) VALUES (:ssn, :bname, :address, :phone);"
43
- c .execute (command , args )
44
-
45
- card_id = c .execute ("SELECT Card_id FROM BORROWER WHERE Ssn = :ssn" , args ).fetchone ()["Card_id" ]
46
- return {"message" : "Borrower Successfully Created. Card ID: " + 'ID{:0>6}' .format (str (card_id )) + "." , "card_id_str" : 'ID{:0>6}' .format (str (card_id )), "card_id_num" : card_id }, 200
47
-
48
28
49
29
# Endpoints
50
30
api .add_resource (Search , '/book/search' , endpoint = 'search' )
@@ -59,6 +39,8 @@ def create_borrower():
59
39
60
40
api .add_resource (FinesPayment , '/fines/payment' , endpoint = 'fines_payment' )
61
41
42
+ api .add_resource (BorrowerCreate , '/borrower/create' , endpoint = 'borrower_create' )
43
+
62
44
if __name__ == '__main__' :
63
45
64
46
# DB reset command line argument
0 commit comments