Where to put validation of value object that require database lookup?

Viewed 557

I have an entity Coupon with some attributes and one of them is platform. Platform is a value object with single attribute:name. For example, there is Coupon for web platform and there is also another one for Android app platform.

In the admin dashboard, an admin can specify platform for the new Coupon she is creating. Since our business is growing I decided to put list of valid/supported platform in a table in database. So when we rollout our new iPhone app, I can simply add new entry to the platform table (I haven't had time to create dashboard for it but it's possible in the future, but for now adding directly to database is simple enough).

My current implementation is as follows:

CouponApplicationService {
  createCoupon(percentage, platformName) {
    platform = platformRepository.getByName(platform name)
    coupon = new Coupon(percentage,platform)
    couponRepository.save(coupon)
  }
}

However, I am feeling weird that I have to create repository for a ValueObject. Is it actually okay to do so? Or maybe I was mistaken to think that Platform is a ValueObject and it's actually an entity that require an ID?

Thank you

1 Answers
Related