mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
Refactor database schema.
This commit is contained in:
@@ -6,10 +6,6 @@ import Database.threadLocalSession
|
||||
|
||||
trait AccountService {
|
||||
|
||||
def getAccountByUserId(userId: Long): Option[Account] =
|
||||
Query(Accounts) filter(_.userId is userId.bind) firstOption
|
||||
|
||||
|
||||
def getAccountByUserName(userName: String): Option[Account] =
|
||||
Query(Accounts) filter(_.userName is userName.bind) firstOption
|
||||
|
||||
|
||||
@@ -15,22 +15,21 @@ trait ProjectService { self: AccountService =>
|
||||
* The project is created as public repository at first. Users can modify the project type at the repository settings
|
||||
* page after the project creation to configure the project as the private repository.
|
||||
*
|
||||
* @param projectName the project name
|
||||
* @param repositoryName the repository name
|
||||
* @param userName the user name of the project owner
|
||||
* @param description the project description
|
||||
* @return the created project id
|
||||
*/
|
||||
def createProject(projectName: String, userName: String, description: Option[String]): Long = {
|
||||
def createProject(repositoryName: String, userName: String, description: Option[String]): Long = {
|
||||
// TODO create a git repository also here?
|
||||
|
||||
val currentDate = new java.sql.Date(System.currentTimeMillis)
|
||||
|
||||
Projects.ins returning Projects.projectId insert
|
||||
Project(
|
||||
projectId = None,
|
||||
projectName = projectName,
|
||||
userId = getUserId(userName),
|
||||
projectType = Public,
|
||||
Repositories.* insert
|
||||
Repository(
|
||||
repositoryName = repositoryName,
|
||||
userName = userName,
|
||||
repositoryType = Public,
|
||||
description = description,
|
||||
defaultBranch = "master",
|
||||
registeredDate = currentDate,
|
||||
@@ -39,49 +38,72 @@ trait ProjectService { self: AccountService =>
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified user's project list.
|
||||
* Returns the specified user's repository informations.
|
||||
*
|
||||
* @param userName the user name
|
||||
* @return the project list which is sorted in descending order of lastActivityDate.
|
||||
* @param servletContext the servlet context
|
||||
* @return the repository informations which is sorted in descending order of lastActivityDate.
|
||||
*/
|
||||
def getRepositoriesOfUser(userName: String, servletContext: ServletContext): List[RepositoryInfo] = {
|
||||
(Query(Projects) filter(_.userId is getUserId(userName).bind) sortBy(_.lastActivityDate desc) list) map { project =>
|
||||
val repositoryInfo = JGitUtil.getRepositoryInfo(userName, project.projectName, servletContext)
|
||||
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, project, repositoryInfo.branchList, repositoryInfo.tags)
|
||||
(Query(Repositories) filter(_.userName is userName.bind) sortBy(_.lastActivityDate desc) list) map { repository =>
|
||||
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext)
|
||||
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags)
|
||||
}
|
||||
}
|
||||
|
||||
def getRepository(userName: String, projectName: String, servletContext: ServletContext): Option[RepositoryInfo] = {
|
||||
(Query(Projects) filter { project =>
|
||||
(project.userId is getUserId(userName).bind) && (project.projectName is projectName.bind)
|
||||
} firstOption) map { project =>
|
||||
val repositoryInfo = JGitUtil.getRepositoryInfo(userName, project.projectName, servletContext)
|
||||
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, project, repositoryInfo.branchList, repositoryInfo.tags)
|
||||
/**
|
||||
* Returns the specified repository information.
|
||||
*
|
||||
* @param userName the user name
|
||||
* @param repositoryName the repository name
|
||||
* @param servletContext the servlet context
|
||||
* @return the repository information
|
||||
*/
|
||||
def getRepository(userName: String, repositoryName: String, servletContext: ServletContext): Option[RepositoryInfo] = {
|
||||
(Query(Repositories) filter { repository =>
|
||||
(repository.userName is userName.bind) && (repository.repositoryName is repositoryName.bind)
|
||||
} firstOption) map { repository =>
|
||||
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext)
|
||||
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the accessible repository informations for the specified account user.
|
||||
*
|
||||
* @param account the account
|
||||
* @param servletContext the servlet context
|
||||
* @return the repository informations which is sorted in descending order of lastActivityDate.
|
||||
*/
|
||||
def getAccessibleRepositories(account: Option[Account], servletContext: ServletContext): List[RepositoryInfo] = {
|
||||
account match {
|
||||
case Some(x) => {
|
||||
(Query(Projects) sortBy(_.lastActivityDate desc) list) map { project =>
|
||||
(Query(Repositories) sortBy(_.lastActivityDate desc) list) map { repository =>
|
||||
// TODO ユーザ名はジョインして取得する?
|
||||
val repositoryInfo = JGitUtil.getRepositoryInfo(getUserName(project.userId), project.projectName, servletContext)
|
||||
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, project, repositoryInfo.branchList, repositoryInfo.tags)
|
||||
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext)
|
||||
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags)
|
||||
}
|
||||
}
|
||||
case None => {
|
||||
(Query(Projects) filter(_.projectType is Public.bind) sortBy(_.lastActivityDate desc) list) map { project =>
|
||||
(Query(Repositories) filter(_.repositoryType is Public.bind) sortBy(_.lastActivityDate desc) list) map { repository =>
|
||||
// TODO ユーザ名はジョインして取得する?
|
||||
val repositoryInfo = JGitUtil.getRepositoryInfo(getUserName(project.userId), project.projectName, servletContext)
|
||||
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, project, repositoryInfo.branchList, repositoryInfo.tags)
|
||||
val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, servletContext)
|
||||
RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the last activity date of the project.
|
||||
*/
|
||||
def updateLastActivityDate(userName: String, projectName: String): Unit = {
|
||||
|
||||
}
|
||||
|
||||
private def getUserName(userId: Long): String = getAccountByUserId(userId).get.userName
|
||||
|
||||
private def getUserId(userName: String): Long = getAccountByUserName(userName).get.userId.get
|
||||
// private def getUserName(userId: Long): String = getAccountByUserId(userId).get.userName
|
||||
//
|
||||
// private def getUserId(userName: String): Long = getAccountByUserName(userName).get.userId.get
|
||||
|
||||
}
|
||||
|
||||
@@ -90,5 +112,5 @@ object ProjectService {
|
||||
val Public = 0
|
||||
val Private = 1
|
||||
|
||||
case class RepositoryInfo(owner: String, name: String, url: String, project: Project, branchList: List[String], tags: List[util.JGitUtil.TagInfo])
|
||||
case class RepositoryInfo(owner: String, name: String, url: String, repository: Repository, branchList: List[String], tags: List[util.JGitUtil.TagInfo])
|
||||
}
|
||||
Reference in New Issue
Block a user