diff --git a/src/main/scala/app/IssuesController.scala b/src/main/scala/app/IssuesController.scala index 6aed5fb..1923d3f 100644 --- a/src/main/scala/app/IssuesController.scala +++ b/src/main/scala/app/IssuesController.scala @@ -15,11 +15,16 @@ with UsersOnlyAuthenticator => case class IssueForm(title: String, content: Option[String]) + case class CommentForm(issueId: Int, content: String) val form = mapping( "title" -> trim(label("Title", text(required))), "content" -> trim(optional(text())) )(IssueForm.apply) + val commentForm = mapping( + "issueId" -> label("Issue Id", number()), + "content" -> trim(label("Comment", text(required))) + )(CommentForm.apply) get("/:owner/:repository/issues"){ val owner = params("owner") @@ -72,21 +77,12 @@ }) // TODO requires users only and redable repository checking - post("/:owner/:repository/issue_comments")( usersOnly { + post("/:owner/:repository/issue_comments", commentForm)( usersOnly { form => val owner = params("owner") val repository = params("repository") - val issueId = params("issueId").toInt - val content = params("content") // TODO input check - contentType = formats("json") - saveComment(owner, repository, context.loginAccount.get.userName, issueId, content) map { - model => org.json4s.jackson.Serialization.write( - Map("commentedUserName" -> model.commentedUserName, - "registeredDate" -> view.helpers.datetime(model.registeredDate), - "content" -> view.Markdown.toHtml( - model.content, getRepository(owner, repository, baseUrl).get, false, true, true) - )) - } getOrElse "" + redirect("/%s/%s/issues/%d#comment-%d".format(owner, repository, form.issueId, + saveComment(owner, repository, context.loginAccount.get.userName, form.issueId, form.content))) }) -} \ No newline at end of file +} diff --git a/src/main/scala/service/IssuesService.scala b/src/main/scala/service/IssuesService.scala index df40009..8ef8fea 100644 --- a/src/main/scala/service/IssuesService.scala +++ b/src/main/scala/service/IssuesService.scala @@ -60,16 +60,14 @@ def saveComment(owner: String, repository: String, loginUser: String, issueId: Int, content: String) = - Query(IssueComments) filter { - _.commentId is ( IssueComments.autoInc insert ( - owner, - repository, - issueId, - loginUser, - content, - currentDate, - currentDate) ).bind - } firstOption + IssueComments.autoInc insert ( + owner, + repository, + issueId, + loginUser, + content, + currentDate, + currentDate) } @@ -109,4 +107,4 @@ param(request, "sort"), param(request, "direction")) } -} \ No newline at end of file +} diff --git a/src/main/twirl/issues/issue.scala.html b/src/main/twirl/issues/issue.scala.html index 417b4d3..bfb64ae 100644 --- a/src/main/twirl/issues/issue.scala.html +++ b/src/main/twirl/issues/issue.scala.html @@ -19,25 +19,26 @@ @markdown(issue.content getOrElse "No description given.", repository, false, true, true) - @comments.map { comment => -
-
- @comment.commentedUserName commented - @datetime(comment.registeredDate) -
-
- @markdown(comment.content, repository, false, true, true) -
+
+
+ @comment.commentedUserName commented + @datetime(comment.registeredDate)
+
+ @markdown(comment.content, repository, false, true, true) +
+
} - +
@html.preview(repository, "", false, true, true, "width: 730px; height: 100px;")
- + + +
@if(issue.closed) { @@ -50,25 +51,4 @@ Labels
-} - \ No newline at end of file +} \ No newline at end of file