From: Olaf Wintermann Date: Tue, 12 Aug 2025 10:59:36 +0000 (+0200) Subject: add feed list from database X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=01a467b75c8b05aab0f35be291ae3756d37a1d59;p=rssreader.git add feed list from database --- diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt index af002fa..410e21d 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -30,6 +30,7 @@ object Database { createStmt.addBatch(""" CREATE TABLE groups ( group_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + pos INT default 0, name VARCHAR ) """.trimIndent()) @@ -38,6 +39,7 @@ object Database { CREATE TABLE feedcollections ( feedcollection_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, group_id INT NOT NULL REFERENCES groups(group_id) ON DELETE CASCADE, + pos INT default 0, name VARCHAR, update_interval INT ) @@ -72,4 +74,39 @@ object Database { println("Database schema already exists.") } } + + public fun getFeedTree() : List { + val groups = mutableListOf() + + connection.createStatement().use { stmt -> + val rs = stmt.executeQuery(""" + select + g.group_id, + g.name as group_name, + f.feedcollection_id, + f.name as feed_name + from groups g + left join feedcollections f on g.group_id = f.group_id + order by g.pos, f.pos + """.trimIndent()) + + var currentGroup: FeedGroup? = null + while(rs.next()) { + val groupId = rs.getInt("group_id") + val groupName = rs.getString("group_name") + val feedId = rs.getInt("feedcollection_id") + val feedName = rs.getString("feed_name") + + if(currentGroup == null || currentGroup.id != groupId) { + currentGroup = FeedGroup(groupId, groupName) + groups.add(currentGroup) + } + + currentGroup.feeds.add(FeedCollection(feedId, feedName)) + } + rs.close() + } + + return groups + } } diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedGroup.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedGroup.kt index dc597f3..7ed6062 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedGroup.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedGroup.kt @@ -3,4 +3,6 @@ package de.unixwork.rssreader class FeedGroup(id: Int, name: String) { val id = id val name: String = name + + val feeds = mutableListOf() } \ No newline at end of file diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt index fb5c2da..10b468c 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt @@ -9,13 +9,16 @@ class FeedSourceList : Document() { init { val db = Database - // testcode - val sublist1 = SubList() - sublist1.header = "Test 1" - val sublist1data = list("sublist1data") - val col1 = FeedCollection("Test Feed") - sublist1data.add(col1) - sublist1.value = sublist1data - feeds.add(sublist1) + val groups = db.getFeedTree() + groups.forEach { + val sublist = SubList() + sublist.header = it.name + val feedlist = list() + it.feeds.forEach { fc -> + feedlist.add(fc) + } + sublist.value = feedlist + feeds.add(sublist) + } } } \ No newline at end of file