File tree 1 file changed +4
-11
lines changed
1 file changed +4
-11
lines changed Original file line number Diff line number Diff line change 6
6
import model
7
7
import orm
8
8
import repository
9
+ import services
9
10
10
11
11
12
orm .start_mappers ()
12
13
get_session = sessionmaker (bind = create_engine (config .get_postgres_uri ()))
13
14
app = Flask (__name__ )
14
15
15
16
16
- def is_valid_sku (sku , batches ):
17
- return sku in {b .sku for b in batches }
18
-
19
-
20
17
@app .route ("/allocate" , methods = ["POST" ])
21
18
def allocate_endpoint ():
22
19
session = get_session ()
23
- batches = repository .SqlAlchemyRepository (session ). list ( )
20
+ repo = repository .SqlAlchemyRepository (session )
24
21
line = model .OrderLine (
25
22
request .json ["orderid" ], request .json ["sku" ], request .json ["qty" ],
26
23
)
27
24
28
- if not is_valid_sku (line .sku , batches ):
29
- return {"message" : f"Invalid sku { line .sku } " }, 400
30
-
31
25
try :
32
- batchref = model .allocate (line , batches )
33
- except model .OutOfStock as e :
26
+ batchref = services .allocate (line , repo , session )
27
+ except ( model .OutOfStock , services . InvalidSku ) as e :
34
28
return {"message" : str (e )}, 400
35
29
36
- session .commit ()
37
30
return {"batchref" : batchref }, 201
You can’t perform that action at this time.
0 commit comments