我按照書功能和無功領域建模如何減少樣板與Kleisli
而對於一些服務方式,它只是代表工作到存儲庫層的設計。有沒有辦法減少這個樣板:
trait FeedbackServiceImpl extends FeedbackService {
override def saveTFE(feedback: TripFeedbackEvent) =
Kleisli[Future, Context, Either[String, Id]] { ctx => ctx.feedbackRepo.save(feedback) }
override def saveLFE(feedback: LibraryFeedbackEvent) =
Kleisli[Future, Context, Either[String, Id]] { ctx => ctx.feedbackRepo.save(feedback) }
override def findByUser(userId: Id) =
Kleisli[Future, Context, Seq[FeedbackEvent]] { ctx => ctx.feedbackRepo.findByUser(userId) }
override def all =
Kleisli[Future, Context, Seq[FeedbackEvent]] { ctx => ctx.feedbackRepo.all }
override def findByTip(tipId: Id) =
Kleisli[Future, Context, Seq[FeedbackEvent]] { ctx => ctx.feedbackRepo.findByTip(tipId) }
}