diff --git a/src/main/scala/model/BaseTable.scala b/src/main/scala/model/BaseTable.scala new file mode 100644 index 0000000..ebe986d --- /dev/null +++ b/src/main/scala/model/BaseTable.scala @@ -0,0 +1,15 @@ +package model + +import scala.slick.driver.H2Driver.simple._ + +protected[model] abstract class BaseTable[T](_tableName: String) extends Table[T](_tableName) { + def userName = column[String]("USER_NAME") + def repositoryName = column[String]("REPOSITORY_NAME") + def base = userName ~ repositoryName + + def repository(owner: String, repository: String) = + (userName is owner.bind) && (repositoryName is repository.bind) + + def repository(other: BaseTable[T]) = + (userName is other.userName) && (repositoryName is other.repositoryName) +} diff --git a/src/main/scala/model/Collaborator.scala b/src/main/scala/model/Collaborator.scala index 9d0d3b9..644e775 100644 --- a/src/main/scala/model/Collaborator.scala +++ b/src/main/scala/model/Collaborator.scala @@ -1,12 +1,11 @@ package model import scala.slick.driver.H2Driver.simple._ +import model.{BaseTable => Table} object Collaborators extends Table[Collaborator]("COLLABORATOR") { - def userName = column[String]("USER_NAME", O PrimaryKey) - def repositoryName = column[String]("REPOSITORY_NAME") def collaboratorName = column[String]("COLLABORATOR_NAME") - def * = userName ~ repositoryName ~ collaboratorName <> (Collaborator, Collaborator.unapply _) + def * = base ~ collaboratorName <> (Collaborator, Collaborator.unapply _) } case class Collaborator( diff --git a/src/main/scala/model/Issue.scala b/src/main/scala/model/Issue.scala index 7c48cbe..5de5312 100644 --- a/src/main/scala/model/Issue.scala +++ b/src/main/scala/model/Issue.scala @@ -1,18 +1,15 @@ package model import scala.slick.driver.H2Driver.simple._ +import model.{BaseTable => Table} object IssueId extends Table[(String, String, Int)]("ISSUE_ID") { - def userName = column[String]("USER_NAME", O PrimaryKey) - def repositoryName = column[String]("REPOSITORY_NAME", O PrimaryKey) def issueId = column[Int]("ISSUE_ID") - def * = userName ~ repositoryName ~ issueId + def * = base ~ issueId } object Issues extends Table[Issue]("ISSUE") with Functions { - def userName = column[String]("USER_NAME", O PrimaryKey) - def repositoryName = column[String]("REPOSITORY_NAME", O PrimaryKey) - def issueId = column[Int]("ISSUE_ID", O PrimaryKey) + def issueId = column[Int]("ISSUE_ID") def openedUserName = column[String]("OPENED_USER_NAME") def milestoneId = column[Int]("MILESTONE_ID") def assignedUserName = column[String]("ASSIGNED_USER_NAME") @@ -21,7 +18,7 @@ def closed = column[Boolean]("CLOSED") def registeredDate = column[java.util.Date]("REGISTERED_DATE") def updatedDate = column[java.util.Date]("UPDATED_DATE") - def * = userName ~ repositoryName ~ issueId ~ openedUserName ~ milestoneId.? ~ assignedUserName.? ~ title ~ content.? ~ closed ~ registeredDate ~ updatedDate <> (Issue, Issue.unapply _) + def * = base ~ issueId ~ openedUserName ~ milestoneId.? ~ assignedUserName.? ~ title ~ content.? ~ closed ~ registeredDate ~ updatedDate <> (Issue, Issue.unapply _) } case class Issue( diff --git a/src/main/scala/model/IssueComment.scala b/src/main/scala/model/IssueComment.scala index a8fd761..a3c5c50 100644 --- a/src/main/scala/model/IssueComment.scala +++ b/src/main/scala/model/IssueComment.scala @@ -1,19 +1,18 @@ package model import scala.slick.driver.H2Driver.simple._ +import model.{BaseTable => Table} object IssueComments extends Table[IssueComment]("ISSUE_COMMENT") with Functions { - def userName = column[String]("USER_NAME") - def repositoryName = column[String]("REPOSITORY_NAME") def issueId = column[Int]("ISSUE_ID") - def commentId = column[Int]("COMMENT_ID", O PrimaryKey, O AutoInc) + def commentId = column[Int]("COMMENT_ID", O AutoInc) def commentedUserName = column[String]("COMMENTED_USER_NAME") def content = column[String]("CONTENT") def registeredDate = column[java.util.Date]("REGISTERED_DATE") def updatedDate = column[java.util.Date]("UPDATED_DATE") - def * = userName ~ repositoryName ~ issueId ~ commentId ~ commentedUserName ~ content ~ registeredDate ~ updatedDate <> (IssueComment, IssueComment.unapply _) + def * = base ~ issueId ~ commentId ~ commentedUserName ~ content ~ registeredDate ~ updatedDate <> (IssueComment, IssueComment.unapply _) - def autoInc = userName ~ repositoryName ~ issueId ~ commentedUserName ~ content ~ registeredDate ~ updatedDate returning commentId + def autoInc = base ~ issueId ~ commentedUserName ~ content ~ registeredDate ~ updatedDate returning commentId } case class IssueComment( diff --git a/src/main/scala/model/IssueLabels.scala b/src/main/scala/model/IssueLabels.scala index a0e87a6..db27dda 100644 --- a/src/main/scala/model/IssueLabels.scala +++ b/src/main/scala/model/IssueLabels.scala @@ -1,13 +1,12 @@ package model import scala.slick.driver.H2Driver.simple._ +import model.{BaseTable => Table} -object IssueLabels extends Table[IssueLabel]("ISSUE_LABEL") with Functions { - def userName = column[String]("USER_NAME", O PrimaryKey) - def repositoryName = column[String]("REPOSITORY_NAME", O PrimaryKey) - def issueId = column[Int]("ISSUE_ID", O PrimaryKey) - def labelId = column[Int]("LABEL_ID", O PrimaryKey) - def * = userName ~ repositoryName ~ issueId ~ labelId <> (IssueLabel, IssueLabel.unapply _) +object IssueLabels extends Table[IssueLabel]("ISSUE_LABEL") { + def issueId = column[Int]("ISSUE_ID") + def labelId = column[Int]("LABEL_ID") + def * = base ~ issueId ~ labelId <> (IssueLabel, IssueLabel.unapply _) } case class IssueLabel( diff --git a/src/main/scala/model/Labels.scala b/src/main/scala/model/Labels.scala index 162e4a3..e5b66f2 100644 --- a/src/main/scala/model/Labels.scala +++ b/src/main/scala/model/Labels.scala @@ -1,15 +1,14 @@ package model import scala.slick.driver.H2Driver.simple._ +import model.{BaseTable => Table} -object Labels extends Table[Label]("LABEL") with Functions { - def userName = column[String]("USER_NAME", O PrimaryKey) - def repositoryName = column[String]("REPOSITORY_NAME", O PrimaryKey) - def labelId = column[Int]("LABEL_ID", O PrimaryKey, O AutoInc) +object Labels extends Table[Label]("LABEL") { + def labelId = column[Int]("LABEL_ID", O AutoInc) def labelName = column[String]("LABEL_NAME") def color = column[String]("COLOR") - def * = userName ~ repositoryName ~ labelId ~ labelName ~ color <> (Label, Label.unapply _) - def ins = userName ~ repositoryName ~ labelName ~ color + def * = base ~ labelId ~ labelName ~ color <> (Label, Label.unapply _) + def ins = base ~ labelName ~ color } case class Label( diff --git a/src/main/scala/model/Milestone.scala b/src/main/scala/model/Milestone.scala index ed492a8..048dbba 100644 --- a/src/main/scala/model/Milestone.scala +++ b/src/main/scala/model/Milestone.scala @@ -1,18 +1,17 @@ package model import scala.slick.driver.H2Driver.simple._ +import model.{BaseTable => Table} object Milestones extends Table[Milestone]("MILESTONE") with Functions { - def userName = column[String]("USER_NAME", O PrimaryKey) - def repositoryName = column[String]("REPOSITORY_NAME", O PrimaryKey) - def milestoneId = column[Int]("MILESTONE_ID", O PrimaryKey, O AutoInc) + def milestoneId = column[Int]("MILESTONE_ID", O AutoInc) def title = column[String]("TITLE") def description = column[String]("DESCRIPTION") def dueDate = column[java.util.Date]("DUE_DATE") def closedDate = column[java.util.Date]("CLOSED_DATE") - def * = userName ~ repositoryName ~ milestoneId ~ title ~ description.? ~ dueDate.? ~ closedDate.? <> (Milestone, Milestone.unapply _) + def * = base ~ milestoneId ~ title ~ description.? ~ dueDate.? ~ closedDate.? <> (Milestone, Milestone.unapply _) - def autoInc = userName ~ repositoryName ~ title ~ description.? ~ dueDate.? ~ closedDate.? returning milestoneId + def autoInc = base ~ title ~ description.? ~ dueDate.? ~ closedDate.? returning milestoneId } case class Milestone( diff --git a/src/main/scala/model/Repository.scala b/src/main/scala/model/Repository.scala index 8c92ed4..3408ca8 100644 --- a/src/main/scala/model/Repository.scala +++ b/src/main/scala/model/Repository.scala @@ -1,22 +1,21 @@ package model import scala.slick.driver.H2Driver.simple._ +import model.{BaseTable => Table} object Repositories extends Table[Repository]("REPOSITORY") with Functions { - def repositoryName= column[String]("REPOSITORY_NAME", O PrimaryKey) - def userName = column[String]("USER_NAME", O PrimaryKey) def isPrivate = column[Boolean]("PRIVATE") def description = column[String]("DESCRIPTION") def defaultBranch = column[String]("DEFAULT_BRANCH") def registeredDate = column[java.util.Date]("REGISTERED_DATE") def updatedDate = column[java.util.Date]("UPDATED_DATE") def lastActivityDate = column[java.util.Date]("LAST_ACTIVITY_DATE") - def * = repositoryName ~ userName ~ isPrivate ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> (Repository, Repository.unapply _) + def * = base ~ isPrivate ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> (Repository, Repository.unapply _) } case class Repository( - repositoryName: String, userName: String, + repositoryName: String, isPrivate: Boolean, description: Option[String], defaultBranch: String, diff --git a/src/main/scala/service/RepositoryService.scala b/src/main/scala/service/RepositoryService.scala index 57520ba..2a2a9c4 100644 --- a/src/main/scala/service/RepositoryService.scala +++ b/src/main/scala/service/RepositoryService.scala @@ -26,8 +26,8 @@ Repositories insert Repository( - repositoryName = repositoryName, userName = userName, + repositoryName = repositoryName, isPrivate = false, description = description, defaultBranch = "master",