From cda8e51d4b404e55490c82fe149f44e543ad6fe1 Mon Sep 17 00:00:00 2001 From: Wei Zhang Date: Wed, 11 Dec 2024 11:56:35 +0800 Subject: [PATCH] feat(graphQL): add notifications api Signed-off-by: Wei Zhang --- ee/tabby-schema/graphql/schema.graphql | 10 ++++ ee/tabby-schema/src/schema/mod.rs | 61 ++++++++++++++++++++++ ee/tabby-schema/src/schema/notification.rs | 12 ++++- 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/ee/tabby-schema/graphql/schema.graphql b/ee/tabby-schema/graphql/schema.graphql index 67c1b82377d1..9c09e84cc936 100644 --- a/ee/tabby-schema/graphql/schema.graphql +++ b/ee/tabby-schema/graphql/schema.graphql @@ -576,6 +576,7 @@ type Mutation { refreshToken(refreshToken: String!): RefreshTokenResponse! createInvitation(email: String!): ID! sendTestEmail(to: String!): Boolean! + markNotificationsReaded(notificationIds: [ID!]!): Boolean! createGitRepository(name: String!, gitUrl: String!): ID! deleteGitRepository(id: ID!): Boolean! updateGitRepository(id: ID!, name: String!, gitUrl: String!): Boolean! @@ -615,6 +616,14 @@ type NetworkSetting { externalUrl: String! } +type Notification { + id: ID! + content: String! + read: Boolean! + createdAt: DateTime! + updatedAt: DateTime! +} + type OAuthCredential { provider: OAuthProvider! clientId: String! @@ -713,6 +722,7 @@ type Query { dailyStatsInPastYear(users: [ID!]): [CompletionStats!]! dailyStats(start: DateTime!, end: DateTime!, users: [ID!], languages: [Language!]): [CompletionStats!]! userEvents(after: String, before: String, first: Int, last: Int, users: [ID!], start: DateTime!, end: DateTime!): UserEventConnection! + notifications(readed: Boolean): [Notification!]! diskUsageStats: DiskUsageStats! repositoryList: [Repository!]! contextInfo: ContextInfo! diff --git a/ee/tabby-schema/src/schema/mod.rs b/ee/tabby-schema/src/schema/mod.rs index e85b2e0a4cd8..4c59508e1980 100644 --- a/ee/tabby-schema/src/schema/mod.rs +++ b/ee/tabby-schema/src/schema/mod.rs @@ -528,6 +528,63 @@ impl Query { .await } + async fn notifications( + ctx: &Context, + readed: Option, + ) -> Result> { + let user = check_user(ctx).await?; + match readed { + Some(true) => Ok(vec![ + notification::Notification { + id: "1".to_string().into(), + content: "Hello".into(), + read: true, + created_at: Utc::now(), + updated_at: Utc::now(), + }, + notification::Notification { + id: "3".to_string().into(), + content: "Tabby".into(), + read: true, + created_at: Utc::now(), + updated_at: Utc::now(), + }, + ]), + Some(false) => Ok(vec![ + notification::Notification { + id: "2".to_string().into(), + content: "World".into(), + read: false, + created_at: Utc::now(), + updated_at: Utc::now(), + }, + notification::Notification { + id: "4".to_string().into(), + content: "Assistant".into(), + read: false, + created_at: Utc::now(), + updated_at: Utc::now(), + }, + ]), + None => Ok(vec![ + notification::Notification { + id: "5".to_string().into(), + content: "World".into(), + read: false, + created_at: Utc::now(), + updated_at: Utc::now(), + }, + notification::Notification { + id: "6".to_string().into(), + content: "Assistant".into(), + read: true, + created_at: Utc::now(), + updated_at: Utc::now(), + }, + ]), + } + } + async fn disk_usage_stats(ctx: &Context) -> Result { check_admin(ctx).await?; ctx.locator.analytic().disk_usage_stats().await @@ -989,6 +1046,10 @@ impl Mutation { Ok(true) } + async fn mark_notifications_readed(ctx: &Context, notification_ids: Vec) -> Result { + Ok(true) + } + async fn create_git_repository(ctx: &Context, name: String, git_url: String) -> Result { check_admin(ctx).await?; let input = repository::CreateGitRepositoryInput { name, git_url }; diff --git a/ee/tabby-schema/src/schema/notification.rs b/ee/tabby-schema/src/schema/notification.rs index a72e3e243173..78cddc443ffc 100644 --- a/ee/tabby-schema/src/schema/notification.rs +++ b/ee/tabby-schema/src/schema/notification.rs @@ -1,7 +1,17 @@ -use juniper::GraphQLEnum; +use chrono::{DateTime, Utc}; +use juniper::{GraphQLEnum, GraphQLObject, ID}; #[derive(GraphQLEnum, Clone, Debug)] pub enum NotificationRecipient { Admin, AllUser, } + +#[derive(GraphQLObject)] +pub struct Notification { + pub id: ID, + pub content: String, + pub read: bool, + pub created_at: DateTime, + pub updated_at: DateTime, +}