Bookmark imported game

This commit is contained in:
Thibault Duplessis 2013-02-26 13:50:41 +01:00
parent 51013bc56c
commit 649a8c7659
6 changed files with 18 additions and 15 deletions

View file

@ -13,13 +13,13 @@ final class BookmarkApi(
userRepo: UserRepo, userRepo: UserRepo,
paginator: PaginatorBuilder) { paginator: PaginatorBuilder) {
def toggle(gameId: String, user: User): IO[Unit] = for { def toggle(gameId: String, userId: String): IO[Unit] = for {
gameOption gameRepo game gameId gameOption gameRepo game gameId
_ gameOption.fold( _ gameOption.fold(
game for { game for {
bookmarked bookmarkRepo.toggle(game.id, user.id) bookmarked bookmarkRepo.toggle(game.id, userId)
_ gameRepo.incBookmarks(game.id, bookmarked.fold(1, -1)) _ gameRepo.incBookmarks(game.id, bookmarked.fold(1, -1))
_ io(cached invalidateUserId user.id) _ io(cached invalidateUserId userId)
} yield (), } yield (),
io()) io())
} yield () } yield ()

View file

@ -12,7 +12,6 @@ object Bookmark extends LilaController {
private def gameRepo = env.game.gameRepo private def gameRepo = env.game.gameRepo
def toggle(gameId: String) = Auth { implicit ctx def toggle(gameId: String) = Auth { implicit ctx
me me IOk(api.toggle(gameId, me.id))
IOk(api.toggle(gameId, me))
} }
} }

View file

@ -117,7 +117,8 @@ final class CoreEnv private (application: Application, val settings: Settings) {
lazy val importer = new lila.importer.ImporterEnv( lazy val importer = new lila.importer.ImporterEnv(
gameRepo = game.gameRepo, gameRepo = game.gameRepo,
hand = round.hand, hand = round.hand,
finisher = round.finisher) finisher = round.finisher,
bookmark = bookmark.api.toggle _)
lazy val tournament = new lila.tournament.TournamentEnv( lazy val tournament = new lila.tournament.TournamentEnv(
app = app, app = app,

View file

@ -12,7 +12,8 @@ import akka.dispatch.Future
final class Importer( final class Importer(
gameRepo: GameRepo, gameRepo: GameRepo,
hand: Hand, hand: Hand,
finisher: Finisher) extends Futuristic { finisher: Finisher,
bookmark: (String, String) IO[Unit]) extends Futuristic {
val delayInMs = 100 val delayInMs = 100
@ -26,6 +27,9 @@ final class Importer(
_ ((result |@| dbGame) apply { _ ((result |@| dbGame) apply {
case (res, dbg) finish(dbg, res) case (res, dbg) finish(dbg, res)
}) | Future() }) | Future()
_ ((dbGame |@| user) apply {
case (dbg, u) bookmark(dbg.id, u).toFuture
}) | Future()
} yield game.some } yield game.some
case _ Future(none) case _ Future(none)
} }

View file

@ -4,12 +4,15 @@ package importer
import game.GameRepo import game.GameRepo
import round.{ Hand, Finisher } import round.{ Hand, Finisher }
import scalaz.effects.IO
final class ImporterEnv( final class ImporterEnv(
gameRepo: GameRepo, gameRepo: GameRepo,
hand: Hand, hand: Hand,
finisher: Finisher) { finisher: Finisher,
bookmark: (String, String) IO[Unit]) {
lazy val forms = new DataForm lazy val forms = new DataForm
lazy val importer = new Importer(gameRepo, hand, finisher) lazy val importer = new Importer(gameRepo, hand, finisher, bookmark)
} }

4
todo
View file

@ -58,7 +58,3 @@ recognize pgn in forum and show a pgn4web
localize in chrome web store localize in chrome web store
make deploy of translations easier (new project?) make deploy of translations easier (new project?)
show language list on 2/3 columns show language list on 2/3 columns
deploy
------
db.game4.ensureIndex({"me.pgni.user":1},{sparse:1})