diff -r c357c4e69b9e -r aa22103809cd src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt --- a/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt Fri Dec 30 13:21:09 2022 +0100 +++ b/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt Fri Dec 30 19:04:34 2022 +0100 @@ -534,10 +534,15 @@ return i } + override fun listIssues(project: Project): List = + withStatement("$issueQuery where i.project = ?") { + setInt(1, project.id) + queryAll { it.extractIssue() } + } + override fun listIssues(project: Project, version: Version?, component: Component?): List = withStatement( - """$issueQuery where - (not ? or i.project = ?) and + """$issueQuery where i.project = ? and (not ? or ? in (resolved, affected)) and (not ? or (resolved is null and affected is null)) and (not ? or component = ?) and (not ? or component is null) """.trimIndent() @@ -553,10 +558,9 @@ setInt(idcol, search.id) } } - setBoolean(1, true) - setInt(2, project.id) - applyFilter(version, 3, 5, 4) - applyFilter(component, 6, 8, 7) + setInt(1, project.id) + applyFilter(version, 2, 4, 3) + applyFilter(component, 5, 7, 6) queryAll { it.extractIssue() } } @@ -629,6 +633,53 @@ // + // + override fun insertIssueRelation(rel: IssueRelation) { + withStatement( + """ + insert into lpit_issue_relation (from_issue, to_issue, type) + values (?, ?, ?::relation_type) + on conflict do nothing + """.trimIndent() + ) { + if (rel.reverse) { + setInt(2, rel.from.id) + setInt(1, rel.to.id) + } else { + setInt(1, rel.from.id) + setInt(2, rel.to.id) + } + setEnum(3, rel.type) + executeUpdate() + } + } + + override fun deleteIssueRelation(rel: IssueRelation) { + withStatement("delete from lpit_issue_relation where from_issue = ? and to_issue = ? and type=?::relation_type") { + if (rel.reverse) { + setInt(2, rel.from.id) + setInt(1, rel.to.id) + } else { + setInt(1, rel.from.id) + setInt(2, rel.to.id) + } + setEnum(3, rel.type) + executeUpdate() + } + } + + override fun listIssueRelations(issue: Issue): List = buildList { + withStatement("select to_issue, type from lpit_issue_relation where from_issue = ?") { + setInt(1, issue.id) + queryAll { IssueRelation(issue, findIssue(it.getInt("to_issue"))!!, it.getEnum("type"), false) } + }.forEach(this::add) + withStatement("select from_issue, type from lpit_issue_relation where to_issue = ?") { + setInt(1, issue.id) + queryAll { IssueRelation(issue, findIssue(it.getInt("from_issue"))!!, it.getEnum("type"), true) } + }.forEach(this::add) + } + // + // private fun ResultSet.extractIssueComment() =