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
case class GFolder(id: String, | |
eTag: String, | |
url: String, | |
iconUrl: String, | |
title: String, | |
owner: String, | |
parents: Set[String], | |
children: Set[String], | |
scions: Set[String], | |
created: LocalDateTime, |
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
case class MagicNotebook(tree: GFolder, | |
implicit val folders: Map[String, GFolder], | |
implicit val docs: Map[String, GDoc]) | |
object MagicNotebook { | |
def create(userId: String)(implicit s: Session) = { | |
DbHomes.findById(userId).flatMap { fileId => | |
DbGFolders.findById(fileId).map { tree => | |
val folders = DbGFolders.findAllFor(fileId) |
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
CREATE VIEW scion_view AS | |
WITH RECURSIVE scions(id, scion) AS ( | |
SELECT c.id, c.child | |
FROM children AS c | |
UNION ALL | |
SELECT s.id, c.child | |
FROM children AS c, scions AS s | |
WHERE c.id = s.scion) | |
SELECT * FROM scions ORDER BY id, scion; |
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
SELECT DISTINCT | |
id, string_agg(child, ',' ORDER BY child) AS child_str | |
FROM children GROUP BY id; |
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
CREATE VIEW gfolder_view AS | |
SELECT | |
f.id, f.e_tag, f.url, f.icon_url, f.title, m.name, f.file_owner, | |
p.parent_str, c.child_str, s.scion_str, f.created, f.modified | |
FROM | |
gfiles AS f | |
JOIN mimes AS m ON (f.mime_type = m.name) | |
LEFT JOIN (SELECT DISTINCT id, string_agg(parent, ',' ORDER BY parent) AS parent_str | |
FROM parents GROUP BY id) AS p ON (f.id = p.id) | |
LEFT JOIN (SELECT DISTINCT id, string_agg(child, ',' ORDER BY child) AS child_str |
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
case class DbGFolder(id: String, | |
eTag: String, | |
url: String, | |
iconUrl: String, | |
title: String, | |
owner: String, | |
parents: Option[String], | |
children: Option[String], | |
scions: Option[String], | |
created: LocalDateTime, |
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
class DbUserSpec extends FeatureSpec with GivenWhenThen { | |
feature("A prospective user can log into the system and create a new account") { | |
info("As a prospective user") | |
info("I want to be able to create an account") | |
info("So that I can use the MagicNotebook app") | |
scenario("I login for the first time") { | |
Given("I click 'Accept' on the Google OAuth Consent Page") | |
And("I allow the app to have access to my Google Drive and personal info") | |
pending |
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
trait GoogleOAuth extends AuthConstants with CacheConstants { | |
def persistPacket(rUser: Response, rToken: Response)(implicit s: Session): Future[Try[DbUser]] = future { | |
(rUser.json.as[JsObject] ++ rToken.json.as[JsObject]).validate[GoogleOAuthPacket] match { | |
case JsError(errors) => | |
Logger.error(s"failed to validate user, with errors: $errors") | |
Failure(new Throwable("didn't work")) | |
case JsSuccess(packet, _) => | |
Logger.debug(s"successfully parsed user and token: $packet") |
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
import java.io.File | |
import play.api.{Mode, Play, DefaultApplication} | |
import org.scalatest.{SequentialNestedSuiteExecution, BeforeAndAfterAll, Suites} | |
import app.models.DbUserSpec | |
class IntegrationSuites extends Suites(new PlayConfigSpec, new DbUserSpec) with BeforeAndAfterAll | |
with SequentialNestedSuiteExecution with DbSetup { | |
implicit val app: DefaultApplication = | |
new DefaultApplication(new File("."), this.getClass.getClassLoader, None, Mode.Test) |
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
@DoNotDiscover | |
class DbUserTest extends FunSpec with Matchers with EitherValues with DbUserJson { | |
describe("A DbUser") { | |
describe("Should be instantiated from valid json") { | |
validUserJson.validate[DbUser].left.get.email should be("bart@simpsons.com") | |
} | |
} | |
} |
OlderNewer