0:00 All right, so let's continue finishing our Mongo 0:03 product repository 0:05 by implementing the rest of our methods that we know our port 0:09 expects. So let's start off next with the async 0:12 findById method, which automatically gets 0:16 filled out thanks to the interface. 0:18 And so for findById, we'll just look for the document using 0:22 this._collection.findOne 0:26 method, 0:27 which allows us to pass in a filter query where we can look 0:31 for the document by any property that exists on 0:35 it. In this case, we'll use the ID, which is automatically 0:38 optimized for fast lookups, and simply pass in the 0:42 product ID value object, which we turn into a string. 0:46 Then check to see if we don't have the doc, 0:49 then we return null, which we know our application layer will 0:53 handle 0:53 globally. And now at this point, we have the document, but we need 0:57 to turn it into the domain product 1:01 entity. Just like we've done for toPersistence, 1:04 we also want 1:05 that toDomain method. So let's go ahead and 1:09 add this next, our new private static 1:12 toDomain method that takes in the product 1:16 document that I'll call productDoc, and returns back the 1:19 product entity. 1:21 And so for this, we know, just as we did in the Drizzle product 1:24 repository, 1:26 we can use the Product.reconstitute method. 1:30 That will take in the product properties and turn it into 1:34 the entity. So for example, the ID, we're gonna 1:37 pass new Product ID and set our 1:41 document.id as this. 1:44 And I'll continue on for the rest of the properties that exist on our 1:47 product. All right, so now I've filled out the rest of the 1:50 properties that we know 1:51 the product reconstitute expects. 1:54 So this includes the SKU that we're using, the 1:56 skuValueObj.create, and 1:59 Money.createValueObject, where we pass in our raw cents value 2:04 and divide it by a hundred, as well as pass in the currency,
The rest of the transcript is for members.
Sign in