---Presenter: Eric WeatherSubject: How to Create RequestsDuration: 00:33:01---00:00:05.640 --> 00:00:10.608 - In this video, we're going to be talking about how we're creating 00:00:10.608 --> 00:00:14.748 - requests, request handlers, and how we're calling those from our 00:00:14.748 --> 00:00:20.130 - job. This is going to be a lengthy video. This is going to 00:00:20.130 --> 00:00:25.098 - also include how mediator uses these and then and then we can 00:00:25.098 --> 00:00:27.168 - kind of move forward with 00:00:27.168 --> 00:00:31.900 - creating those. And then calling them. So again, it's going to be 00:00:31.900 --> 00:00:35.332 - a lengthier video. So this covers all of that. So we're 00:00:35.332 --> 00:00:37.204 - going to start in our ERP 00:00:37.204 --> 00:00:41.160 - connector. And take a look exactly what it's doing. So in 00:00:41.160 --> 00:00:44.813 - this case it's R training Web API, so we're going to take a 00:00:44.813 --> 00:00:48.185 - look at our requests and we're going to start with the base 00:00:48.185 --> 00:00:50.995 - request. In this case, it's going to be training request. 00:00:50.995 --> 00:00:54.367 - It's going to be whatever your base request is. So for example, 00:00:54.367 --> 00:00:57.739 - if you're doing if you're doing a sage, integration is going to 00:00:57.739 --> 00:01:00.830 - be sage 300 requests. If you're doing a CRM integration, CRM 00:01:00.830 --> 00:01:04.202 - requests, that's just going to be the base, and this is going 00:01:04.202 --> 00:01:07.855 - to contain all of the Valley. All of the fields that you need 00:01:07.855 --> 00:01:10.946 - for every single request for crud for all of your crud. 00:01:10.980 --> 00:01:13.514 - In the case of the Web API. 00:01:14.290 --> 00:01:16.982 - The table is necessary 00:01:16.982 --> 00:01:20.846 - throughout so. If we're creating products, if we're 00:01:20.846 --> 00:01:23.128 - listing products updating, reading, deleting products, we 00:01:23.128 --> 00:01:26.062 - have to specify that table because the endpoint requires 00:01:26.062 --> 00:01:28.996 - that we can't just delete everything, we're going to 00:01:28.996 --> 00:01:32.908 - delete a table. We're going to create to a table, so that's 00:01:32.908 --> 00:01:36.820 - where this comes from. If you have other values that are the 00:01:36.820 --> 00:01:40.080 - same, you'll add to this class. So let's say for 00:01:40.080 --> 00:01:43.992 - example, you also like Seth. Does you have a schema? So you 00:01:43.992 --> 00:01:47.904 - have your schema and then your table. So we would add a 00:01:47.904 --> 00:01:49.208 - public string of schema. 00:01:52.460 --> 00:01:56.266 - And then we would need to give it to ourselves here. 00:01:58.870 --> 00:02:00.190 - And then add it here. 00:02:04.340 --> 00:02:06.716 - So you can do that for whatever you need to use 00:02:06.716 --> 00:02:09.308 - across all requests. We don't need to do that for our Web 00:02:09.308 --> 00:02:11.684 - API, so we're going to go ahead and remove this back 00:02:11.684 --> 00:02:11.900 - out. 00:02:14.970 --> 00:02:15.729 - But for now. 00:02:17.000 --> 00:02:19.938 - That's how you would do it. OK, so the first the request that 00:02:19.938 --> 00:02:22.876 - we're going to create in this video is a list request, but you 00:02:22.876 --> 00:02:26.040 - can see how they're going to be created in the rest of AM and 00:02:26.040 --> 00:02:29.430 - will probably do a video on how to do create how to do a read, 00:02:29.430 --> 00:02:30.560 - how to do an update. 00:02:30.570 --> 00:02:33.683 - Forward, but for the moment, let's just do a list request. 00:02:33.683 --> 00:02:37.928 - OK, so the base the way that the list request is set up is we 00:02:37.928 --> 00:02:41.607 - have a list request of a generic T model, so we're not specifying 00:02:41.607 --> 00:02:44.720 - the model at this level will specify that at the concrete 00:02:44.720 --> 00:02:46.984 - request level. So if we're specifically talking about 00:02:46.984 --> 00:02:48.682 - products, will set that at that 00:02:48.682 --> 00:02:52.590 - level. And then it inherits from the training request. So that's 00:02:52.590 --> 00:02:57.296 - how we get access to the table. However, we need to create the 00:02:57.296 --> 00:02:59.468 - constructor for the table by an 00:02:59.468 --> 00:03:02.916 - hour constructor. Going going ahead and constructing the base. 00:03:02.916 --> 00:03:06.492 - You doing this with the table that we're bringing in. So let's 00:03:06.492 --> 00:03:10.366 - say we had a separate list that we wanted to create, let's say. 00:03:11.330 --> 00:03:14.876 - We wanted to do a list 00:03:14.876 --> 00:03:20.460 - request by. Brand, let's say we're doing, let's say we're 00:03:20.460 --> 00:03:24.420 - doing products and actually we would do this by. 00:03:24.770 --> 00:03:29.726 - Generic sizing this so typically the way end points work is self 00:03:29.726 --> 00:03:34.682 - is a little different. We can go over Steven separate videos, but 00:03:34.682 --> 00:03:38.812 - in most endpoints if you're doing a git request, you're 00:03:38.812 --> 00:03:44.181 - going to have some kind of filter, so the So what we would 00:03:44.181 --> 00:03:49.550 - do here probably is we would add on a public readonly string and 00:03:49.550 --> 00:03:51.615 - we would call this filter. 00:03:52.840 --> 00:03:58.365 - Uh, one way we would do that is we would. We would basically 00:03:58.365 --> 00:04:02.190 - create the filter we would give ourselves a secondary. 00:04:02.930 --> 00:04:09.113 - A constructor here and call this protected list request. 00:04:09.890 --> 00:04:12.480 - And this is going to be. We're going to take 00:04:12.480 --> 00:04:13.775 - in a string of filter. 00:04:15.720 --> 00:04:17.785 - And then the table that we need 00:04:17.785 --> 00:04:20.170 - to use. And then at table. 00:04:21.100 --> 00:04:25.444 - And then we're going to say filter equals filter, so at and 00:04:25.444 --> 00:04:29.788 - I'll show how to do utilize this here at the request level. 00:04:30.760 --> 00:04:35.870 - It's going to. It's going to involve creating a couple 00:04:35.870 --> 00:04:39.447 - separate helper helper functions, probably some enums. 00:04:39.460 --> 00:04:42.991 - Based off of like Oh data. Odata uses some different filters. 00:04:42.991 --> 00:04:46.522 - Odata uses like. Let's say you're trying to find the order 00:04:46.522 --> 00:04:50.053 - numb so they like order NUM, space, EQ, space, whatever your 00:04:50.053 --> 00:04:53.905 - value is. So let's say order number one. So you'd say order 00:04:53.905 --> 00:04:57.436 - NUM space EQ space one. So that's how you would filter 00:04:57.436 --> 00:05:01.930 - based off of that and you have to add some filters in there so 00:05:01.930 --> 00:05:05.461 - you would set this then at the request level but ultimately 00:05:05.461 --> 00:05:09.313 - your list requests would need to be generic so we couldn't say 00:05:09.313 --> 00:05:12.844 - brand equals whatever this brand gets passed in because this list 00:05:12.844 --> 00:05:14.449 - request doesn't just get you. 00:05:14.470 --> 00:05:18.220 - Used byproducts, this list across gets used by all requests 00:05:18.220 --> 00:05:23.095 - that are a list. Requests for training, so we would just do it 00:05:23.095 --> 00:05:27.970 - this way and then we would do any kind of manipulation at the 00:05:27.970 --> 00:05:29.095 - concrete request level. 00:05:29.960 --> 00:05:34.804 - So that's how we're going to use that for now. This is, and I 00:05:34.804 --> 00:05:38.610 - request this is part of mediator, so this is the. This 00:05:38.610 --> 00:05:43.108 - is how we say that the list request is part of the mediator, 00:05:43.108 --> 00:05:47.606 - so we need to look at that when we're dealing with how we're 00:05:47.606 --> 00:05:51.758 - handling these. So for example, we have our eye request of a 00:05:51.758 --> 00:05:55.564 - array of T model. So whatever, whatever class we're getting in 00:05:55.564 --> 00:05:59.370 - here, we're going to give back an array of T model. 00:06:00.530 --> 00:06:05.276 - OK, so let's go ahead and take a look at the list request handler 00:06:05.276 --> 00:06:10.361 - and we can see kind of how this is using or how this gets used. 00:06:10.361 --> 00:06:13.751 - So let's go to our training request handler. Start with 00:06:13.751 --> 00:06:17.141 - start raining request handler. All of our request handlers need 00:06:17.141 --> 00:06:20.531 - to use this integration service so the integration service that 00:06:20.531 --> 00:06:24.260 - were specifically using comes from. We need to inject our all 00:06:24.260 --> 00:06:28.328 - of our integration services and we can go see we've already set 00:06:28.328 --> 00:06:31.040 - one up in the setting up a new 00:06:31.040 --> 00:06:37.240 - connect. Video. With this so if we go look at our service 00:06:37.240 --> 00:06:40.471 - extensions and go look at our services extension, we've 00:06:40.471 --> 00:06:43.343 - already added our eye integration service of training 00:06:43.343 --> 00:06:47.292 - integration service. So if you had multiple of these, so let's 00:06:47.292 --> 00:06:49.087 - say you had a scoped. 00:06:49.870 --> 00:06:53.610 - I integration service and let's say you had a NetSuite 00:06:53.610 --> 00:06:57.350 - Integration Service. So you would put NetSuite in a gration. 00:07:00.280 --> 00:07:05.359 - Service So now we have two I integration services. We need to 00:07:05.359 --> 00:07:09.067 - specify which one we're going to use, so ignore the error for 00:07:09.067 --> 00:07:11.848 - right now in the training request handler, we are 00:07:11.848 --> 00:07:14.629 - specifically taking in the I enumerable because we have 00:07:14.629 --> 00:07:17.410 - multiple of them. Multiple of these I integration services. 00:07:18.310 --> 00:07:21.316 - Called integration services. So we're going to pull out 00:07:21.316 --> 00:07:24.322 - specifically the single one where it is the training 00:07:24.322 --> 00:07:26.660 - integration service. So even though we have. 00:07:27.550 --> 00:07:30.601 - Multiple in here we have a training integration services 00:07:30.601 --> 00:07:33.313 - with NetSuite integration service. Because we've said We 00:07:33.313 --> 00:07:38.059 - want the name of this one, it will give us that one. Then we 00:07:38.059 --> 00:07:41.788 - have access to that anywhere where we were in inheriting this 00:07:41.788 --> 00:07:42.805 - training request handler. 00:07:44.010 --> 00:07:47.230 - OK, so let's go look at our list request handler and first of all 00:07:47.230 --> 00:07:50.573 - let me go. Get rid of that 'cause we don't need that. 00:07:53.120 --> 00:07:55.688 - OK, so in our training Chris Taylor, now we're going to look 00:07:55.688 --> 00:07:56.758 - at our list request handler. 00:07:57.760 --> 00:08:00.793 - So our list request handler implements the I request 00:08:00.793 --> 00:08:04.163 - handler, so it's basically saying to mediator I am a 00:08:04.163 --> 00:08:07.533 - handler for requests. The list request handler takes in the 00:08:07.533 --> 00:08:11.577 - type of request that were pulling in, so you can see List 00:08:11.577 --> 00:08:14.947 - request of T model. So for example, if we're doing 00:08:14.947 --> 00:08:18.991 - products, we would need to pass into it from our from our 00:08:18.991 --> 00:08:23.372 - concrete, the T request. So if we had a list products, we would 00:08:23.372 --> 00:08:27.416 - say list product's request and then RT model is the class that 00:08:27.416 --> 00:08:31.123 - we're giving back even though we're giving it back an array. 00:08:31.190 --> 00:08:36.118 - We just care about the actual model that it is so far. In this 00:08:36.118 --> 00:08:39.990 - case it would be CPI training product. We don't care about, 00:08:39.990 --> 00:08:43.510 - uh, uh, knowledge that it's the implementation of this CPI 00:08:43.510 --> 00:08:47.382 - training product here because at this level all we really know 00:08:47.382 --> 00:08:50.902 - about is product. But because it's because it's generic when 00:08:50.902 --> 00:08:54.774 - we create our actual request and request handler will use this 00:08:54.774 --> 00:08:59.350 - instantiation of the the product to give to it and it knows how 00:08:59.350 --> 00:09:00.758 - to handle it here. 00:09:01.650 --> 00:09:05.000 - So we're going to inherit from our training request handler, 00:09:05.000 --> 00:09:07.680 - which is why we're giving getting our integration 00:09:07.680 --> 00:09:11.365 - services. So we have been passed the I enumerable of AI 00:09:11.365 --> 00:09:14.045 - integration service that we're calling integration services and 00:09:14.045 --> 00:09:17.395 - handing it off to the training request handler, which then 00:09:17.395 --> 00:09:19.610 - again. Oops. 00:09:21.630 --> 00:09:25.451 - I press. Delete instead their training request handler, which 00:09:25.451 --> 00:09:29.447 - sets the integration service so you can see down here we were 00:09:29.447 --> 00:09:32.111 - using that integration service from the training request 00:09:32.111 --> 00:09:35.221 - handler. Also, it is implementing the I request 00:09:35.221 --> 00:09:38.737 - handler so the I request handler basically says that I have to 00:09:38.737 --> 00:09:42.839 - have some kind of handle method on it. So my task of TI response 00:09:42.839 --> 00:09:45.769 - mighty request and then my cancellation token here. So I 00:09:45.769 --> 00:09:49.871 - have to have I have to have some sort of requests that it takes 00:09:49.871 --> 00:09:53.094 - in, so that's where Artie request is coming in. From here 00:09:53.094 --> 00:09:56.610 - are list request of T model because we want list requests in 00:09:56.610 --> 00:10:00.126 - list request to match. So we have the request and the request 00:10:00.126 --> 00:10:03.056 - handler matching of whatever their requests that we got here 00:10:03.056 --> 00:10:04.814 - was and then we have it 00:10:04.814 --> 00:10:07.810 - returning. Our array of T model. So if we go back 00:10:07.810 --> 00:10:08.858 - to our request handler. 00:10:09.900 --> 00:10:14.255 - You can see that it's going to take. It's going to return the 00:10:14.255 --> 00:10:18.275 - response, so the response in this case is the 2nd type input, 00:10:18.275 --> 00:10:22.630 - so the second type input is going to be the array of T 00:10:22.630 --> 00:10:26.650 - model. If we just looked at our read request handler, a read 00:10:26.650 --> 00:10:29.665 - request handler only returns just a individual instance of 00:10:29.665 --> 00:10:34.020 - the T model product in our case. But in any other case, sales 00:10:34.020 --> 00:10:36.700 - orders, accounts, customers, Contacts, whatever it is. So 00:10:36.700 --> 00:10:41.055 - that is how is how we're telling it what were returning. So we 00:10:41.055 --> 00:10:43.065 - have our request and then it's 00:10:43.065 --> 00:10:48.060 - returning. OK. Now we had to implement this handle 00:10:48.060 --> 00:10:51.690 - method so they handle method is how we are calling our 00:10:51.690 --> 00:10:52.680 - integration service so. 00:10:53.780 --> 00:10:57.901 - We are going to look at our our handle so it calls the 00:10:57.901 --> 00:11:01.071 - integration service. In this case it remember is our. If 00:11:01.071 --> 00:11:02.339 - we go look here. 00:11:03.630 --> 00:11:07.470 - Our training integration service so it's actually using. 00:11:09.000 --> 00:11:10.716 - Our let's see where to go. 00:11:13.450 --> 00:11:14.480 - Not that one this one. 00:11:15.100 --> 00:11:18.308 - Our training integration service, and again, we're not 00:11:18.308 --> 00:11:21.516 - implementing this, but because training the integration service 00:11:21.516 --> 00:11:25.927 - is implementing I integration service, we know that we have to 00:11:25.927 --> 00:11:29.928 - have a. List request to create request a read 00:11:29.928 --> 00:11:32.406 - request. An update requests Anna delete request. 00:11:33.430 --> 00:11:37.266 - So we're specifically calling integration service list. 00:11:37.850 --> 00:11:42.686 - With the model that we know we're using, so in this case 00:11:42.686 --> 00:11:47.161 - product. And then our request, so whatever our request value 00:11:47.161 --> 00:11:52.047 - is. So in this case it's going to be a list request or it's 00:11:52.047 --> 00:11:56.584 - going to be at a higher level. That's going to be the list 00:11:56.584 --> 00:11:58.329 - product's request which is going 00:11:58.329 --> 00:12:02.580 - to. Inherit from the list request, but at the base level 00:12:02.580 --> 00:12:06.909 - it has to be a list request. We're going to pass in the 00:12:06.909 --> 00:12:10.572 - request that we're getting from our request. So for example, if 00:12:10.572 --> 00:12:14.901 - it has all the values that we needed. So for example, we had. 00:12:16.350 --> 00:12:20.094 - Our table we might have our schema. We have our compare date 00:12:20.094 --> 00:12:23.838 - possibly. We have our filter. All of those things are going to 00:12:23.838 --> 00:12:25.398 - be used in the training 00:12:25.398 --> 00:12:29.171 - integration service. And we'll show how to do that 00:12:29.171 --> 00:12:31.289 - once we implement this training integration 00:12:31.289 --> 00:12:33.760 - service. How we know specifically what request 00:12:33.760 --> 00:12:34.819 - it's using so. 00:12:35.900 --> 00:12:40.531 - Let's look at so this handler method basically just passes on 00:12:40.531 --> 00:12:43.057 - and says, OK, we're going to 00:12:43.057 --> 00:12:46.546 - return. The integration service dot list method with these 00:12:46.546 --> 00:12:49.984 - generic values that we're getting from the concrete and 00:12:49.984 --> 00:12:53.804 - then these actual parameters that were passing in. So that's 00:12:53.804 --> 00:12:57.624 - how mediator takes the request, sees what mediators sends, and 00:12:57.624 --> 00:13:01.826 - then handles it appropriately based off of the what the value 00:13:01.826 --> 00:13:05.646 - or what class is being requested. It knows what handler 00:13:05.646 --> 00:13:06.792 - to go use. 00:13:07.390 --> 00:13:10.679 - OK, so now we can go take a look at our concrete examples. 00:13:11.780 --> 00:13:17.539 - Go ahead and close all these, so let's go look at our request 00:13:17.539 --> 00:13:20.197 - first. So we want to implement 00:13:20.197 --> 00:13:24.250 - a. A list products, so we're going to. We're going to call 00:13:24.250 --> 00:13:27.490 - this. We're going to go ahead and create a new request here. 00:13:29.210 --> 00:13:30.449 - We're going to build a new item. 00:13:31.040 --> 00:13:33.408 - And we're going to. 00:13:34.340 --> 00:13:38.198 - Create a new class called list. 00:13:38.870 --> 00:13:41.500 - Training products. 00:13:45.350 --> 00:13:46.010 - Request 00:13:47.150 --> 00:13:52.410 - OK, the naming convention here is the action, the ERP. 00:13:53.350 --> 00:13:55.410 - The. 00:13:58.410 --> 00:14:01.248 - The entity and then the word request in between product, the 00:14:01.248 --> 00:14:04.086 - entity and their word request. You could have an extra filter. 00:14:04.086 --> 00:14:07.182 - So for example, if you're just listing all of them, or if 00:14:07.182 --> 00:14:08.214 - you're just listing by. 00:14:08.860 --> 00:14:12.314 - Compare date then you probably wouldn't want to add any extra 00:14:12.314 --> 00:14:15.768 - filter here. But let's say we're filtering based off of, let's 00:14:15.768 --> 00:14:19.222 - say products were filtering off of the brand, so let's say 00:14:19.222 --> 00:14:22.990 - mobile phones are the products that we have. Our brand could be 00:14:22.990 --> 00:14:27.386 - Samsung, so let's say or Apple or LG or whatever it is, but we 00:14:27.386 --> 00:14:30.840 - want we want to create a separate request that might be 00:14:30.840 --> 00:14:32.410 - list training products by brand 00:14:32.410 --> 00:14:36.284 - request. That way, that way you can. You can differentiate 00:14:36.284 --> 00:14:39.980 - between the different requests that you have, but we still use 00:14:39.980 --> 00:14:43.340 - that same naming convention. So when we're typing, our requests 00:14:43.340 --> 00:14:47.372 - were saying list. OK, now I have access to my training ERP 00:14:47.372 --> 00:14:50.732 - products. Oh, I have two different requests. I have lists 00:14:50.732 --> 00:14:54.092 - training products request and I have a list training products 00:14:54.092 --> 00:14:56.780 - products by brand requester. However, many different requests 00:14:56.780 --> 00:15:00.772 - you have. So ultimately, we're listing training products 00:15:00.772 --> 00:15:05.868 - requests, so we'll add that. OK, so we're going to take this down 00:15:05.868 --> 00:15:10.572 - to the requests level. We don't want to add that extra extra 00:15:10.572 --> 00:15:14.884 - little piece there, so we're going to make this a public 00:15:14.884 --> 00:15:18.804 - class of oops list training products. Request. This is going 00:15:18.804 --> 00:15:22.480 - to. Inherit from our list request. 00:15:23.960 --> 00:15:27.032 - OK, you're going to have to add a using statement for your 00:15:27.032 --> 00:15:27.800 - clarity training requests. 00:15:29.860 --> 00:15:34.816 - And then it's going to be of type. We want to return 00:15:34.816 --> 00:15:38.946 - the type and use the type of CPI training product. 00:15:40.230 --> 00:15:43.750 - You're going to have to add another using statements out of 00:15:43.750 --> 00:15:46.950 - the reference to our clarity connect entities. Now this is 00:15:46.950 --> 00:15:50.470 - where we were talking about before in the products that we 00:15:50.470 --> 00:15:53.030 - can't instantiate this product, we can't instantiate the. 00:15:53.630 --> 00:15:58.340 - Connector product of the connector entity. We have to use 00:15:58.340 --> 00:16:02.036 - the. Instantiation of it, which is the CPI training 00:16:02.036 --> 00:16:05.468 - product because if we used product and we needed to use 00:16:05.468 --> 00:16:08.588 - these skews, this internal skew in the sale price, we 00:16:08.588 --> 00:16:12.644 - couldn't do it. So we have to use in this case the concrete 00:16:12.644 --> 00:16:12.956 - version. 00:16:14.070 --> 00:16:18.138 - OK, so you're going to get a issue here that says that. 00:16:19.660 --> 00:16:23.820 - It does not contain structure. Take zero arguments because that 00:16:23.820 --> 00:16:25.068 - list requests requires. 00:16:25.770 --> 00:16:30.670 - At the very least, that compare Dayton a table or a filter in a 00:16:30.670 --> 00:16:34.520 - table, so we're going to do a public list training products 00:16:34.520 --> 00:16:38.020 - request called. We're going to compare date, 'cause That's the 00:16:38.020 --> 00:16:41.870 - base. Once we're going to compare date and then a string 00:16:41.870 --> 00:16:42.920 - of our table. 00:16:44.240 --> 00:16:46.130 - And then we're going to give 00:16:46.130 --> 00:16:48.760 - that compare dates. And that 00:16:48.760 --> 00:16:51.170 - table. To our list request. 00:16:54.680 --> 00:16:57.804 - So now we have a satisfied, satisfied request. We are not 00:16:57.804 --> 00:17:00.076 - taking anything extra. We're not doing anything with 00:17:00.076 --> 00:17:02.632 - compare date and we're not doing anything with table, 00:17:02.632 --> 00:17:06.040 - we're just taking these in and passing them on to the list 00:17:06.040 --> 00:17:08.596 - request. Because this list request is abstract, I can't 00:17:08.596 --> 00:17:12.004 - create just a generic list request. I have to do it via 00:17:12.004 --> 00:17:12.572 - this method. 00:17:13.690 --> 00:17:18.324 - OK, so now we can go create our request handler. So in our CPI 00:17:18.324 --> 00:17:21.303 - training request handlers, we're going to add an item. 00:17:22.150 --> 00:17:27.676 - Again, we're going to call this list training products 00:17:27.676 --> 00:17:28.904 - request handler. 00:17:32.050 --> 00:17:35.018 - OK. Alright, so in our in our 00:17:35.018 --> 00:17:38.620 - request handler. The first thing we're going to do is we're going 00:17:38.620 --> 00:17:39.970 - to shorten the namespace down to 00:17:39.970 --> 00:17:44.094 - request handlers. This is going to be a public class. 00:17:45.350 --> 00:17:49.190 - And it's going to inherit from our list request handler. 00:17:50.290 --> 00:17:52.842 - Again, we're going to have to add our reference to our 00:17:52.842 --> 00:17:53.770 - clarity training request handler. 00:17:54.880 --> 00:17:58.565 - And just like so the list request handler takes in two 00:17:58.565 --> 00:18:02.585 - types, so we need that type to be the request that we're 00:18:02.585 --> 00:18:06.605 - making. And again, it's not just a list request that were making 00:18:06.605 --> 00:18:09.285 - were specifically making for this handler were specifically 00:18:09.285 --> 00:18:12.970 - making a list. Training products request will have to add a 00:18:12.970 --> 00:18:16.655 - reference to our clarity connect dot requests, and then I think 00:18:16.655 --> 00:18:18.665 - we actually have to add A. 00:18:19.300 --> 00:18:22.150 - Reference to Nope were good so. 00:18:23.250 --> 00:18:28.410 - The second type that it takes in is going to be the model, so if 00:18:28.410 --> 00:18:32.194 - we go back to our request handler, remember the first is 00:18:32.194 --> 00:18:36.666 - the request, the second is the model, so this is going to be 00:18:36.666 --> 00:18:40.794 - remember a CPI training product, so we're going to grab our CPI 00:18:40.794 --> 00:18:42.654 - training product. And put it 00:18:42.654 --> 00:18:46.237 - right there. We're going to have to add our reference to 00:18:46.237 --> 00:18:47.369 - our clarity connect entities. 00:18:48.530 --> 00:18:50.616 - And now we're going to go so. 00:18:51.260 --> 00:18:55.275 - Again, we have a squiggle because we don't have a blank 00:18:55.275 --> 00:19:00.020 - list request handler, we have to give it the I enumerable of the 00:19:00.020 --> 00:19:03.305 - integration services, so we're going to create a constructor 00:19:03.305 --> 00:19:05.860 - here called list training products request handler. 00:19:07.350 --> 00:19:10.986 - This is going to take in the I enumerable of the eye 00:19:10.986 --> 00:19:14.622 - integration service so that at the base level it can grab the 00:19:14.622 --> 00:19:18.561 - correct one and allow us to use it in the handle method. So 00:19:18.561 --> 00:19:22.197 - we're going to use and I were going to inject an ienumerable. 00:19:23.330 --> 00:19:25.740 - Of type I integration service. 00:19:28.800 --> 00:19:30.856 - At our reference to our clarity dot shared. 00:19:32.170 --> 00:19:34.658 - And we're going to call this integration services. 00:19:36.360 --> 00:19:40.683 - This is going to be a base or we're going to 00:19:40.683 --> 00:19:43.827 - pass on the integration services to our base. 00:19:46.290 --> 00:19:49.290 - And that's it. Were done with this request handler. The 00:19:49.290 --> 00:19:51.990 - request handlers are fairly simple. They literally are going 00:19:51.990 --> 00:19:55.890 - to tell it. You're going to tell it exactly what kind of request 00:19:55.890 --> 00:19:59.790 - handler it is. Let's give it the request. Give it the type, and 00:19:59.790 --> 00:20:02.490 - then we're always going to create this same constructor 00:20:02.490 --> 00:20:05.190 - with I enumerable, I integration service integration services and 00:20:05.190 --> 00:20:09.090 - pass those on to the handler to the base handler, so that's it 00:20:09.090 --> 00:20:11.790 - in terms of creating the requests in the handler. 00:20:12.620 --> 00:20:15.240 - Now in our training service. 00:20:16.040 --> 00:20:18.584 - Our concrete training service. Here we're going to 00:20:18.584 --> 00:20:21.764 - start with our interface and we're going to give we're 00:20:21.764 --> 00:20:25.262 - going to call a method that basically calls all of this. 00:20:25.262 --> 00:20:26.852 - So in our training service. 00:20:28.230 --> 00:20:32.481 - We first the first thing that we need to do is our training 00:20:32.481 --> 00:20:35.751 - service needs to know about mediator, so we're going to 00:20:35.751 --> 00:20:37.059 - create a I mediator. 00:20:37.810 --> 00:20:40.985 - Um property here, so using 00:20:40.985 --> 00:20:45.122 - mediator. Is it going to be mediator and then we're going to 00:20:45.122 --> 00:20:46.210 - do our guitar etc. 00:20:48.230 --> 00:20:53.108 - OK. So now that we know about mediator, we can give ourselves 00:20:53.108 --> 00:20:56.496 - our our signatures. So the first thing that we're going to 00:20:56.496 --> 00:21:00.192 - do here is we're going to do a list training products so. 00:21:01.230 --> 00:21:04.035 - We're going to have a return of task because this is 00:21:04.035 --> 00:21:05.310 - going to be a sink. 00:21:06.650 --> 00:21:11.096 - Remember, we are for a request that we're going to do a CPI 00:21:11.096 --> 00:21:14.213 - training product. Is what is going to be returned and it's 00:21:14.213 --> 00:21:15.395 - going to be an array of. 00:21:15.930 --> 00:21:18.500 - Will add X are entities. 00:21:19.860 --> 00:21:21.554 - And we're going to name this the 00:21:21.554 --> 00:21:23.630 - action. The ERP. 00:21:24.800 --> 00:21:25.589 - And the entity. 00:21:28.800 --> 00:21:33.560 - And this one remember we took in we needed to take in a compare 00:21:33.560 --> 00:21:35.260 - date, so let's look at. 00:21:38.510 --> 00:21:41.278 - Let's look at sorry. 00:21:42.630 --> 00:21:44.300 - Our. 00:21:46.400 --> 00:21:47.180 - Request 00:21:48.370 --> 00:21:49.595 - OK, it looks in a compare data. 00:21:49.595 --> 00:21:55.430 - It takes in a table. So we're going to take in a date time of 00:21:55.430 --> 00:21:56.684 - a compare dates. 00:21:57.460 --> 00:22:02.634 - And we're going to do a string. Now we know. Sorry table. We 00:22:02.634 --> 00:22:06.216 - know that we're going to use products here, however, 00:22:06.216 --> 00:22:10.594 - potentially later on we want to use the same request. Very 00:22:10.594 --> 00:22:15.370 - doubtful of We're going to use the same request to call a 00:22:15.370 --> 00:22:20.054 - different table. So we're going to pass in string table. 00:22:20.710 --> 00:22:24.340 - And then we're going to set a default value of products. 00:22:27.740 --> 00:22:35.106 - OK. So we are going to now take a look at how we 00:22:35.106 --> 00:22:37.218 - can implement this so. 00:22:37.220 --> 00:22:40.804 - The other thing that we need to add, and I apologize that I did 00:22:40.804 --> 00:22:43.876 - not get this in the creation of the parameters is mediator the 00:22:43.876 --> 00:22:46.692 - handler itself. Let's go take a look at the request handler. 00:22:48.600 --> 00:22:53.478 - Takes in a cancellation token, so we have to. 00:22:54.200 --> 00:22:57.182 - Give ourselves this cancellation token in our 00:22:57.182 --> 00:23:01.442 - request handler. So let's take a look at our request 00:23:01.442 --> 00:23:01.868 - handler. 00:23:05.770 --> 00:23:10.120 - So we want to give this a cancellation token loops. 00:23:16.430 --> 00:23:20.070 - And we have to put it before this because anytime you have a 00:23:20.070 --> 00:23:23.710 - nullable type or a default type, it has to be last. So we're 00:23:23.710 --> 00:23:26.790 - going to go ahead and put the cancellation token here. Then 00:23:26.790 --> 00:23:30.150 - our default of table equals products so we don't have to. We 00:23:30.150 --> 00:23:33.230 - don't have to add this table equal products and less were 00:23:33.230 --> 00:23:36.030 - over writing that which I doubt we will do so. 00:23:36.840 --> 00:23:41.100 - Let's go and save this and let's go to our training service. 00:23:41.140 --> 00:23:46.072 - So we should get a error here that we are not implementing 00:23:46.072 --> 00:23:49.360 - the mediator or norwex implementing the list training 00:23:49.360 --> 00:23:53.470 - products. So first thing we're going to do excuse me. 00:23:54.700 --> 00:23:57.570 - Is we're going to go ahead and implement the eye 00:23:57.570 --> 00:24:00.440 - mediator, so we're going to have a public I mediator. 00:24:02.260 --> 00:24:06.190 - Going to using mediator, we're going to call this mediator. 00:24:07.200 --> 00:24:08.845 - And this is a gitter Anna Sutter. 00:24:10.260 --> 00:24:13.816 - So we need to go ahead and give us give ourselves that in the 00:24:13.816 --> 00:24:16.610 - constructor. So when we injected this training service an when we 00:24:16.610 --> 00:24:18.642 - set up a new set up our new 00:24:18.642 --> 00:24:22.400 - connect. Because we set up that service, we can inject whatever 00:24:22.400 --> 00:24:25.760 - we need to when we create the new instance of this service. 00:24:27.260 --> 00:24:32.005 - So we need to go public. We're going to take in this public 00:24:32.005 --> 00:24:36.020 - training service and we're going to inject in the eye. Mediator 00:24:36.020 --> 00:24:37.115 - called this mediator. 00:24:38.020 --> 00:24:39.196 - And then we can set it. 00:24:44.470 --> 00:24:47.806 - OK, so now we have access to mediator, for which we can 00:24:47.806 --> 00:24:51.142 - call our send call, which the mediator send him is. What is 00:24:51.142 --> 00:24:54.200 - what makes the call. Then based off the request it goes 00:24:54.200 --> 00:24:56.980 - and calls the request handler. So let's will walk through 00:24:56.980 --> 00:25:00.316 - that as we create it. So the second value that we haven't 00:25:00.316 --> 00:25:02.540 - implemented is the list training product. So these 00:25:02.540 --> 00:25:05.320 - things to do here is we're going to implement the 00:25:05.320 --> 00:25:05.598 - interface. 00:25:06.820 --> 00:25:09.273 - OK, first thing we want to do we implement these. We 00:25:09.273 --> 00:25:10.388 - want to make these async. 00:25:12.170 --> 00:25:17.617 - OK, now we have our throw new not implementable. We want to go 00:25:17.617 --> 00:25:19.712 - ahead and implement this so. 00:25:19.770 --> 00:25:23.943 - In here you would do any kind of configuration that you need to 00:25:23.943 --> 00:25:27.474 - to create the filter to create the any other values. Basically 00:25:27.474 --> 00:25:29.400 - whatever you want, we need to 00:25:29.400 --> 00:25:33.242 - create here so. We're not going to do anything with the 00:25:33.242 --> 00:25:35.618 - compare date, will create another one for the filter 00:25:35.618 --> 00:25:39.050 - here in a bit, but for now we're just going to do the 00:25:39.050 --> 00:25:41.690 - compared to this one is pretty simple. We're just returning 00:25:41.690 --> 00:25:42.746 - await mediator dot send. 00:25:45.130 --> 00:25:50.380 - And we're going to give it. The first is as you can see there an 00:25:50.380 --> 00:25:54.580 - object request, so our requests is going to be a new list. 00:25:54.580 --> 00:25:57.380 - Training products requests because that's the request for 00:25:57.380 --> 00:26:00.880 - using. Going to add a using statement for our requests. 00:26:01.690 --> 00:26:04.114 - It's going to take in a compare date. 00:26:06.150 --> 00:26:11.220 - And it's going to have to take in the table so the table. 00:26:11.860 --> 00:26:13.788 - In this case we're presetting to product, so 00:26:13.788 --> 00:26:15.234 - we need to pass that in. 00:26:18.940 --> 00:26:21.492 - OK, this second parameter that the mediator send 00:26:21.492 --> 00:26:24.044 - request uses the cancellation token. It defaults to 00:26:24.044 --> 00:26:27.234 - default. However, if we cancel the job, we want that 00:26:27.234 --> 00:26:30.424 - cancellation token to be passed down to here so that 00:26:30.424 --> 00:26:33.933 - it cancels before it goes and makes a request. So we're 00:26:33.933 --> 00:26:35.528 - going to pass in token. 00:26:36.640 --> 00:26:39.890 - And the last thing we're going to do here because it's an async 00:26:39.890 --> 00:26:42.640 - method, we're going to throw our configure way false on there, 00:26:42.640 --> 00:26:44.140 - and we're done. So now we're 00:26:44.140 --> 00:26:48.820 - returning the handled. Return value of this list. Training 00:26:48.820 --> 00:26:50.350 - products request so. 00:26:51.350 --> 00:26:54.608 - The complexity here is allows for more organization because 00:26:54.608 --> 00:26:58.590 - this potentially we could have another 10 lines here that sets 00:26:58.590 --> 00:27:02.210 - up the list training product request. Obviously in this one 00:27:02.210 --> 00:27:06.554 - it doesn't, but we wanted we want to organize these so that 00:27:06.554 --> 00:27:10.898 - we have them wherever we need them. The actions are going to 00:27:10.898 --> 00:27:12.708 - separate them out into our. 00:27:14.290 --> 00:27:17.722 - Into our action. So we have our list or create our read 00:27:17.722 --> 00:27:20.582 - our updates then we have our training. This was always 00:27:20.582 --> 00:27:23.442 - going to say training because it's the training service. But 00:27:23.442 --> 00:27:27.446 - then we have our entity on top of that. So in fact we could 00:27:27.446 --> 00:27:30.306 - probably even cut the training out. That's something that we 00:27:30.306 --> 00:27:33.738 - can talk about, but for now we're going to leave it in 00:27:33.738 --> 00:27:36.884 - just because just for naming convention, we want To Do List 00:27:36.884 --> 00:27:38.600 - training services or list training products. 00:27:39.680 --> 00:27:43.123 - The reason that we could possibly cut it out and let's 00:27:43.123 --> 00:27:46.879 - hold off on doing that until it becomes part of documentation is 00:27:46.879 --> 00:27:50.009 - that in our job service, I'm sorry in our controller. 00:27:50.009 --> 00:27:52.513 - Apologies, we could technically call. We've already given 00:27:52.513 --> 00:27:53.765 - ourselves the training service. 00:27:54.620 --> 00:27:58.806 - We could just call list products and then we know based off of 00:27:58.806 --> 00:28:02.670 - the fact that it's the training service that we don't have to 00:28:02.670 --> 00:28:03.958 - redundancy put least list 00:28:03.958 --> 00:28:07.108 - training products. But for now, we're going to leave it as 00:28:07.108 --> 00:28:08.662 - training products, because that's the naming convention 00:28:08.662 --> 00:28:11.104 - that we've come up with that could change down the line. 00:28:12.780 --> 00:28:17.050 - OK, so now we have access to this, so let's go ahead and go 00:28:17.050 --> 00:28:20.405 - back to our product controller and call this thing. So instead 00:28:20.405 --> 00:28:24.065 - of doing our context right line OK, we're going to set our 00:28:24.065 --> 00:28:27.115 - product's going to get products and we're going to await. 00:28:28.580 --> 00:28:31.066 - That method that we just created again, we just showed that 00:28:31.066 --> 00:28:32.422 - that's going to be on the 00:28:32.422 --> 00:28:36.099 - training service. That got injected in the job service 00:28:36.099 --> 00:28:39.582 - constructor, so this training service that got injected we 00:28:39.582 --> 00:28:41.517 - have use of it here. 00:28:42.590 --> 00:28:45.278 - So we can use that. We're going to call list training products. 00:28:45.278 --> 00:28:47.966 - This is going to take into compare date. So the first thing 00:28:47.966 --> 00:28:51.774 - that we need to do is we need to go show how we're going to do a 00:28:51.774 --> 00:28:55.268 - compare date. So our compare date. 00:28:56.370 --> 00:29:03.654 - Is going to come from calling a method from our hang fire 00:29:03.654 --> 00:29:07.296 - job service, so we're going to 00:29:07.296 --> 00:29:10.110 - do a. Bar compare date. 00:29:10.710 --> 00:29:16.094 - Equals. Gets compared 8 Yep, the context is going to be a context 00:29:16.094 --> 00:29:20.150 - that we're passing in and then the method name is going to be 00:29:20.150 --> 00:29:24.206 - the name of the job that were calling. So in this case it's 00:29:24.206 --> 00:29:25.454 - going to be processed. 00:29:26.730 --> 00:29:27.510 - Products. 00:29:30.110 --> 00:29:33.134 - So now we have our compared to what this does is it goes and 00:29:33.134 --> 00:29:34.430 - looks at the hang fire table. 00:29:35.410 --> 00:29:39.505 - For job and says OK, give me the last time that process products 00:29:39.505 --> 00:29:42.655 - ran successfully. So let's say we're running this every 30 00:29:42.655 --> 00:29:46.750 - minutes and a job runs at noon and his successful, let's say it 00:29:46.750 --> 00:29:50.530 - takes, doesn't matter how long it takes to run. Let's say it 00:29:50.530 --> 00:29:54.310 - takes 10 minutes to run at 12:30. When it runs, the get 00:29:54.310 --> 00:29:57.775 - compare date says when was the last time the job ran 00:29:57.775 --> 00:30:01.555 - successfully, so it ran it at noon at 12:00 o'clock. So the 00:30:01.555 --> 00:30:03.445 - compare date is then going to 00:30:03.445 --> 00:30:08.414 - say OK. This product is going to say give me all of the products 00:30:08.414 --> 00:30:11.434 - that have been created or updated since 12:00 o'clock, so 00:30:11.434 --> 00:30:12.944 - that's where that get compared. 00:30:12.944 --> 00:30:17.106 - It comes from. We can go into that more in detail, potentially 00:30:17.106 --> 00:30:20.230 - later. You can always ask someone if we need more examples 00:30:20.230 --> 00:30:22.786 - and we can create more documentation for that if 00:30:22.786 --> 00:30:25.910 - necessary. However, we're going to go ahead for the purposes of 00:30:25.910 --> 00:30:27.614 - this video and pass that compare 00:30:27.614 --> 00:30:31.828 - date in here. Right, the second value it takes is the 00:30:31.828 --> 00:30:34.938 - cancellation tokens, so that's just going to come from the 00:30:34.938 --> 00:30:37.530 - constructor of the. Of the 00:30:37.530 --> 00:30:40.770 - method. And then if we wanted to, we could override that 00:30:40.770 --> 00:30:43.010 - product or that table. It's already set the products and 00:30:43.010 --> 00:30:45.250 - we're fine with that because that's what we created this 00:30:45.250 --> 00:30:46.594 - request for. So we're going to 00:30:46.594 --> 00:30:48.610 - configure await. False. 00:30:51.380 --> 00:30:53.412 - OK, so if we ran this we should 00:30:53.412 --> 00:30:57.192 - get products back. So let's go ahead and run this super getting 00:30:57.192 --> 00:30:58.382 - errors we might. Who knows. 00:31:09.090 --> 00:31:12.445 - Alright, so we have our dashboard here so this is what 00:31:12.445 --> 00:31:15.800 - our dashboard looks like. We're going to go to our recurring 00:31:15.800 --> 00:31:19.155 - jobs. If you see some other methods here. Process product so 00:31:19.155 --> 00:31:23.120 - ring job can be scheduled. Could not load the job. Why cannot be 00:31:23.120 --> 00:31:26.170 - loaded job with his suggests a method with signature process 00:31:26.170 --> 00:31:29.830 - product. So that's an old one. I apologize, we've had that one. 00:31:29.830 --> 00:31:33.490 - Remember we called our ID products before we can go take a 00:31:33.490 --> 00:31:34.710 - look at that here. 00:31:35.880 --> 00:31:39.756 - So if we go back to our job service, we called this 00:31:39.756 --> 00:31:43.309 - recurring job ID products. So the what's left over here is 00:31:43.309 --> 00:31:47.185 - remnants from old jobs, so we're going to run products and the 00:31:47.185 --> 00:31:51.707 - first thing I need to do if you'll give me just a second as 00:31:51.707 --> 00:31:56.552 - I need to go turn on the Web API so that we can actually get 00:31:56.552 --> 00:31:57.844 - things back instead of. 00:31:58.470 --> 00:32:00.420 - Just throwing an error that. 00:32:00.920 --> 00:32:03.320 - It couldn't handle it. 00:32:03.380 --> 00:32:05.900 - So let me run this really 00:32:05.900 --> 00:32:09.168 - quickly. And then we can get going. 00:32:13.780 --> 00:32:18.148 - So what I'm starting here is I'm starting this job and you can 00:32:18.148 --> 00:32:22.180 - see the API controller, so this would be slash API slash product 00:32:22.180 --> 00:32:26.548 - so you know what this is not going to work because we have 00:32:26.548 --> 00:32:27.892 - not integrated with our. 00:32:28.970 --> 00:32:29.700 - Um? 00:32:31.340 --> 00:32:33.710 - We have not set up our integration service, so we're 00:32:33.710 --> 00:32:36.791 - going to hold off on that for the moment. Right now it's just 00:32:36.791 --> 00:32:41.755 - throwing. But for now, we can see that we have our list 00:32:41.755 --> 00:32:45.205 - training products and we've seen our dashboard so right now 00:32:45.205 --> 00:32:48.655 - that's it will implement other business logic then will also 00:32:48.655 --> 00:32:51.760 - implement the integration service in a separate video, but 00:32:51.760 --> 00:32:54.865 - that's how you would make a request for our. 00:32:55.610 --> 00:32:56.640 - Integration list.