added get channels
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
-- RedefineTables
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_Channel" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"eventId" TEXT NOT NULL,
|
||||
"content" TEXT NOT NULL,
|
||||
"active" BOOLEAN NOT NULL DEFAULT false,
|
||||
"accountId" INTEGER NOT NULL,
|
||||
CONSTRAINT "Channel_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
INSERT INTO "new_Channel" ("accountId", "content", "eventId", "id") SELECT "accountId", "content", "eventId", "id" FROM "Channel";
|
||||
DROP TABLE "Channel";
|
||||
ALTER TABLE "new_Channel" RENAME TO "Channel";
|
||||
CREATE UNIQUE INDEX "Channel_eventId_key" ON "Channel"("eventId");
|
||||
CREATE INDEX "Channel_eventId_idx" ON "Channel"("eventId");
|
||||
PRAGMA foreign_key_check;
|
||||
PRAGMA foreign_keys=ON;
|
||||
@@ -80,9 +80,10 @@ model Chat {
|
||||
}
|
||||
|
||||
model Channel {
|
||||
id Int @id @default(autoincrement())
|
||||
eventId String @unique
|
||||
id Int @id @default(autoincrement())
|
||||
eventId String @unique
|
||||
content String
|
||||
active Boolean @default(false)
|
||||
|
||||
Account Account @relation(fields: [accountId], references: [id])
|
||||
accountId Int
|
||||
|
||||
@@ -100,6 +100,17 @@ struct CreateChannelData {
|
||||
account_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct GetChannelData {
|
||||
limit: i32,
|
||||
offset: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct GetActiveChannelData {
|
||||
active: bool,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_accounts(db: DbState<'_>) -> Result<Vec<account::Data>, ()> {
|
||||
@@ -253,6 +264,31 @@ async fn create_channel(db: DbState<'_>, data: CreateChannelData) -> Result<chan
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_channels(db: DbState<'_>, data: GetChannelData) -> Result<Vec<channel::Data>, ()> {
|
||||
db.channel()
|
||||
.find_many(vec![])
|
||||
.take(data.limit.into())
|
||||
.skip(data.offset.into())
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_active_channels(
|
||||
db: DbState<'_>,
|
||||
data: GetActiveChannelData,
|
||||
) -> Result<Vec<channel::Data>, ()> {
|
||||
db.channel()
|
||||
.find_many(vec![channel::active::equals(data.active)])
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn create_chat(db: DbState<'_>, data: CreateChatData) -> Result<chat::Data, ()> {
|
||||
@@ -299,6 +335,8 @@ async fn main() {
|
||||
get_latest_notes,
|
||||
get_note_by_id,
|
||||
create_channel,
|
||||
get_channels,
|
||||
get_active_channels,
|
||||
create_chat,
|
||||
get_chats
|
||||
],
|
||||
@@ -344,6 +382,8 @@ async fn main() {
|
||||
get_note_by_id,
|
||||
count_total_notes,
|
||||
create_channel,
|
||||
get_channels,
|
||||
get_active_channels,
|
||||
create_chat,
|
||||
get_chats
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user