Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. trait Player extends Temp {
  2.  
  3. val gameId: BSONObjectID
  4.  
  5. val personalDetails: abc.PersonalDetails // <- comes from shared library
  6.  
  7. }
  8.  
  9. case class FootballPlayer(var _id: Option[BSONObjectID] = None,
  10. gameId: BSONObjectID,
  11. personalDetails: abc.PersonalDetails,
  12. var created: Option[DateTime] = None,
  13. var updated: Option[DateTime] = None
  14. ) extends Player
  15.  
  16. case class VideogamePlayer(var _id: Option[BSONObjectID] = None,
  17. gameId: BSONObjectID,
  18. personalDetails: abc.PersonalDetails,
  19. var created: Option[DateTime] = None,
  20. var updated: Option[DateTime] = None
  21. ) extends Player
  22.  
  23. trait PlayerDAO[T <: Player] {
  24.  
  25. def findById(_id: BSONObjectID)(implicit reads: Reads[T]): Future[Option[T]]
  26.  
  27. def insert(t: T)(implicit writes: OWrites[T]): Future[T]
  28.  
  29. }
  30.  
  31. class MongoPlayerDAO[T <: Player] @Inject()(
  32. playerRepository: PlayerRepository[T]
  33. ) extends PlayerDAO[T] {
  34.  
  35. def findById(_id: BSONObjectID)(implicit reads: Reads[T]): Future[Option[T]] = playerRepository.findById(_id)
  36.  
  37. def insert(t: T)(implicit writes: OWrites[T]): Future[T] = playerRepository.insert(t).map(_ => t)
  38.  
  39. }
  40.  
  41. class PlayerService[T <: Player] @Inject()(playerDAO: PlayerDAO[T])(implicit reads: Reads[T], writes: OWrites[T]) {
  42.  
  43. def findById(_id: BSONObjectID): Future[Option[T]] = playerDAO.findById(_id)
  44.  
  45.  
  46. def save(t: T): Future[T] = playerDAO.save(t)
  47.  
  48. }
  49.  
  50. class PlayerModule extends AbstractModule with ScalaModule {
  51.  
  52. def configure() {
  53. bind[PlayerDAO[FootballPlayer]].to[MongoPlayerDAO[FootballPlayer]]
  54. bind[PlayerDAO[VideogamePlayer]].to[MongoPlayerDAO[VideogamePlayer]]
  55. // ...
  56. ()
  57. }
  58. }
  59.  
  60. import models.FootballPlayer._
  61. import models.VideogamePlayer._
  62.  
  63. class PlayerController @Inject()(
  64. val messagesApi: MessagesApi,
  65. footballPlayerService: PlayerService[FootballPlayer],
  66. videogamePlayerService: PlayerService[VideogamePlayer]
  67. ) extends Controller with I18nSupport
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement