Python-powered Chat Apps with Twilio and SendGrid Transcripts
Chapter: Creating the admin backend for Flask
Lecture: Concept: Fulfilling an order

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In our admin back end. We need to fulfill an order and there's two basic steps. In order to do this, we need to go and have some functional
0:09 talk to the database using the SQLAlchemy Unit of Work. Find that order and fulfill it.
0:14 So here we write a simple query on the order say filter right on the id order.id==id. give us the first one If that doesn't exist.
0:22 That means they passed an order_id to an order that doesn't exist. Guess what? You can't fulfill that. We just say return False. But if it's there,
0:30 we can start this fulfillment process. Maybe it's already been fulfilled. We don't want to override that dates. We'll just say, Yeah, sure,
0:36 it's fulfilled. Great. Still fulfilled. And finally, if it's actually unfulfilled and we're switching at date,
0:43 we say the fulfilled date is currently now and then because we're leaving this context. Block this unit of work with commit on success.
0:50 It was true. It's going to insert that change or update that change back to the database and then we'll.
0:56 return True. This is the data layer side of fulfilling in order. We also need a public interface for this to happen.
1:03 Remember, we built that cool admin back end had a table and had that
1:07 green button that said Fulfill when things were unfulfilled and what it would do is it
1:11 would call this flask end point here /admin/fulfill/7 or whatever the number is, we're going to go over here.
1:20 We're actually going to check and see if the order exists. Now, this is a bit of a duplication,
1:25 but I really wanted to make sure we could return 404 and be a good Web citizen independent of whether or not we could fulfill the order.
1:32 So if it doesn't exist, we're going to say 404. But it's still a good idea to have that validation in the service.
1:37 Then we're going to go to the service and say, Fulfill the order and we actually also we're going to go to our WhatsApp service ultimately
1:43 and send the cake ready. We're not doing that yet in this chapter. That's still to come, but that's what is happening overall when we fulfill the order
1:50 so the user will get a message. Hey, your cake is ready. And then we're going to just send them back to that admin page that will have
1:56 the effect of just refreshing that page and they'll see the change state from unfulfilled or
2:01 open to fulfilled. That's it really quite simple to go through that whole process, isn't it.


Talk Python's Mastodon Michael Kennedy's Mastodon