Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nkpart committed Jan 30, 2010
1 parent ec86587 commit 24e607c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 55 deletions.
21 changes: 21 additions & 0 deletions src/main/scala/gae/Find.scala
Expand Up @@ -18,3 +18,24 @@ object Find {

def apply[T](implicit k: Kind[T]): Find[T] = Find(gae.createQuery[T], defaultOptions)
}

trait FindDSL {
val field: String
type QRY = Query => Query

import com.google.appengine.api.datastore.Query.SortDirection._
import com.google.appengine.api.datastore.Query.FilterOperator._

def asc: QRY = (_.addSort(field, ASCENDING))
def desc: QRY = (_.addSort(field, DESCENDING))
def ?==[T](t: T): QRY = (_.addFilter(field, EQUAL, t))

def ?!=[T](t: T): QRY = (_.addFilter(field, NOT_EQUAL, t))
}

trait FindDSLImplicits {
implicit def stringTo(s: String): FindDSL = new FindDSL { val field = s }
implicit def stringFrom(dsl: FindDSL): String = dsl.field
}

object dsl extends FindDSLImplicits
7 changes: 4 additions & 3 deletions src/main/scala/gae/package.scala
Expand Up @@ -3,12 +3,13 @@ import gae._
import scalaz._
import Scalaz._

package object gae extends
trait GAEBase extends
IdentityImplicits with
DatastoreServiceImplicits with
EntityImplicits with
UserServiceImplicits
{
UserServiceImplicits

package object gae extends GAEBase {

import com.google.appengine.api.datastore._
def createQuery[T](implicit s: Kind[T]) = new Query(s.kind)
Expand Down
12 changes: 4 additions & 8 deletions src/main/scala/scapps/Controller.scala
@@ -1,19 +1,15 @@
package scapps

import Function._
import scalaz.Scalaz._
import scalaz.http.Slinky._
import scalaz._
import http._
import Scalaz._
import scalaz.http.Slinky._
import scalaz.http._
import scalaz.http.request._
import scalaz.http.request.Request._
import scalaz.http.response._
import scalaz.http.servlet._
import scalaz.http.servlet.HttpServlet.resource
import xml.NodeSeq
import gae._
import RichNodeSeq._
import rest.Resourced
import rest._

trait Controller {
val layout: (NodeSeq => NodeSeq) // TODO strong type of layout. so the implicit is more explicit.
Expand Down
Expand Up @@ -6,7 +6,7 @@ import http.request.Request._
import Scalaz._
import rest._

trait RichRequest[IN[_]] {
trait RequestW[IN[_]] {
val request: Request[IN]

def apply(s: String)(implicit f: FoldLeft[IN]): Option[String] = (request !| s) ∘ (_.mkString)
Expand All @@ -16,10 +16,10 @@ trait RichRequest[IN[_]] {
def update[T](t: T)(implicit postable: RequestUpdate[T], fl: FoldLeft[IN]) = postable.update(request)(t)
}

trait RichRequests {
implicit def To[IN[_]](r: Request[IN]) = new RichRequest[IN] { val request = r }
trait RequestImplicits {
implicit def To[IN[_]](r: Request[IN]) = new RequestW[IN] { val request = r }

implicit def From[IN[_]](r: RichRequest[IN]) = r.request
implicit def From[IN[_]](r: RequestW[IN]) = r.request
}

object RichRequest extends RichRequests
object RichRequest extends RequestImplicits
23 changes: 0 additions & 23 deletions src/main/scala/scapps/RichNodeSeq.scala

This file was deleted.

18 changes: 4 additions & 14 deletions src/main/scala/wd/Brewery.scala
Expand Up @@ -5,28 +5,18 @@ import com.google.appengine.api.datastore.Query.SortDirection
import com.google.appengine.api.datastore.Query.SortDirection._
import com.google.appengine.api.datastore.Query.FilterOperator._
import gae._
import gae.dsl._
import scalaz._
import Scalaz._

// Location
// * full address.
// isPub
// TODO
// - full address
// - isPub

case class Country(value: String) extends NewType[String]
case class Brewery(name: String, country: Country)

object Brewery {

implicit def dsl(field: String) = new {
import com.google.appengine.api.datastore.Query.SortDirection._
import com.google.appengine.api.datastore.Query.FilterOperator._

type QRY = Query => Query

def asc: QRY = (_.addSort(field, ASCENDING))
def ?==[T](t: T): QRY = (_.addFilter(field, EQUAL, t))
}

val allByName = Find[Brewery].query("name".asc).iterable _

def allInCountry(c: Country) = Find[Brewery].query("country" ?== c.value).iterable _
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/wd/WD.scala
Expand Up @@ -8,7 +8,7 @@ import scalaz.http.request._
import wd.{Brewery, Beer, Style, Country}
import prohax.Inflector._

package object wd extends RichRequests {
package object wd extends RequestImplicits {
type DB[T] = (DatastoreService => T)
//TODO move to scapps
type NamedError = (String, String)
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/wd/controllers/BaseController.scala
Expand Up @@ -10,7 +10,6 @@ import wd.views.layouts
import com.google.appengine.api.users.UserServiceFactory

trait ControllerHelpers { self: Controller =>

implicit val charset = UTF8

val layout = layouts.main(UserServiceFactory.getUserService) _
Expand Down

0 comments on commit 24e607c

Please sign in to comment.