Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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:</p> <pre><code>trait Profile case object AdminProfile extends Profile case object CustomerProfile extends Profile case object CompanyProfile extends Profile </code></pre> <p>And you have a method that extracts a profile from the request header:</p> <pre><code>def extractProfile(rh: RequestHeader): Option[Profile] = rh.session.get("profile").map { case "admin" =&gt; AdminProfile case "customer" =&gt; CustomerProfile case "company" =&gt; CompanyProfile } </code></pre> <p>You can just do this in your action:</p> <pre><code>def dashboard = Action { req =&gt; extractProfile(req).map { case AdminProfile =&gt; // code here that loads stuff and renders it for admin case CustomerProfile =&gt; // code here for customer case CompanyProfile =&gt; // code here for company } getOrElse NotFound } </code></pre> <p>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:</p> <pre><code>def dashboard = EssentialAction { req =&gt; extractProfile(req).map { case AdminProfile =&gt; Admin.dashboard(req) case CustomerProfile =&gt; Customer.dashboard(req) case CompanyProfile =&gt; Company.dashboard(req) } getOrElse NotFound } </code></pre> <p>Notice the use of <code>EssentialAction</code> here. It's necessary if you want to compose multiple actions into one action.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload