mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 13:35:50 +01:00
Create java.util.Date TypeMapper. And add the currentDate method.
This commit is contained in:
@@ -38,11 +38,9 @@ trait AccountControllerBase extends ControllerBase {
|
||||
|
||||
post("/:userName/_edit", form)(ownerOnly { form =>
|
||||
val userName = params("userName")
|
||||
val currentDate = new java.sql.Timestamp(System.currentTimeMillis) // TODO make a common function to get the current timestamp.
|
||||
updateAccount(getAccountByUserName(userName).get.copy(
|
||||
mailAddress = form.mailAddress,
|
||||
url = form.url,
|
||||
updatedDate = currentDate))
|
||||
url = form.url))
|
||||
|
||||
redirect("/%s".format(userName))
|
||||
})
|
||||
|
||||
@@ -50,11 +50,11 @@ abstract class ControllerBase extends ScalatraFilter with ClientSideValidationFo
|
||||
/**
|
||||
* ValueType for the Date property.
|
||||
*/
|
||||
def date(constraints: Constraint*): SingleValueType[java.sql.Date] =
|
||||
new SingleValueType[java.sql.Date]((pattern("\\d{4}-\\d{2}-\\d{2}") +: constraints): _*){
|
||||
def convert(value: String): java.sql.Date = {
|
||||
def date(constraints: Constraint*): SingleValueType[java.util.Date] =
|
||||
new SingleValueType[java.util.Date]((pattern("\\d{4}-\\d{2}-\\d{2}") +: constraints): _*){
|
||||
def convert(value: String): java.util.Date = {
|
||||
val formatter = new java.text.SimpleDateFormat("yyyy-MM-dd")
|
||||
new java.sql.Date(formatter.parse(value).getTime)
|
||||
formatter.parse(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import jp.sf.amateras.scalatra.forms._
|
||||
|
||||
import service._
|
||||
import util.{WritableRepositoryAuthenticator, ReadableRepositoryAuthenticator, UsersOnlyAuthenticator}
|
||||
import java.sql.Timestamp
|
||||
|
||||
class IssuesController extends IssuesControllerBase
|
||||
with IssuesService with RepositoryService with AccountService
|
||||
@@ -16,7 +15,7 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
|
||||
case class IssueForm(title: String, content: Option[String])
|
||||
|
||||
case class MilestoneForm(title: String, description: Option[String], dueDate: Option[java.sql.Date])
|
||||
case class MilestoneForm(title: String, description: Option[String], dueDate: Option[java.util.Date])
|
||||
|
||||
val form = mapping(
|
||||
"title" -> trim(label("Title", text(required))),
|
||||
@@ -128,8 +127,8 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
getMilestone(owner, repository, milestoneId) match {
|
||||
case None => NotFound()
|
||||
case Some(m) => {
|
||||
// TODO make a common function to get the current timestamp.
|
||||
val currentDate = new Timestamp(System.currentTimeMillis)
|
||||
// TODO I want to ban to use the currentDate in Controller.
|
||||
val currentDate = new java.util.Date()
|
||||
updateMilestone(m.copy(closedDate = Some(currentDate)))
|
||||
redirect("/%s/%s/issues/milestones".format(owner, repository))
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ trait UsersControllerBase extends ControllerBase { self: AccountService with Adm
|
||||
})
|
||||
|
||||
post("/admin/users/_new", newForm)(adminOnly { form =>
|
||||
// TODO make a common function to get the current timestamp.
|
||||
val currentDate = new java.sql.Timestamp(System.currentTimeMillis)
|
||||
// TODO I want to ban to use the currentDate in Controller.
|
||||
val currentDate = new java.util.Date()
|
||||
createAccount(Account(
|
||||
userName = form.userName,
|
||||
password = form.password,
|
||||
@@ -58,14 +58,11 @@ trait UsersControllerBase extends ControllerBase { self: AccountService with Adm
|
||||
|
||||
post("/admin/users/:name/_edit", editForm)(adminOnly { form =>
|
||||
val userName = params("userName")
|
||||
// TODO make a common function to get the current timestamp.
|
||||
val currentDate = new java.sql.Timestamp(System.currentTimeMillis)
|
||||
updateAccount(getAccountByUserName(userName).get.copy(
|
||||
password = form.password,
|
||||
mailAddress = form.mailAddress,
|
||||
isAdmin = form.isAdmin,
|
||||
url = form.url,
|
||||
updatedDate = currentDate))
|
||||
url = form.url))
|
||||
|
||||
redirect("/admin/users")
|
||||
})
|
||||
|
||||
@@ -2,15 +2,15 @@ package model
|
||||
|
||||
import scala.slick.driver.H2Driver.simple._
|
||||
|
||||
object Accounts extends Table[Account]("ACCOUNT") {
|
||||
object Accounts extends Table[Account]("ACCOUNT") with Functions {
|
||||
def userName = column[String]("USER_NAME", O PrimaryKey)
|
||||
def mailAddress = column[String]("MAIL_ADDRESS")
|
||||
def password = column[String]("PASSWORD")
|
||||
def isAdmin = column[Boolean]("ADMINISTRATOR")
|
||||
def url = column[String]("URL")
|
||||
def registeredDate = column[java.sql.Timestamp]("REGISTERED_DATE") // TODO convert java.util.Date later
|
||||
def updatedDate = column[java.sql.Timestamp]("UPDATED_DATE")
|
||||
def lastLoginDate = column[java.sql.Timestamp]("LAST_LOGIN_DATE")
|
||||
def registeredDate = column[java.util.Date]("REGISTERED_DATE")
|
||||
def updatedDate = column[java.util.Date]("UPDATED_DATE")
|
||||
def lastLoginDate = column[java.util.Date]("LAST_LOGIN_DATE")
|
||||
def * = userName ~ mailAddress ~ password ~ isAdmin ~ url.? ~ registeredDate ~ updatedDate ~ lastLoginDate.? <> (Account, Account.unapply _)
|
||||
}
|
||||
|
||||
@@ -20,16 +20,7 @@ case class Account(
|
||||
password: String,
|
||||
isAdmin: Boolean,
|
||||
url: Option[String],
|
||||
registeredDate: java.sql.Timestamp,
|
||||
updatedDate: java.sql.Timestamp,
|
||||
lastLoginDate: Option[java.sql.Timestamp]
|
||||
registeredDate: java.util.Date,
|
||||
updatedDate: java.util.Date,
|
||||
lastLoginDate: Option[java.util.Date]
|
||||
)
|
||||
|
||||
class AccountDao {
|
||||
import Database.threadLocalSession
|
||||
|
||||
def insert(o: Account): Long = Accounts insert o
|
||||
|
||||
def select(key: String): Option[Account] = Query(Accounts) filter(_.userName is key.bind) firstOption
|
||||
|
||||
}
|
||||
|
||||
17
src/main/scala/model/Functions.scala
Normal file
17
src/main/scala/model/Functions.scala
Normal file
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
import scala.slick.lifted.MappedTypeMapper
|
||||
|
||||
protected[model] trait Functions {
|
||||
// java.util.Date TypeMapper
|
||||
implicit val dateTypeMapper = MappedTypeMapper.base[java.util.Date, java.sql.Timestamp](
|
||||
d => new java.sql.Timestamp(d.getTime),
|
||||
t => new java.util.Date(t.getTime)
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns system date.
|
||||
*/
|
||||
def currentDate = new java.util.Date()
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ object IssueId extends Table[(String, String, Int)]("ISSUE_ID") {
|
||||
def * = userName ~ repositoryName ~ issueId
|
||||
}
|
||||
|
||||
object Issues extends Table[Issue]("ISSUE") {
|
||||
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)
|
||||
@@ -19,8 +19,8 @@ object Issues extends Table[Issue]("ISSUE") {
|
||||
def title = column[String]("TITLE")
|
||||
def content = column[String]("CONTENT")
|
||||
def closed = column[Boolean]("CLOSED")
|
||||
def registeredDate = column[java.sql.Date]("REGISTERED_DATE") // TODO convert java.util.Date later
|
||||
def updatedDate = column[java.sql.Date]("UPDATED_DATE")
|
||||
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 _)
|
||||
}
|
||||
|
||||
@@ -34,5 +34,5 @@ case class Issue(
|
||||
title: String,
|
||||
content: Option[String],
|
||||
closed: Boolean,
|
||||
registeredDate: java.sql.Date,
|
||||
updatedDate: java.sql.Date)
|
||||
registeredDate: java.util.Date,
|
||||
updatedDate: java.util.Date)
|
||||
@@ -2,17 +2,17 @@ package model
|
||||
|
||||
import scala.slick.driver.H2Driver.simple._
|
||||
|
||||
object Milestones extends Table[Milestone]("MILESTONE") {
|
||||
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)
|
||||
def milestoneId = column[Int]("MILESTONE_ID", O PrimaryKey, O AutoInc)
|
||||
def title = column[String]("TITLE")
|
||||
def description = column[String]("DESCRIPTION")
|
||||
def dueDate = column[java.sql.Date]("DUE_DATE") // TODO convert java.util.Date later
|
||||
def closedDate = column[java.sql.Timestamp]("CLOSED_DATE")
|
||||
|
||||
def ins = userName ~ repositoryName ~ title ~ description.? ~ dueDate.? ~ closedDate.?
|
||||
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 autoInc = userName ~ repositoryName ~ title ~ description.? ~ dueDate.? ~ closedDate.? returning milestoneId
|
||||
}
|
||||
|
||||
case class Milestone(
|
||||
@@ -21,5 +21,5 @@ case class Milestone(
|
||||
milestoneId: Int,
|
||||
title: String,
|
||||
description: Option[String],
|
||||
dueDate: Option[java.sql.Date],
|
||||
closedDate: Option[java.sql.Timestamp])
|
||||
dueDate: Option[java.util.Date],
|
||||
closedDate: Option[java.util.Date])
|
||||
|
||||
@@ -2,15 +2,15 @@ package model
|
||||
|
||||
import scala.slick.driver.H2Driver.simple._
|
||||
|
||||
object Repositories extends Table[Repository]("REPOSITORY") {
|
||||
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.sql.Timestamp]("REGISTERED_DATE") // TODO convert java.util.Date later
|
||||
def updatedDate = column[java.sql.Timestamp]("UPDATED_DATE")
|
||||
def lastActivityDate = column[java.sql.Timestamp]("LAST_ACTIVITY_DATE")
|
||||
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 _)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ case class Repository(
|
||||
isPrivate: Boolean,
|
||||
description: Option[String],
|
||||
defaultBranch: String,
|
||||
registeredDate: java.sql.Timestamp,
|
||||
updatedDate: java.sql.Timestamp,
|
||||
lastActivityDate: java.sql.Timestamp
|
||||
registeredDate: java.util.Date,
|
||||
updatedDate: java.util.Date,
|
||||
lastActivityDate: java.util.Date
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import model._
|
||||
import Accounts._
|
||||
import scala.slick.driver.H2Driver.simple._
|
||||
import Database.threadLocalSession
|
||||
|
||||
@@ -11,7 +12,7 @@ trait AccountService {
|
||||
|
||||
def getAllUsers(): List[Account] = Query(Accounts) sortBy(_.userName) list
|
||||
|
||||
def createAccount(account: Account): Unit = Accounts.* insert account
|
||||
def createAccount(account: Account): Unit = Accounts insert account
|
||||
|
||||
def updateAccount(account: Account): Unit =
|
||||
Query(Accounts)
|
||||
@@ -23,12 +24,11 @@ trait AccountService {
|
||||
account.isAdmin,
|
||||
account.url,
|
||||
account.registeredDate,
|
||||
account.updatedDate,
|
||||
currentDate,
|
||||
account.lastLoginDate)
|
||||
|
||||
def updateLastLoginDate(userName: String): Unit =
|
||||
// TODO make a common function to get the current timestamp.
|
||||
Query(Accounts).filter(_.userName is userName.bind).map(_.lastLoginDate)
|
||||
.update(new java.sql.Timestamp(System.currentTimeMillis))
|
||||
.update(currentDate)
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import scala.slick.jdbc.{StaticQuery => Q}
|
||||
import Q.interpolation
|
||||
|
||||
import model._
|
||||
import Issues._
|
||||
|
||||
trait IssuesService {
|
||||
def getIssue(owner: String, repository: String, issueId: String) =
|
||||
@@ -41,8 +42,8 @@ trait IssuesService {
|
||||
title,
|
||||
content,
|
||||
false,
|
||||
new java.sql.Date(System.currentTimeMillis), // TODO
|
||||
new java.sql.Date(System.currentTimeMillis))
|
||||
currentDate,
|
||||
currentDate)
|
||||
|
||||
// increment issue id
|
||||
IssueId.filter { t =>
|
||||
@@ -51,9 +52,8 @@ trait IssuesService {
|
||||
} get
|
||||
|
||||
def createMilestone(owner: String, repository: String,
|
||||
title: String, description: Option[String], dueDate: Option[java.sql.Date]): Unit = {
|
||||
Milestones.ins insert (owner, repository, title, description, dueDate, None)
|
||||
}
|
||||
title: String, description: Option[String], dueDate: Option[java.util.Date]) =
|
||||
Milestones.autoInc insert (owner, repository, title, description, dueDate, None)
|
||||
|
||||
def updateMilestone(milestone: Milestone): Unit =
|
||||
Query(Milestones)
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package service
|
||||
|
||||
import model._
|
||||
import Repositories._
|
||||
import scala.slick.driver.H2Driver.simple._
|
||||
import Database.threadLocalSession
|
||||
import util.JGitUtil
|
||||
import scala.Some
|
||||
import model.Repository
|
||||
import model.Account
|
||||
import model.Collaborator
|
||||
|
||||
trait RepositoryService { self: AccountService =>
|
||||
import RepositoryService._
|
||||
@@ -27,9 +24,6 @@ trait RepositoryService { self: AccountService =>
|
||||
|
||||
// TODO insert default labels.
|
||||
|
||||
// TODO make a common function to get the current timestamp.
|
||||
val currentDate = new java.sql.Timestamp(System.currentTimeMillis)
|
||||
|
||||
Repositories insert
|
||||
Repository(
|
||||
repositoryName = repositoryName,
|
||||
@@ -160,22 +154,20 @@ trait RepositoryService { self: AccountService =>
|
||||
* Updates the last activity date of the repository.
|
||||
*/
|
||||
def updateLastActivityDate(userName: String, repositoryName: String): Unit =
|
||||
// TODO make a common function to get the current timestamp.
|
||||
Query(Repositories)
|
||||
.filter { r => (r.userName is userName.bind) && (r.repositoryName is repositoryName.bind) }
|
||||
.map { _.lastActivityDate }
|
||||
.update (new java.sql.Timestamp(System.currentTimeMillis))
|
||||
.update (currentDate)
|
||||
|
||||
/**
|
||||
* Save repository options.
|
||||
*/
|
||||
def saveRepositoryOptions(userName: String, repositoryName: String,
|
||||
description: Option[String], defaultBranch: String, isPrivate: Boolean): Unit =
|
||||
// TODO make a common function to get the current timestamp.
|
||||
Query(Repositories)
|
||||
.filter { r => (r.userName is userName.bind) && (r.repositoryName is repositoryName.bind) }
|
||||
.map { r => r.description.? ~ r.defaultBranch ~ r.isPrivate ~ r.updatedDate }
|
||||
.update (description, defaultBranch, isPrivate, new java.sql.Timestamp(System.currentTimeMillis))
|
||||
.update (description, defaultBranch, isPrivate, currentDate)
|
||||
|
||||
/**
|
||||
* Add collaborator to the repository.
|
||||
|
||||
Reference in New Issue
Block a user