diff --git a/src/main/scala/app/LabelsController.scala b/src/main/scala/app/LabelsController.scala index 55c4009..a4bd836 100644 --- a/src/main/scala/app/LabelsController.scala +++ b/src/main/scala/app/LabelsController.scala @@ -36,7 +36,10 @@ val owner = params("owner") val repository = params("repository") - issues.html.labellist(getLabels(owner, repository), getRepository(owner, repository, baseUrl).get) + getRepository(owner, repository, baseUrl) match { + case None => NotFound() + case Some(r) => issues.html.labellist(getLabels(owner, repository), r) + } }) get("/:owner/:repository/issues/label/:labelId/edit")(writableRepository { @@ -44,9 +47,12 @@ val repository = params("repository") val labelId = params("labelId").toInt - getLabel(owner, repository, labelId) match { + getRepository(owner, repository, baseUrl) match { case None => NotFound() - case Some(l) => issues.html.labeledit(Some(l), getRepository(owner, repository, baseUrl).get) + case Some(r) => getLabel(owner, repository, labelId) match { + case None => NotFound() + case Some(l) => issues.html.labeledit(Some(l), r) + } } }) @@ -55,9 +61,27 @@ val repository = params("repository") val labelId = params("labelId").toInt -// createLabel(owner, repository, form.labelName, form.color.substring(1)) -// - issues.html.labellist(getLabels(owner, repository), getRepository(owner, repository, baseUrl).get) + getRepository(owner, repository, baseUrl) match { + case None => NotFound() + case Some(r) => { + updateLabel(owner, repository, labelId, form.labelName, form.color.substring(1)) + issues.html.labellist(getLabels(owner, repository), r) + } + } + }) + + get("/:owner/:repository/issues/label/:labelId/delete")(writableRepository { + val owner = params("owner") + val repository = params("repository") + val labelId = params("labelId").toInt + + getRepository(owner, repository, baseUrl) match { + case None => NotFound() + case Some(r) => { + deleteLabel(owner, repository, labelId) + issues.html.labellist(getLabels(owner, repository), r) + } + } }) } \ No newline at end of file diff --git a/src/main/scala/service/LabelsService.scala b/src/main/scala/service/LabelsService.scala index 8391dc6..83151ab 100644 --- a/src/main/scala/service/LabelsService.scala +++ b/src/main/scala/service/LabelsService.scala @@ -24,4 +24,22 @@ def createLabel(owner: String, repository: String, labelName: String, color: String): Unit = Labels.ins insert (owner, repository, labelName, color) + def updateLabel(owner: String, repository: String, labelId: Int, labelName: String, color: String): Unit = + Query(Labels) + .filter { l => (l.userName is owner.bind) && (l.repositoryName is repository.bind) && (l.labelId is labelId.bind)} + .map { l => l.labelName ~ l.color } + .update (labelName, color) + + def deleteLabel(owner: String, repository: String, labelId: Int): Unit = { + // TODO delete ISSUE_LABEL +// Query(Issues) +// .filter { i => (i.userName is owner.bind) && (i.repositoryName is repository.bind) && (i.milestoneId is milestoneId.bind)} +// .map { i => i.milestoneId.? } +// .update(None) + + Query(Labels) + .filter { i => (i.userName is owner.bind) && (i.repositoryName is repository.bind) && (i.labelId is labelId.bind)} + .delete + } + } diff --git a/src/main/twirl/issues/labellist.scala.html b/src/main/twirl/issues/labellist.scala.html index 1043d0c..9a7383f 100644 --- a/src/main/twirl/issues/labellist.scala.html +++ b/src/main/twirl/issues/labellist.scala.html @@ -15,8 +15,15 @@