score:0
assuming that these profiles are persisted in some form, a simple mechanism would be to have a field identifying them and to use that field(from the table(sql)/document(nosql)) to determine which features should be active or which templates to use.
score:0
i would use one action
that handles the route /dashboard
and have three different views, one for each kind of users. once a request received, the action
will be able to know which kind of users is making the call and would respond with something like ok(views.html.customerdashboard)
for example.
score:1
since the dashboard isn't really a resource, it's a context sensitive thing, i wouldn't worry about being restful as the other posts suggest. so, you have your profiles:
trait profile
case object adminprofile extends profile
case object customerprofile extends profile
case object companyprofile extends profile
and you have a method that extracts a profile from the request header:
def extractprofile(rh: requestheader): option[profile] = rh.session.get("profile").map {
case "admin" => adminprofile
case "customer" => customerprofile
case "company" => companyprofile
}
you can just do this in your action:
def dashboard = action { req =>
extractprofile(req).map {
case adminprofile => // code here that loads stuff and renders it for admin
case customerprofile => // code here for customer
case companyprofile => // code here for company
} getorelse notfound
}
let's say though that you wanted the admins to be able to access the customer or company dashboard, and so you already have the 3 routes as described in your original post, so you can go to a specific one if you want. you can easily add a fourth action that simply delegates /dashboard to the appropriate one. eg:
def dashboard = essentialaction { req =>
extractprofile(req).map {
case adminprofile => admin.dashboard(req)
case customerprofile => customer.dashboard(req)
case companyprofile => company.dashboard(req)
} getorelse notfound
}
notice the use of essentialaction
here. it's necessary if you want to compose multiple actions into one action.
score:4
if the profile should be hidden from the url point of view (not restful ^^). you can hide it, either in the flash scope or session one, regarding the length of the flows.
now, for the routing part, it's yet another story. since you can route (in the route
file) using 'hidden' values, you won't be able to represent these routes in the configuration.
however, you could do you own action interceptor that extract the profile and redirect to the right dashboard (this is probably the quick and dirtiest manner)...
at last, couldn't you just use the profile in the path ;-) ?
get /dashboard dashboard.index
get /admin/dashboard admin.dashboard
get /customer/dashboard customer.dashboard
get /company/dashboard company.dashboard
controller... but doesn't scale for further calls if needed...
object dashboard extends controller {
def index = action { implicit request =>
request.session.get("profile").map { p =>
p match {
case "admin" => redirect( routes.admin.dashboard() )
case "customer" => redirect( routes.customer.dashboard() )
case "company" => redirect( routes.company.dashboard() )
}
}.getorelse {
redirect( routes.customer.dashboard() )
}
}
}
Source: stackoverflow.com
Related Query
- How to use one url for several actions based on profile information?
- How to use just one scala library for maven/eclipse/scala
- How can i use one sequence to auto increment several tables in squeryl (PostgreSQL)?
- PlayFramework - How to use geolocation to redirect client to correct url based on country?
- How to use cdn url with play framework and scala for image display?
- How to wait for several Futures?
- How to use Scala in IntelliJ IDEA (or: why is it so difficult to get a working IDE for Scala)?
- How do I declare a constructor for an 'object' class type in Scala? I.e., a one time operation for the singleton
- How do you use scalaz.WriterT for logging in a for expression?
- How to use actors for database access and DDD?
- How to set the number of threads to use for par
- SLICK How to define bidirectional one-to-many relationship for use in case class
- How do the Scala based frameworks stack up for a complete Scala newbie - Lift, Play, Circumflex, etc
- SPARK DataFrame: How to efficiently split dataframe for each group based on same column values
- How to inject multi dependencies when I use "Reader monad" for dependency injection?
- How to escape a string for use in XML/HTML document in Scala?
- How can I use http request headers for content negotiation in a Mashaller?
- How can I use JMH for Scala benchmarks together with sbt?
- How can I get a Random URL on http request for Gatling?
- How to use a wildcard for a higher-kinded type in Scala?
- How to make IntelliJ IDEA use javac for Java and scalac for Scala?
- Scala spark: how to use dataset for a case class with the schema has snake_case?
- How can one use Amazon's DynamoDBMapper in Scala?
- Scala - how to explicitly choose which overloaded method to use when one arg must be null?
- How to use Reactive Streams for NIO binary processing?
- How to use return of one gatling request into another request - Scala
- How to profile the time spent for a task in SBT
- How to Use Circe for Decoding JSON Lists/Arrays in Scala
- How to implement several 'threads' running in only one thread
- How do I use Scala dispatch to get the URL returned in a 301 redirect?
More Query from same tag
- Using sockets with scalajs
- Stackless Scala With Free Monads, complete example
- Scala Doobie not inserting values into database
- Use SBT to launch an applicative task/batch?
- How to convert String into list of Integers in Scala?
- Apache Spark - Transform Map[String, String] to Map[String, Struct]
- Use persistent external program for occasional input / output translation in Scala
- call ResultSet.getMetaData in Scala results in java.lang.SecurityException
- Does every traversable monad have an accompanying sequence
- Literal identifier in back ticks in scala
- Unable to match exception instance in test case
- why does eclipse complain "recursive method loop needs result type"?
- Play Framework/Scala: "return" statement in Action?
- Forking each ScalaTest suite with sbt
- Error with Spark: NoSuchMethodError: scala.Predef$.$conforms()Lscala/Predef$$less$colon$less
- Spark: how to not use aws credentials explicitly in Spark application
- Why does join fail with "java.util.concurrent.TimeoutException: Futures timed out after [300 seconds]"?
- Scalding Tutorial with HDFS: Data is missing from one or more paths in: List(tutorial/data/hello.txt)
- create JAR for Spark
- Why is Scala looking for SNAPSHOT version?
- Specify subset of elements in Spark RDD (Scala)
- Scala sealed abstract class with enum object matching against string
- Scala filter return only one (or specific number) of results
- java.net.MalformedURLException: no protocol: null when passing an arg to a spark-submit job
- Difference between >> and >>> in Scala
- Scala: Why is this pattern match code throwing an IndexOutOfBoundsException?
- how to declare a mutable map with key value typing in Scala without initialization
- Play Framework, JSON Overloaded method value [apply]
- Safely parsing a string to a boolean
- How to fetch data for Optional List of custom data type in cassandra using Websudos Phanthom