@@ -7,12 +7,7 @@ import lila.db.dsl.{ *, given }
7
7
8
8
case class Bookmark (game : Game , user : User )
9
9
10
- final class BookmarkApi (
11
- coll : Coll ,
12
- gameApi : GameApi ,
13
- gameProxy : lila.core.game.GameProxy ,
14
- paginator : PaginatorBuilder
15
- )(using Executor ):
10
+ final class BookmarkApi (coll : Coll , gameApi : GameApi , paginator : PaginatorBuilder )(using Executor ):
16
11
17
12
private def exists (gameId : GameId , userId : UserId ): Fu [Boolean ] =
18
13
coll.exists(selectId(gameId, userId))
@@ -38,7 +33,9 @@ final class BookmarkApi(
38
33
39
34
def remove (gameId : GameId , userId : UserId ): Funit = coll.delete.one(selectId(gameId, userId)).void
40
35
41
- def toggle (gameId : GameId , userId : UserId , v : Option [Boolean ]): Funit =
36
+ def toggle (
37
+ updateProxy : GameId => Update [Game ] => Funit
38
+ )(gameId : GameId , userId : UserId , v : Option [Boolean ]): Funit =
42
39
exists(gameId, userId)
43
40
.flatMap: e =>
44
41
val newValue = v.getOrElse(! e)
@@ -48,7 +45,7 @@ final class BookmarkApi(
48
45
_ <- if newValue then add(gameId, userId, nowInstant) else remove(gameId, userId)
49
46
inc = if newValue then 1 else - 1
50
47
_ <- gameApi.incBookmarks(gameId, inc)
51
- _ <- gameProxy.updateIfPresent (gameId)(g => g.copy(bookmarks = g.bookmarks + inc))
48
+ _ <- updateProxy (gameId)(g => g.copy(bookmarks = g.bookmarks + inc))
52
49
yield ()
53
50
.recover:
54
51
lila.db.ignoreDuplicateKey
0 commit comments