forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
181 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package lila.team | ||
|
||
private object BSONHandlers { | ||
|
||
import lila.db.dsl.BSONJodaDateTimeHandler | ||
implicit val TeamBSONHandler = reactivemongo.bson.Macros.handler[Team] | ||
implicit val RequestBSONHandler = reactivemongo.bson.Macros.handler[Request] | ||
implicit val MemberBSONHandler = reactivemongo.bson.Macros.handler[Member] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package lila.team | ||
|
||
import lila.db.dsl.Coll | ||
|
||
private final class Colls( | ||
val team: Coll, | ||
val request: Coll, | ||
val member: Coll) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,44 @@ | ||
package lila.team | ||
|
||
import play.api.libs.json.Json | ||
import reactivemongo.api._ | ||
import reactivemongo.bson._ | ||
|
||
import lila.db.dsl._ | ||
import tube.memberTube | ||
|
||
object MemberRepo { | ||
|
||
// dirty | ||
private val coll = Env.current.colls.member | ||
|
||
import BSONHandlers._ | ||
|
||
type ID = String | ||
|
||
def userIdsByTeam(teamId: ID): Fu[Set[ID]] = | ||
memberTube.coll.distinct("user", BSONDocument("team" -> teamId).some) map lila.db.BSON.asStringSet | ||
coll.distinct("user", $doc("team" -> teamId).some) map lila.db.BSON.asStringSet | ||
|
||
def teamIdsByUser(userId: ID): Fu[Set[ID]] = | ||
memberTube.coll.distinct("team", BSONDocument("user" -> userId).some) map lila.db.BSON.asStringSet | ||
coll.distinct("team", $doc("user" -> userId).some) map lila.db.BSON.asStringSet | ||
|
||
def removeByteam(teamId: ID): Funit = | ||
$remove(teamQuery(teamId)) | ||
coll.remove(teamQuery(teamId)).void | ||
|
||
def removeByUser(userId: ID): Funit = | ||
$remove(userQuery(userId)) | ||
coll.remove(userQuery(userId)).void | ||
|
||
def exists(teamId: ID, userId: ID): Fu[Boolean] = | ||
$count.exists(selectId(teamId, userId)) | ||
coll.exists(selectId(teamId, userId)) | ||
|
||
def add(teamId: String, userId: String): Funit = | ||
$insert(Member.make(team = teamId, user = userId)) | ||
coll.insert(Member.make(team = teamId, user = userId)).void | ||
|
||
def remove(teamId: String, userId: String): Funit = | ||
$remove(selectId(teamId, userId)) | ||
coll.remove(selectId(teamId, userId)).void | ||
|
||
def countByTeam(teamId: String): Fu[Int] = | ||
$count(teamQuery(teamId)) | ||
coll.countSel(teamQuery(teamId)) | ||
|
||
def selectId(teamId: ID, userId: ID) = $select(Member.makeId(teamId, userId)) | ||
def teamQuery(teamId: ID) = Json.obj("team" -> teamId) | ||
def userQuery(userId: ID) = Json.obj("user" -> userId) | ||
def selectId(teamId: ID, userId: ID) = $id(Member.makeId(teamId, userId)) | ||
def teamQuery(teamId: ID) = $doc("team" -> teamId) | ||
def userQuery(userId: ID) = $doc("user" -> userId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.