senro_usecaser 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -182,9 +182,89 @@ class DevelopmentProvider < SenroUsecaser::Provider
182
182
  def register: (SenroUsecaser::Container) -> void
183
183
  end
184
184
 
185
+ # 最初のステップ用(user_id, product_ids)
186
+ module OrderRequestInput
187
+ # : () -> Integer
188
+ def user_id: () -> Integer
189
+
190
+ # : () -> Array[Integer]
191
+ def product_ids: () -> Array[Integer]
192
+ end
193
+
194
+ # ユーザー検証後(user, product_ids)
195
+ module ValidatedUserInput
196
+ # : () -> User
197
+ def user: () -> User
198
+
199
+ # : () -> Array[Integer]
200
+ def product_ids: () -> Array[Integer]
201
+ end
202
+
203
+ # 商品検証後(user, items, subtotal)
204
+ module ValidatedProductsInput
205
+ # : () -> User
206
+ def user: () -> User
207
+
208
+ # : () -> Array[Product]
209
+ def items: () -> Array[Product]
210
+
211
+ # : () -> Integer
212
+ def subtotal: () -> Integer
213
+ end
214
+
215
+ # 税計算後(user, items, subtotal, tax)
216
+ module TaxCalculatedInput
217
+ # : () -> User
218
+ def user: () -> User
219
+
220
+ # : () -> Array[Product]
221
+ def items: () -> Array[Product]
222
+
223
+ # : () -> Integer
224
+ def subtotal: () -> Integer
225
+
226
+ # : () -> Integer
227
+ def tax: () -> Integer
228
+ end
229
+
230
+ # 割引適用後(user, items, subtotal, tax, discount)
231
+ # TaxCalculatedInput を継承
232
+ module DiscountAppliedInput
233
+ include TaxCalculatedInput
234
+
235
+ # : () -> Integer
236
+ def discount: () -> Integer
237
+ end
238
+
239
+ # 合計計算後(user, items, subtotal, tax, discount, total)
240
+ # DiscountAppliedInput を継承(TaxCalculatedInput も含む)
241
+ module TotalCalculatedInput
242
+ include DiscountAppliedInput
243
+
244
+ # : () -> Integer
245
+ def total: () -> Integer
246
+ end
247
+
248
+ # 注文作成後(user, order)
249
+ module OrderCreatedInput
250
+ # : () -> User
251
+ def user: () -> User
252
+
253
+ # : () -> Order
254
+ def order: () -> Order
255
+ end
256
+
257
+ # 最終出力用(order)
258
+ module FinalOrderInput
259
+ # : () -> Order
260
+ def order: () -> Order
261
+ end
262
+
185
263
  # ユーザー検証
186
264
  class ValidateUserUseCase < SenroUsecaser::Base
187
265
  class Input
266
+ include OrderRequestInput
267
+
188
268
  # : (user_id: Integer, product_ids: Array[Integer], **untyped) -> void
189
269
  def initialize: (user_id: Integer, product_ids: Array[Integer], **untyped) -> void
190
270
 
@@ -196,6 +276,8 @@ class ValidateUserUseCase < SenroUsecaser::Base
196
276
  end
197
277
 
198
278
  class Output
279
+ include ValidatedUserInput
280
+
199
281
  # : (user: User, product_ids: Array[Integer], **untyped) -> void
200
282
  def initialize: (user: User, product_ids: Array[Integer], **untyped) -> void
201
283
 
@@ -215,6 +297,8 @@ end
215
297
  # 商品検証と在庫チェック
216
298
  class ValidateProductsUseCase < SenroUsecaser::Base
217
299
  class Input
300
+ include ValidatedUserInput
301
+
218
302
  # : (user: User, product_ids: Array[Integer], **untyped) -> void
219
303
  def initialize: (user: User, product_ids: Array[Integer], **untyped) -> void
220
304
 
@@ -226,6 +310,8 @@ class ValidateProductsUseCase < SenroUsecaser::Base
226
310
  end
227
311
 
228
312
  class Output
313
+ include ValidatedProductsInput
314
+
229
315
  # : (user: User, items: Array[Product], subtotal: Integer, **untyped) -> void
230
316
  def initialize: (user: User, items: Array[Product], subtotal: Integer, **untyped) -> void
231
317
 
@@ -248,6 +334,8 @@ end
248
334
  # 税金計算
249
335
  class CalculateTaxUseCase < SenroUsecaser::Base
250
336
  class Input
337
+ include ValidatedProductsInput
338
+
251
339
  # : (user: User, items: Array[Product], subtotal: Integer, **untyped) -> void
252
340
  def initialize: (user: User, items: Array[Product], subtotal: Integer, **untyped) -> void
253
341
 
@@ -262,6 +350,8 @@ class CalculateTaxUseCase < SenroUsecaser::Base
262
350
  end
263
351
 
264
352
  class Output
353
+ include TaxCalculatedInput
354
+
265
355
  # : (user: User, items: Array[Product], subtotal: Integer, tax: Integer, **untyped) -> void
266
356
  def initialize: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, **untyped) -> void
267
357
 
@@ -285,6 +375,8 @@ end
285
375
  # プレミアム会員割引
286
376
  class ApplyPremiumDiscountUseCase < SenroUsecaser::Base
287
377
  class Input
378
+ include TaxCalculatedInput
379
+
288
380
  # : (user: User, items: Array[Product], subtotal: Integer, tax: Integer, **untyped) -> void
289
381
  def initialize: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, **untyped) -> void
290
382
 
@@ -302,6 +394,8 @@ class ApplyPremiumDiscountUseCase < SenroUsecaser::Base
302
394
  end
303
395
 
304
396
  class Output
397
+ include DiscountAppliedInput
398
+
305
399
  # : (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, **untyped) -> void
306
400
  def initialize: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, **untyped) -> void
307
401
 
@@ -328,8 +422,12 @@ class ApplyPremiumDiscountUseCase < SenroUsecaser::Base
328
422
  end
329
423
 
330
424
  # 合計計算
425
+ # Note: TaxCalculatedInput または DiscountAppliedInput のどちらも受け入れる
426
+ # discount がない場合はデフォルト値 0 を使用
331
427
  class CalculateTotalUseCase < SenroUsecaser::Base
332
428
  class Input
429
+ include TaxCalculatedInput
430
+
333
431
  # : (user: User, items: Array[Product], subtotal: Integer, tax: Integer, ?discount: Integer, **untyped) -> void
334
432
  def initialize: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, ?discount: Integer, **untyped) -> void
335
433
 
@@ -350,6 +448,8 @@ class CalculateTotalUseCase < SenroUsecaser::Base
350
448
  end
351
449
 
352
450
  class Output
451
+ include TotalCalculatedInput
452
+
353
453
  # : (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, total: Integer, **untyped) -> void
354
454
  def initialize: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, total: Integer, **untyped) -> void
355
455
 
@@ -372,13 +472,15 @@ class CalculateTotalUseCase < SenroUsecaser::Base
372
472
  attr_reader total: untyped
373
473
  end
374
474
 
375
- # : (Input) -> SenroUsecaser::Result[Output]
376
- def call: (Input) -> SenroUsecaser::Result[Output]
475
+ # : (TaxCalculatedInput) -> SenroUsecaser::Result[Output]
476
+ def call: (TaxCalculatedInput) -> SenroUsecaser::Result[Output]
377
477
  end
378
478
 
379
479
  # 決済処理
380
480
  class ProcessPaymentUseCase < SenroUsecaser::Base
381
481
  class Input
482
+ include TotalCalculatedInput
483
+
382
484
  # : (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, total: Integer, **untyped) -> void
383
485
  def initialize: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, total: Integer, **untyped) -> void
384
486
 
@@ -402,6 +504,8 @@ class ProcessPaymentUseCase < SenroUsecaser::Base
402
504
  end
403
505
 
404
506
  class Output
507
+ include TotalCalculatedInput
508
+
405
509
  # : (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, total: Integer, payment: PaymentResult, **untyped) -> void
406
510
  def initialize: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, total: Integer, payment: PaymentResult, **untyped) -> void
407
511
 
@@ -436,6 +540,8 @@ end
436
540
  # 注文作成
437
541
  class CreateOrderRecordUseCase < SenroUsecaser::Base
438
542
  class Input
543
+ include TotalCalculatedInput
544
+
439
545
  # : (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, total: Integer, **untyped) -> void
440
546
  def initialize: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, total: Integer, **untyped) -> void
441
547
 
@@ -459,6 +565,8 @@ class CreateOrderRecordUseCase < SenroUsecaser::Base
459
565
  end
460
566
 
461
567
  class Output
568
+ include OrderCreatedInput
569
+
462
570
  # : (user: User, order: Order, **untyped) -> void
463
571
  def initialize: (user: User, order: Order, **untyped) -> void
464
572
 
@@ -478,6 +586,8 @@ end
478
586
  # 通知送信
479
587
  class SendOrderNotificationUseCase < SenroUsecaser::Base
480
588
  class Input
589
+ include OrderCreatedInput
590
+
481
591
  # : (user: User, order: Order, **untyped) -> void
482
592
  def initialize: (user: User, order: Order, **untyped) -> void
483
593
 
@@ -489,6 +599,8 @@ class SendOrderNotificationUseCase < SenroUsecaser::Base
489
599
  end
490
600
 
491
601
  class Output
602
+ include FinalOrderInput
603
+
492
604
  # : (user: User, order: Order, notified: bool, **untyped) -> void
493
605
  def initialize: (user: User, order: Order, notified: bool, **untyped) -> void
494
606
 
@@ -504,13 +616,15 @@ class SendOrderNotificationUseCase < SenroUsecaser::Base
504
616
 
505
617
  def notification_service: () -> NotificationService
506
618
 
507
- # : (Input) -> SenroUsecaser::Result[Output]
508
- def call: (Input) -> SenroUsecaser::Result[Output]
619
+ # : (OrderCreatedInput) -> SenroUsecaser::Result[Output]
620
+ def call: (OrderCreatedInput) -> SenroUsecaser::Result[Output]
509
621
  end
510
622
 
511
623
  # パイプライン最終出力をラップ
512
624
  class WrapOrderOutputUseCase < SenroUsecaser::Base
513
625
  class Input
626
+ include FinalOrderInput
627
+
514
628
  # : (order: Order, **untyped) -> void
515
629
  def initialize: (order: Order, **untyped) -> void
516
630
 
@@ -524,16 +638,18 @@ end
524
638
 
525
639
  # ログ記録用 Extension
526
640
  module LoggingExtension
527
- # : (Hash[Symbol, untyped]) -> void
528
- def self.before: (Hash[Symbol, untyped]) -> void
641
+ # : (untyped) -> void
642
+ def self.before: (untyped) -> void
529
643
 
530
- # : (Hash[Symbol, untyped], SenroUsecaser::Result[untyped]) -> void
531
- def self.after: (Hash[Symbol, untyped], SenroUsecaser::Result[untyped]) -> void
644
+ # : (untyped, SenroUsecaser::Result[untyped]) -> void
645
+ def self.after: (untyped, SenroUsecaser::Result[untyped]) -> void
532
646
  end
533
647
 
534
648
  # 注文作成パイプライン
535
649
  class CreateOrderUseCase < SenroUsecaser::Base
536
650
  class Input
651
+ include OrderRequestInput
652
+
537
653
  # : (user_id: Integer, product_ids: Array[Integer], **untyped) -> void
538
654
  def initialize: (user_id: Integer, product_ids: Array[Integer], **untyped) -> void
539
655
 
@@ -546,22 +662,68 @@ class CreateOrderUseCase < SenroUsecaser::Base
546
662
 
547
663
  def self.call: (Input, ?container: SenroUsecaser::Container) -> SenroUsecaser::Result[CreateOrderOutput]
548
664
 
549
- # : (Hash[Symbol, untyped]) -> bool
550
- def premium_user?: (Hash[Symbol, untyped]) -> bool
665
+ # : (TaxCalculatedInput) -> bool
666
+ def premium_user?: (TaxCalculatedInput) -> bool
551
667
  end
552
668
 
553
669
  # リクエストごとに current_user を注入するパターン
554
670
  class CurrentUserAwareUseCase < SenroUsecaser::Base
671
+ # 空のInputクラス(入力不要なUseCase用)
672
+ class Input
673
+ # : (**untyped) -> void
674
+ def initialize: (**untyped) -> void
675
+ end
676
+
555
677
  def current_user: () -> User
556
678
 
557
679
  def logger: () -> Logger
558
680
 
559
- # : (?untyped, **untyped) -> SenroUsecaser::Result[GreetingOutput]
560
- def call: (?untyped, **untyped) -> SenroUsecaser::Result[GreetingOutput]
681
+ # : (Input) -> SenroUsecaser::Result[GreetingOutput]
682
+ def call: (Input) -> SenroUsecaser::Result[GreetingOutput]
683
+ end
684
+
685
+ # Accumulated Context 用インターフェース
686
+ module InitialInput
687
+ # : () -> String
688
+ def initial: () -> String
689
+ end
690
+
691
+ module Step1Output
692
+ # : () -> String
693
+ def step1_data: () -> String
694
+
695
+ # : () -> Integer
696
+ def counter: () -> Integer
697
+ end
698
+
699
+ module Step2Output
700
+ include Step1Output
701
+
702
+ # : () -> String
703
+ def step2_data: () -> String
704
+ end
705
+
706
+ module FinalAccumulatedInput
707
+ # : () -> Integer
708
+ def counter: () -> Integer
709
+
710
+ # : () -> bool
711
+ def final: () -> bool
712
+ end
713
+
714
+ module Step3Output
715
+ include Step2Output
716
+
717
+ include FinalAccumulatedInput
718
+
719
+ # : () -> String
720
+ def step3_data: () -> String
561
721
  end
562
722
 
563
723
  class Step1 < SenroUsecaser::Base
564
724
  class Input
725
+ include InitialInput
726
+
565
727
  # : (initial: String, **untyped) -> void
566
728
  def initialize: (initial: String, **untyped) -> void
567
729
 
@@ -570,6 +732,8 @@ class Step1 < SenroUsecaser::Base
570
732
  end
571
733
 
572
734
  class Output
735
+ include Step1Output
736
+
573
737
  # : (step1_data: String, counter: Integer, **untyped) -> void
574
738
  def initialize: (step1_data: String, counter: Integer, **untyped) -> void
575
739
 
@@ -580,12 +744,14 @@ class Step1 < SenroUsecaser::Base
580
744
  attr_reader counter: untyped
581
745
  end
582
746
 
583
- # : (Input) -> SenroUsecaser::Result[Output]
584
- def call: (Input) -> SenroUsecaser::Result[Output]
747
+ # : (InitialInput) -> SenroUsecaser::Result[Output]
748
+ def call: (InitialInput) -> SenroUsecaser::Result[Output]
585
749
  end
586
750
 
587
751
  class Step2 < SenroUsecaser::Base
588
752
  class Input
753
+ include Step1Output
754
+
589
755
  # : (step1_data: String, counter: Integer, **untyped) -> void
590
756
  def initialize: (step1_data: String, counter: Integer, **untyped) -> void
591
757
 
@@ -597,6 +763,8 @@ class Step2 < SenroUsecaser::Base
597
763
  end
598
764
 
599
765
  class Output
766
+ include Step2Output
767
+
600
768
  # : (step1_data: String, step2_data: String, counter: Integer, **untyped) -> void
601
769
  def initialize: (step1_data: String, step2_data: String, counter: Integer, **untyped) -> void
602
770
 
@@ -610,12 +778,14 @@ class Step2 < SenroUsecaser::Base
610
778
  attr_reader counter: untyped
611
779
  end
612
780
 
613
- # : (Input) -> SenroUsecaser::Result[Output]
614
- def call: (Input) -> SenroUsecaser::Result[Output]
781
+ # : (Step1Output) -> SenroUsecaser::Result[Output]
782
+ def call: (Step1Output) -> SenroUsecaser::Result[Output]
615
783
  end
616
784
 
617
785
  class Step3 < SenroUsecaser::Base
618
786
  class Input
787
+ include Step2Output
788
+
619
789
  # : (step1_data: String, step2_data: String, counter: Integer, **untyped) -> void
620
790
  def initialize: (step1_data: String, step2_data: String, counter: Integer, **untyped) -> void
621
791
 
@@ -630,6 +800,8 @@ class Step3 < SenroUsecaser::Base
630
800
  end
631
801
 
632
802
  class Output
803
+ include Step3Output
804
+
633
805
  # : (step1_data: String, step2_data: String, step3_data: String, counter: Integer, final: bool, **untyped) -> void
634
806
  def initialize: (step1_data: String, step2_data: String, step3_data: String, counter: Integer, final: bool, **untyped) -> void
635
807
 
@@ -649,12 +821,14 @@ class Step3 < SenroUsecaser::Base
649
821
  attr_reader final: untyped
650
822
  end
651
823
 
652
- # : (Input) -> SenroUsecaser::Result[Output]
653
- def call: (Input) -> SenroUsecaser::Result[Output]
824
+ # : (Step1Output) -> SenroUsecaser::Result[Output]
825
+ def call: (Step1Output) -> SenroUsecaser::Result[Output]
654
826
  end
655
827
 
656
828
  class WrapAccumulatedOutputUseCase < SenroUsecaser::Base
657
829
  class Input
830
+ include FinalAccumulatedInput
831
+
658
832
  # : (counter: Integer, final: bool, **untyped) -> void
659
833
  def initialize: (counter: Integer, final: bool, **untyped) -> void
660
834
 
@@ -665,12 +839,14 @@ class WrapAccumulatedOutputUseCase < SenroUsecaser::Base
665
839
  attr_reader final: untyped
666
840
  end
667
841
 
668
- # : (Input) -> SenroUsecaser::Result[AccumulatedOutput]
669
- def call: (Input) -> SenroUsecaser::Result[AccumulatedOutput]
842
+ # : (FinalAccumulatedInput) -> SenroUsecaser::Result[AccumulatedOutput]
843
+ def call: (FinalAccumulatedInput) -> SenroUsecaser::Result[AccumulatedOutput]
670
844
  end
671
845
 
672
846
  class AccumulatedContextDemo < SenroUsecaser::Base
673
847
  class Input
848
+ include InitialInput
849
+
674
850
  # : (initial: String, **untyped) -> void
675
851
  def initialize: (initial: String, **untyped) -> void
676
852