File tree Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change 1+ from injector import inject
2+
13from .entities import Comic
24from .vo import ComicStatus
35
46
5- class ObtainAmountToPayService :
7+ class DiscountService :
68 def __call__ (self , comic : Comic ):
79 DISCOUNTS = {
810 ComicStatus .EXCELLENT : ExcellentComicDiscount .for_this (comic = comic ).apply (),
@@ -11,9 +13,17 @@ def __call__(self, comic: Comic):
1113 ComicStatus .IMPAIRED : ImpairedComicDiscount .for_this (comic = comic ).apply (),
1214 ComicStatus .DAMAGED : DamagedComicDiscount .for_this (comic = comic ).apply ()
1315 }
14-
1516 discount = DISCOUNTS .get (comic .status )
16- return comic .price - discount
17+ return discount
18+
19+
20+ class ObtainAmountToPayService :
21+ @inject
22+ def __init__ (self , discount_service : DiscountService ):
23+ self .discount_service = discount_service
24+
25+ def __call__ (self , comic : Comic ):
26+ return comic .price - self .discount_service (comic )
1727
1828
1929class Discount :
Original file line number Diff line number Diff line change 11from injector import Module , singleton
22
3- from apps .comics .domain .services import ObtainAmountToPayService
3+ from apps .comics .domain .services import ObtainAmountToPayService , DiscountService
44from apps .comics .domain .repositories import ComicRepository , RentalRepository
55from apps .comics .application .finders import ComicAllFinder , LastRentalFinder , AllRentalFinder
66from apps .comics .application .services import RentComicService
@@ -14,6 +14,7 @@ def configure(self, binder):
1414 binder .bind (AllRentalFinder , to = AllRentalFinder )
1515 binder .bind (ComicAllFinder , scope = singleton )
1616 binder .bind (ComicRepository , to = ComicDjangoRepository )
17+ binder .bind (DiscountService , to = DiscountService )
1718 binder .bind (LastRentalFinder , to = LastRentalFinder )
1819 binder .bind (ObtainAmountToPayService , to = ObtainAmountToPayService )
1920 binder .bind (RentComicService , to = RentComicService )
Original file line number Diff line number Diff line change 11from unittest import TestCase
22
3- from apps .comics .domain .services import ObtainAmountToPayService
3+ from apps .comics .domain .services import ObtainAmountToPayService , DiscountService
44from apps .comics .domain .vo import ComicStatus
55
66
1010class ObtainAmountToPayServiceTest (TestCase ):
1111
1212 def setUp (self ):
13- self .obtain_amount_to_pay = ObtainAmountToPayService ()
13+ self .obtain_amount_to_pay = ObtainAmountToPayService (DiscountService () )
1414 self .comic = None
1515
1616 def assertThatAmountToPayIs (self , amount ):
You can’t perform that action at this time.
0 commit comments