diff --git a/src/main/scala/app/IssuesController.scala b/src/main/scala/app/IssuesController.scala
index 321d1c4..bd28999 100644
--- a/src/main/scala/app/IssuesController.scala
+++ b/src/main/scala/app/IssuesController.scala
@@ -62,17 +62,25 @@
val repository = params("repository")
redirect("/%s/%s/issues/%d".format(owner, repository,
- saveIssue(owner, repository, context.loginAccount.get.userName, form.title, form.content)))
+ createIssue(owner, repository, context.loginAccount.get.userName, form.title, form.content)))
})
- // TODO Authenticator
+ // TODO Authenticator, Validation
post("/:owner/:repository/issues/:id"){
- // TODO update issue
+ val owner = params("owner")
+ val repository = params("repository")
+ val issueId = params("id").toInt
+ val title = params("title")
+ val content = params.get("content")
+
+ updateIssue(owner, repository, issueId, title, content)
+
contentType = formats("json")
- org.json4s.jackson.Serialization.write(Map(
- "title" -> "test title 2",
- "content" -> view.Markdown.toHtml("* hoge", getRepository("root", "test", baseUrl).get, false, true, true)))
+ org.json4s.jackson.Serialization.write(
+ Map("title" -> title,
+ "content" -> view.Markdown.toHtml(content getOrElse "No description given.",
+ getRepository(owner, repository, baseUrl).get, false, true, true)))
}
// TODO requires users only and readable repository checking
@@ -81,16 +89,21 @@
val repository = params("repository")
redirect("/%s/%s/issues/%d#comment-%d".format(owner, repository, form.issueId,
- saveComment(owner, repository, context.loginAccount.get.userName, form.issueId, form.content)))
+ createComment(owner, repository, context.loginAccount.get.userName, form.issueId, form.content)))
})
- // TODO Authenticator
+ // TODO Authenticator, Validation
post("/:owner/:repository/issue_comments/:id"){
- // TODO update issue memo
+ val commentId = params("id").toInt
+ val content = params("content")
+
+ updateComment(commentId, content)
+
contentType = formats("json")
- org.json4s.jackson.Serialization.write(Map(
- "content" -> view.Markdown.toHtml("* hoge memo", getRepository("root", "test", baseUrl).get, false, true, true)))
+ org.json4s.jackson.Serialization.write(
+ Map("content" -> view.Markdown.toHtml(content,
+ getRepository(params("owner"), params("repository"), baseUrl).get, false, true, true)))
}
// TODO Authenticator
diff --git a/src/main/scala/service/IssuesService.scala b/src/main/scala/service/IssuesService.scala
index c9a3c81..fd3f496 100644
--- a/src/main/scala/service/IssuesService.scala
+++ b/src/main/scala/service/IssuesService.scala
@@ -167,7 +167,7 @@
} exists, condition.labels.nonEmpty)
}
- def saveIssue(owner: String, repository: String, loginUser: String,
+ def createIssue(owner: String, repository: String, loginUser: String,
title: String, content: Option[String]) =
// next id number
sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int]
@@ -191,7 +191,7 @@
}.map(_.issueId).update(id) > 0
} get
- def saveComment(owner: String, repository: String, loginUser: String,
+ def createComment(owner: String, repository: String, loginUser: String,
issueId: Int, content: String) =
IssueComments.autoInc insert (
owner,
@@ -202,6 +202,23 @@
currentDate,
currentDate)
+ def updateIssue(owner: String, repository: String, issueId: Int,
+ title: String, content: Option[String]) =
+ Issues filter { t =>
+ (t.userName is owner.bind) &&
+ (t.repositoryName is repository.bind) &&
+ (t.issueId is issueId.bind)
+ } map { t =>
+ t.title ~ t.content.? ~ t.updatedDate
+ } update (title, content, currentDate)
+
+ def updateComment(commentId: Int, content: String) =
+ IssueComments filter {
+ _.commentId is commentId.bind
+ } map { t =>
+ t.content ~ t.updatedDate
+ } update (content, currentDate)
+
}
object IssuesService {
diff --git a/src/main/twirl/issues/edit.scala.html b/src/main/twirl/issues/edit.scala.html
index edca5b1..82d8a65 100644
--- a/src/main/twirl/issues/edit.scala.html
+++ b/src/main/twirl/issues/edit.scala.html
@@ -4,7 +4,7 @@
@if(!isComment){
}
-
+
Cancel