add base team classes
This commit is contained in:
parent
00da91f76d
commit
69688fcb8b
|
@ -50,6 +50,10 @@ final class CoreEnv private (application: Application, val settings: Settings) {
|
||||||
settings = settings,
|
settings = settings,
|
||||||
mongodb = mongodb.apply _)
|
mongodb = mongodb.apply _)
|
||||||
|
|
||||||
|
lazy val team = new lila.team.TeamEnv(
|
||||||
|
settings = settings,
|
||||||
|
mongodb = mongodb.apply _)
|
||||||
|
|
||||||
lazy val lobby = new lila.lobby.LobbyEnv(
|
lazy val lobby = new lila.lobby.LobbyEnv(
|
||||||
app = app,
|
app = app,
|
||||||
settings = settings,
|
settings = settings,
|
||||||
|
|
|
@ -123,6 +123,8 @@ final class Settings(config: Config, val IsDev: Boolean) {
|
||||||
val WikiCollectionPage = getString("wiki.collection.page")
|
val WikiCollectionPage = getString("wiki.collection.page")
|
||||||
val WikiGitUrl = getString("wiki.git_url")
|
val WikiGitUrl = getString("wiki.git_url")
|
||||||
|
|
||||||
|
val TeamCollectionTeam = getString("team.collection.team")
|
||||||
|
|
||||||
val BookmarkCollectionBookmark = getString("bookmark.collection.bookmark")
|
val BookmarkCollectionBookmark = getString("bookmark.collection.bookmark")
|
||||||
|
|
||||||
val CoreCollectionCache = getString("core.collection.cache")
|
val CoreCollectionCache = getString("core.collection.cache")
|
||||||
|
|
12
app/core/Text.scala
Normal file
12
app/core/Text.scala
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package lila.core
|
||||||
|
|
||||||
|
object Text {
|
||||||
|
|
||||||
|
def slugify(input: String) = {
|
||||||
|
import java.text.Normalizer
|
||||||
|
val nowhitespace = input.replace(" ", "-")
|
||||||
|
val normalized = Normalizer.normalize(nowhitespace, Normalizer.Form.NFD)
|
||||||
|
val slug = """[^\w-]""".r.replaceAllIn(normalized, "")
|
||||||
|
slug.toLowerCase
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,7 +26,7 @@ final class TopicRepo(
|
||||||
}
|
}
|
||||||
|
|
||||||
def nextSlug(categ: Categ, name: String, it: Int = 1): IO[String] = {
|
def nextSlug(categ: Categ, name: String, it: Int = 1): IO[String] = {
|
||||||
val slug = slugify(name) + (it == 1).fold("", "-" + it)
|
val slug = core.Text.slugify(name) + (it == 1).fold("", "-" + it)
|
||||||
byTree(categ.slug, slug) flatMap {
|
byTree(categ.slug, slug) flatMap {
|
||||||
_.isDefined.fold(
|
_.isDefined.fold(
|
||||||
nextSlug(categ, name, it + 1),
|
nextSlug(categ, name, it + 1),
|
||||||
|
@ -34,14 +34,6 @@ final class TopicRepo(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def slugify(input: String) = {
|
|
||||||
import java.text.Normalizer
|
|
||||||
val nowhitespace = input.replace(" ", "-")
|
|
||||||
val normalized = Normalizer.normalize(nowhitespace, Normalizer.Form.NFD)
|
|
||||||
val slug = """[^\w-]""".r.replaceAllIn(normalized, "")
|
|
||||||
slug.toLowerCase
|
|
||||||
}
|
|
||||||
|
|
||||||
val all: IO[List[Topic]] = io {
|
val all: IO[List[Topic]] = io {
|
||||||
find(DBObject()).toList
|
find(DBObject()).toList
|
||||||
}
|
}
|
||||||
|
|
22
app/team/Member.scala
Normal file
22
app/team/Member.scala
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package lila
|
||||||
|
package team
|
||||||
|
|
||||||
|
import org.joda.time.{ DateTime, Duration }
|
||||||
|
import org.scala_tools.time.Imports._
|
||||||
|
|
||||||
|
import user.User
|
||||||
|
|
||||||
|
case class Member(
|
||||||
|
id: String,
|
||||||
|
createdAt: DateTime) {
|
||||||
|
|
||||||
|
def is(userId: String): Boolean = id == userId
|
||||||
|
def is(user: User): Boolean = is(user.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
object Member {
|
||||||
|
|
||||||
|
def apply(user: User): Member = apply(user.id)
|
||||||
|
|
||||||
|
def apply(user: String): Member = new Member(id = user, createdAt = DateTime.now)
|
||||||
|
}
|
38
app/team/Team.scala
Normal file
38
app/team/Team.scala
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package lila
|
||||||
|
package team
|
||||||
|
|
||||||
|
import user.User
|
||||||
|
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
import com.novus.salat.annotations.Key
|
||||||
|
import java.text.Normalizer
|
||||||
|
|
||||||
|
case class Team(
|
||||||
|
@Key("_id") id: String, // also the url slug
|
||||||
|
name: String,
|
||||||
|
location: Option[String],
|
||||||
|
description: String,
|
||||||
|
members: List[Member],
|
||||||
|
nbMembers: Int,
|
||||||
|
createdAt: DateTime,
|
||||||
|
createdBy: String) {
|
||||||
|
|
||||||
|
def slug = id
|
||||||
|
}
|
||||||
|
|
||||||
|
object Team {
|
||||||
|
|
||||||
|
def apply(
|
||||||
|
name: String,
|
||||||
|
location: Option[String],
|
||||||
|
description: String,
|
||||||
|
createdBy: User): Team = new Team(
|
||||||
|
id = core.Text.slugify(name),
|
||||||
|
name = name,
|
||||||
|
location = location,
|
||||||
|
description = description,
|
||||||
|
members = Member(createdBy) :: Nil,
|
||||||
|
nbMembers = 1,
|
||||||
|
createdAt = DateTime.now,
|
||||||
|
createdBy = createdBy.id)
|
||||||
|
}
|
8
app/team/TeamApi.scala
Normal file
8
app/team/TeamApi.scala
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package lila
|
||||||
|
package team
|
||||||
|
|
||||||
|
import scalaz.effects._
|
||||||
|
|
||||||
|
final class TeamApi(repo: TeamRepo) {
|
||||||
|
|
||||||
|
}
|
17
app/team/TeamEnv.scala
Normal file
17
app/team/TeamEnv.scala
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package lila
|
||||||
|
package team
|
||||||
|
|
||||||
|
import core.Settings
|
||||||
|
|
||||||
|
import com.mongodb.casbah.MongoCollection
|
||||||
|
|
||||||
|
final class TeamEnv(
|
||||||
|
settings: Settings,
|
||||||
|
mongodb: String ⇒ MongoCollection) {
|
||||||
|
|
||||||
|
import settings._
|
||||||
|
|
||||||
|
lazy val repo = new TeamRepo(mongodb(TeamCollectionTeam))
|
||||||
|
|
||||||
|
lazy val api = new TeamApi(repo = repo)
|
||||||
|
}
|
41
app/team/TeamRepo.scala
Normal file
41
app/team/TeamRepo.scala
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
package lila
|
||||||
|
package team
|
||||||
|
|
||||||
|
import com.novus.salat._
|
||||||
|
import com.novus.salat.dao._
|
||||||
|
import com.mongodb.casbah.MongoCollection
|
||||||
|
import com.mongodb.casbah.query.Imports._
|
||||||
|
import scalaz.effects._
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
import org.scala_tools.time.Imports._
|
||||||
|
|
||||||
|
import user.User
|
||||||
|
|
||||||
|
final class TeamRepo(collection: MongoCollection)
|
||||||
|
extends SalatDAO[Team, String](collection) {
|
||||||
|
|
||||||
|
def byId(id: String): IO[Option[Team]] = io {
|
||||||
|
findOneById(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
def byUser(user: User): IO[List[Team]] = io {
|
||||||
|
find(userQuery(user)).sort(sortQuery).toList
|
||||||
|
}
|
||||||
|
|
||||||
|
def saveIO(team: Team): IO[Unit] = io {
|
||||||
|
update(
|
||||||
|
selectId(team.id),
|
||||||
|
_grater asDBObject team,
|
||||||
|
upsert = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
def removeIO(team: Team): IO[Unit] = io {
|
||||||
|
remove(selectId(team.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
def userQuery(user: User) = DBObject("members.id" -> user.id)
|
||||||
|
|
||||||
|
def selectId(id: String) = DBObject("_id" -> id)
|
||||||
|
|
||||||
|
val sortQuery = DBObject("updatedAt" -> -1)
|
||||||
|
}
|
|
@ -1,8 +1,6 @@
|
||||||
package lila
|
package lila
|
||||||
package tournament
|
package tournament
|
||||||
|
|
||||||
import com.mongodb.casbah.query.Imports._
|
|
||||||
|
|
||||||
import user.User
|
import user.User
|
||||||
|
|
||||||
case class Player(
|
case class Player(
|
||||||
|
|
Loading…
Reference in a new issue