Skip to content

Commit

Permalink
feat(graphQL): add notifications api
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <[email protected]>
  • Loading branch information
zwpaper committed Dec 12, 2024
1 parent c749141 commit cda8e51
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ee/tabby-schema/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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!
Expand Down
61 changes: 61 additions & 0 deletions ee/tabby-schema/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,63 @@ impl Query {
.await
}

async fn notifications(
ctx: &Context,
readed: Option<bool>,
) -> Result<Vec<notification::Notification>> {
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<DiskUsageStats> {
check_admin(ctx).await?;
ctx.locator.analytic().disk_usage_stats().await
Expand Down Expand Up @@ -989,6 +1046,10 @@ impl Mutation {
Ok(true)
}

async fn mark_notifications_readed(ctx: &Context, notification_ids: Vec<ID>) -> Result<bool> {
Ok(true)
}

async fn create_git_repository(ctx: &Context, name: String, git_url: String) -> Result<ID> {
check_admin(ctx).await?;
let input = repository::CreateGitRepositoryInput { name, git_url };
Expand Down
12 changes: 11 additions & 1 deletion ee/tabby-schema/src/schema/notification.rs
Original file line number Diff line number Diff line change
@@ -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<Utc>,
pub updated_at: DateTime<Utc>,
}

0 comments on commit cda8e51

Please sign in to comment.