Skip to content

Commit dda7675

Browse files
committed
Modify register and update behaviour
1 parent 570dfce commit dda7675

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/main/scala/app/GistController.scala

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ trait GistControllerBase extends ControllerBase {
6565
if(gitdir.exists){
6666
using(Git.open(gitdir)){ git =>
6767
val files: Seq[(String, JGitUtil.ContentInfo)] = JGitUtil.getFileList(git, "master", ".").map { file =>
68-
file.name -> JGitUtil.getContentInfo(git, file.name, file.id)
68+
(if(isGistFile(file.name)) "" else file.name) -> JGitUtil.getContentInfo(git, file.name, file.id)
6969
}
7070
_root_.gist.html.edit(Nil, getGist(userName, repoName), files)
7171
}
@@ -95,7 +95,7 @@ trait GistControllerBase extends ControllerBase {
9595
loginAccount.userName,
9696
repoName,
9797
isPrivate,
98-
files.head._1,
98+
getTitle(files.head._1, repoName),
9999
description
100100
)
101101

@@ -115,12 +115,18 @@ trait GistControllerBase extends ControllerBase {
115115

116116
val loginAccount = context.loginAccount.get
117117
val files = getFileParameters(true)
118-
// TODO Save isPrivate and description
119-
//val isPrivate = params("private")
120118
val description = params("description")
121-
val gitdir = new File(GistRepoDir, userName + "/" + repoName)
119+
120+
// Update database
121+
updateGist(
122+
userName,
123+
repoName,
124+
getTitle(files.head._1, repoName),
125+
description
126+
)
122127

123128
// Commit files
129+
val gitdir = new File(GistRepoDir, userName + "/" + repoName)
124130
using(Git.open(gitdir)){ git =>
125131
val commitId = commitFiles(git, loginAccount, "Update", files)
126132

@@ -318,4 +324,8 @@ trait GistControllerBase extends ControllerBase {
318324
commitId
319325
}
320326

327+
private def isGistFile(fileName: String): Boolean = fileName.matches("gistfile[0-9]+\\.txt")
328+
329+
private def getTitle(fileName: String, repoName: String): String = if(isGistFile(fileName)) repoName else fileName
330+
321331
}

src/main/scala/service/GistService.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ trait GistService {
3636
def registerGist(userName: String, repositoryName: String, isPrivate: Boolean, title: String, description: String)(implicit s: Session): Unit =
3737
Gists.insert(Gist(userName, repositoryName, isPrivate, title, description, new java.util.Date(), new java.util.Date()))
3838

39-
def updateGist(userName: String, repositoryName: String, isPrivate: Boolean, title: String, description: String)(implicit s: Session): Unit =
39+
def updateGist(userName: String, repositoryName: String, title: String, description: String)(implicit s: Session): Unit =
4040
Gists
4141
.filter(t => (t.userName === userName.bind) && (t.repositoryName === repositoryName.bind))
4242
.map(t => (t.title, t.description, t.updatedDate))

0 commit comments

Comments
 (0)