Skip to content

Commit

Permalink
Extract input types
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam committed Apr 25, 2024
1 parent 5906b91 commit 212ea92
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 53 deletions.
26 changes: 1 addition & 25 deletions ee/tabby-webserver/src/schema/github_repository_provider.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use juniper::{GraphQLInputObject, GraphQLObject, ID};
use validator::Validate;
use juniper::{GraphQLObject, ID};

use super::Context;
use crate::{juniper::relay::NodeType, schema::Result};

#[derive(GraphQLInputObject, Validate)]
pub struct CreateRepositoryProviderInput {
#[validate(regex(
code = "displayName",
path = "crate::schema::constants::REPOSITORY_NAME_REGEX"
))]
pub display_name: String,
#[validate(length(code = "access_token", min = 10))]
pub access_token: String,
}

#[derive(GraphQLInputObject, Validate)]
pub struct UpdateRepositoryProviderInput {
pub id: ID,
#[validate(regex(
code = "displayName",
path = "crate::schema::constants::REPOSITORY_NAME_REGEX"
))]
pub display_name: String,
#[validate(length(code = "access_token", min = 10))]
pub access_token: String,
}

#[derive(GraphQLObject, Debug, PartialEq)]
#[graphql(context = Context)]
pub struct GithubRepositoryProvider {
Expand Down
26 changes: 1 addition & 25 deletions ee/tabby-webserver/src/schema/gitlab_repository_provider.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use juniper::{GraphQLInputObject, GraphQLObject, ID};
use validator::Validate;
use juniper::{GraphQLObject, ID};

use super::Context;
use crate::{juniper::relay::NodeType, schema::Result};

#[derive(GraphQLInputObject, Validate)]
pub struct CreateGitlabRepositoryProviderInput {
#[validate(regex(
code = "displayName",
path = "crate::schema::constants::REPOSITORY_NAME_REGEX"
))]
pub display_name: String,
#[validate(length(code = "access_token", min = 10))]
pub access_token: String,
}

#[derive(GraphQLInputObject, Validate)]
pub struct UpdateGitlabRepositoryProviderInput {
pub id: ID,
#[validate(regex(
code = "displayName",
path = "crate::schema::constants::REPOSITORY_NAME_REGEX"
))]
pub display_name: String,
#[validate(length(code = "access_token", min = 10))]
pub access_token: String,
}

#[derive(GraphQLObject, Debug, PartialEq)]
#[graphql(context = Context)]
pub struct GitlabRepositoryProvider {
Expand Down
5 changes: 2 additions & 3 deletions ee/tabby-webserver/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod job;
pub mod license;
pub mod repository;
pub mod setting;
pub mod types;
pub mod user_event;
pub mod worker;

Expand Down Expand Up @@ -51,11 +52,9 @@ use crate::{
axum::FromAuth,
juniper::relay::{self, Connection},
schema::{
github_repository_provider::{
CreateRepositoryProviderInput, UpdateRepositoryProviderInput,
},
gitlab_repository_provider::{GitlabProvidedRepository, GitlabRepositoryProvider},
repository::FileEntrySearchResult,
types::{CreateRepositoryProviderInput, UpdateRepositoryProviderInput},
},
};

Expand Down
25 changes: 25 additions & 0 deletions ee/tabby-webserver/src/schema/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use juniper::{GraphQLInputObject, ID};
use validator::Validate;

#[derive(GraphQLInputObject, Validate)]
pub struct CreateRepositoryProviderInput {
#[validate(regex(
code = "displayName",
path = "crate::schema::constants::REPOSITORY_NAME_REGEX"
))]
pub display_name: String,
#[validate(length(code = "access_token", min = 10))]
pub access_token: String,
}

#[derive(GraphQLInputObject, Validate)]
pub struct UpdateRepositoryProviderInput {
pub id: ID,
#[validate(regex(
code = "displayName",
path = "crate::schema::constants::REPOSITORY_NAME_REGEX"
))]
pub display_name: String,
#[validate(length(code = "access_token", min = 10))]
pub access_token: String,
}

0 comments on commit 212ea92

Please sign in to comment.