Skip to content

Commit

Permalink
cleanup: fixed api spec errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cdxker committed Mar 5, 2024
1 parent d311e73 commit cc31e84
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 50 deletions.
13 changes: 9 additions & 4 deletions server/src/data/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ use utoipa::ToSchema;
// type alias to use in multiple places
pub type Pool = r2d2::Pool<ConnectionManager<PgConnection>>;

#[derive(Debug, Serialize, Deserialize)]
pub struct AI {
pub a : String,
}

#[derive(Debug, Serialize, Deserialize, Queryable, Insertable, Selectable, Clone, ToSchema)]
#[diesel(table_name = users)]
pub struct User {
Expand Down Expand Up @@ -344,7 +349,7 @@ impl SlimUser {
}
}

#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct UserDTO {
pub id: uuid::Uuid,
pub email: Option<String>,
Expand Down Expand Up @@ -483,7 +488,7 @@ impl FileGroup {
}
}

#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct UserDTOWithChunks {
pub id: uuid::Uuid,
pub email: Option<String>,
Expand Down Expand Up @@ -1041,7 +1046,7 @@ impl ClientDatasetConfiguration {
}
}

#[derive(Serialize, Deserialize, Debug, Clone, ToSchema)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DatasetAndOrgWithSubAndPlan {
pub dataset: Dataset,
pub organization: OrganizationWithSubAndPlan,
Expand Down Expand Up @@ -1274,7 +1279,7 @@ impl OrganizationWithSubAndPlan {
}
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, ToSchema, Ord, PartialOrd)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Ord, PartialOrd)]
pub enum UserRole {
Owner = 2,
Admin = 1,
Expand Down
6 changes: 0 additions & 6 deletions server/src/handlers/auth_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ use serde_json::json;
use std::future::{ready, Ready};
use utoipa::ToSchema;

#[derive(Debug, Deserialize, ToSchema)]
pub struct AuthData {
pub email: String,
pub password: String,
}

#[derive(Deserialize, Debug)]
pub struct OpCallback {
pub state: String,
Expand Down
2 changes: 1 addition & 1 deletion server/src/handlers/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub async fn get_events(
Ok(HttpResponse::Ok().json(events))
}

#[derive(Debug, Deserialize, Serialize, Clone, ToSchema)]
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct EventId {
/// Id of the notification to target.
pub notification_id: uuid::Uuid,
Expand Down
26 changes: 13 additions & 13 deletions server/src/handlers/group_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub struct GroupData {
pub total_pages: i64,
}

#[derive(Deserialize, Serialize, ToSchema)]
#[derive(Deserialize, Serialize)]
pub struct DatasetGroupQuery {
pub dataset_id: uuid::Uuid,
pub page: u64,
Expand Down Expand Up @@ -164,7 +164,7 @@ pub async fn get_specific_dataset_chunk_groups(
}))
}

#[derive(Deserialize, Serialize, ToSchema)]
#[derive(Deserialize, Serialize)]
pub struct GetGroupByTrackingIDData {
pub tracking_id: String,
}
Expand Down Expand Up @@ -219,7 +219,7 @@ pub struct UpdateGroupByTrackingIDData {

#[utoipa::path(
put,
path = "/chunk_group/tracking_id",
path = "/chunk_group/tracking_id/{tracking_id}",
context_path = "/api",
tag = "chunk_group",
request_body(content = UpdateGroupByTrackingIDData, description = "JSON request payload to update a chunkGroup", content_type = "application/json"),
Expand All @@ -229,7 +229,7 @@ pub struct UpdateGroupByTrackingIDData {
),
params(
("TR-Dataset" = String, Header, description = "The dataset id to use for the request"),
("tracking_id" = uuid, description = "Tracking id of the chunk_group to update"),
("tracking_id" = uuid::Uuid, description = "Tracking id of the chunk_group to update"),
),
security(
("ApiKey" = ["admin"]),
Expand Down Expand Up @@ -264,7 +264,7 @@ pub async fn update_group_by_tracking_id(
Ok(HttpResponse::NoContent().finish())
}

#[derive(Debug, Deserialize, Serialize, ToSchema)]
#[derive(Debug, Deserialize, Serialize)]
pub struct DeleteGroupByTrackingIDData {
pub delete_chunks: Option<bool>,
}
Expand All @@ -280,7 +280,7 @@ pub struct DeleteGroupByTrackingIDData {
),
params(
("TR-Dataset" = String, Header, description = "The dataset id to use for the request"),
("tracking_id" = uuid, description = "Tracking id of the chunk_group to delete"),
("tracking_id" = uuid::Uuid, description = "Tracking id of the chunk_group to delete"),
),
security(
("ApiKey" = ["admin"]),
Expand Down Expand Up @@ -316,7 +316,7 @@ pub async fn delete_group_by_tracking_id(
Ok(HttpResponse::NoContent().finish())
}

#[derive(Debug, Deserialize, Serialize, ToSchema)]
#[derive(Debug, Deserialize, Serialize)]
pub struct DeleteGroupData {
pub delete_chunks: Option<bool>,
}
Expand All @@ -335,7 +335,7 @@ pub struct DeleteGroupData {
),
params(
("TR-Dataset" = String, Header, description = "The dataset id to use for the request"),
("group_id" = uuid, description = "Id of the chunk_group to delete"),
("group_id" = uuid::Uuid, description = "Id of the chunk_group to delete"),
("delete_chunks" = bool, Query, description = "Delete the chunks within the group"),
),
security(
Expand Down Expand Up @@ -518,7 +518,7 @@ pub struct AddChunkToGroupByTrackingIdData {
),
params(
("TR-Dataset" = String, Header, description = "The dataset id to use for the request"),
("group_id" = uuid, description = "Id of the group to add the chunk to as a bookmark"),
("tracking_id" = uuid, description = "Id of the group to add the chunk to as a bookmark"),
),
security(
("ApiKey" = ["admin"]),
Expand Down Expand Up @@ -569,7 +569,7 @@ pub struct BookmarkData {
pub total_pages: i64,
}

#[derive(Serialize, Deserialize, Debug, ToSchema)]
#[derive(Serialize, Deserialize, Debug)]
pub struct GetAllBookmarksData {
pub group_id: uuid::Uuid,
pub page: Option<u64>,
Expand Down Expand Up @@ -628,7 +628,7 @@ pub async fn get_chunks_in_group(
}))
}

#[derive(Serialize, Deserialize, Debug, ToSchema)]
#[derive(Serialize, Deserialize, Debug)]
pub struct GetAllBookmarksByTrackingIdData {
pub tracking_id: String,
pub page: Option<u64>,
Expand Down Expand Up @@ -726,7 +726,7 @@ pub async fn get_groups_chunk_is_in(
Ok(HttpResponse::Ok().json(groups))
}

#[derive(Deserialize, Serialize, ToSchema)]
#[derive(Deserialize, Serialize)]
pub struct DeleteBookmarkPathData {
pub chunk_id: uuid::Uuid,
}
Expand Down Expand Up @@ -795,7 +795,7 @@ pub async fn group_unique_search(
Ok(group)
}

#[derive(Serialize, Deserialize, Debug, ToSchema)]
#[derive(Serialize, Deserialize, Debug)]
pub struct GenerateOffGroupData {
pub group_id: uuid::Uuid,
pub page: Option<u64>,
Expand Down
12 changes: 6 additions & 6 deletions server/src/handlers/stripe_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub async fn webhook(
Ok(HttpResponse::Ok().finish())
}

#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetDirectPaymentLinkData {
pub plan_id: uuid::Uuid,
pub organization_id: uuid::Uuid,
Expand Down Expand Up @@ -227,8 +227,8 @@ pub async fn direct_to_payment_link(
("subscription_id" = uuid, Path, description = "id of the subscription you want to cancel"),
),
security(
("api_key" = ["owner"]),
("cookie" = ["owner"])
("ApiKey" = ["owner"]),
("Cookie" = ["owner"])
)
)]
pub async fn cancel_subscription(
Expand Down Expand Up @@ -257,7 +257,7 @@ pub async fn cancel_subscription(
Ok(HttpResponse::Ok().finish())
}

#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct UpdateSubscriptionData {
pub subscription_id: uuid::Uuid,
pub plan_id: uuid::Uuid,
Expand All @@ -278,8 +278,8 @@ pub struct UpdateSubscriptionData {
("plan_id" = uuid::Uuid, Path, description = "id of the plan you want to subscribe to"),
),
security(
("api_key" = ["readonly"]),
("cookie" = ["readonly"])
("ApiKey" = ["readonly"]),
("Cookie" = ["readonly"])
)
)]
pub async fn update_subscription_plan(
Expand Down
2 changes: 1 addition & 1 deletion server/src/handlers/user_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct UpdateUserData {
pub role: Option<i32>,
}

#[derive(Serialize, Deserialize, Debug, ToSchema)]
#[derive(Serialize, Deserialize, Debug)]
pub struct GetUserWithChunksData {
/// The id of the user to fetch the chunks for.
pub user_id: uuid::Uuid,
Expand Down
20 changes: 1 addition & 19 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ impl Modify for SecurityAddon {
),
components(
schemas(
handlers::auth_handler::AuthData,
handlers::auth_handler::AuthQuery,
handlers::topic_handler::CreateTopicData,
handlers::topic_handler::DeleteTopicData,
Expand All @@ -174,31 +173,21 @@ impl Modify for SecurityAddon {
handlers::chunk_handler::SearchGroupsResult,
handlers::chunk_handler::SearchChunkQueryResponseBody,
handlers::user_handler::UpdateUserData,
handlers::user_handler::GetUserWithChunksData,
handlers::user_handler::SetUserApiKeyRequest,
handlers::user_handler::SetUserApiKeyResponse,
handlers::user_handler::DeleteUserApiKeyRequest,
handlers::group_handler::GroupData,
handlers::group_handler::DatasetGroupQuery,
handlers::group_handler::CreateChunkGroupData,
handlers::group_handler::DeleteGroupData,
handlers::group_handler::UpdateChunkGroupData,
handlers::group_handler::AddChunkToGroupData,
handlers::group_handler::GetGroupsForChunksData,
handlers::group_handler::DeleteBookmarkPathData,
handlers::group_handler::GenerateOffGroupData,
handlers::group_handler::GetAllBookmarksData,
handlers::group_handler::BookmarkData,
handlers::group_handler::GetGroupByTrackingIDData,
handlers::group_handler::DeleteGroupByTrackingIDData,
handlers::group_handler::UpdateGroupByTrackingIDData,
handlers::group_handler::GetAllBookmarksByTrackingIdData,
handlers::group_handler::AddChunkToGroupData,
operators::group_operator::BookmarkGroupResult,
handlers::file_handler::UploadFileData,
handlers::file_handler::UploadFileResult,
handlers::invitation_handler::InvitationData,
handlers::event_handler::EventId,
handlers::organization_handler::CreateOrganizationData,
handlers::organization_handler::UpdateOrganizationData,
operators::event_operator::EventReturn,
Expand All @@ -207,33 +196,26 @@ impl Modify for SecurityAddon {
handlers::dataset_handler::CreateDatasetRequest,
handlers::dataset_handler::UpdateDatasetRequest,
handlers::dataset_handler::DeleteDatasetRequest,
handlers::stripe_handler::GetDirectPaymentLinkData,
handlers::stripe_handler::UpdateSubscriptionData,
data::models::ApiKeyDTO,
data::models::SlimUser,
data::models::UserOrganization,
data::models::UserDTO,
data::models::Topic,
data::models::Message,
data::models::ChunkMetadata,
data::models::ChunkMetadataWithFileData,
data::models::ChatMessageProxy,
data::models::Event,
data::models::SlimGroup,
data::models::UserDTOWithChunks,
data::models::File,
data::models::ChunkGroup,
data::models::ChunkGroupAndFile,
data::models::FileDTO,
data::models::Organization,
data::models::OrganizationWithSubAndPlan,
data::models::OrganizationUsageCount,
data::models::Dataset,
data::models::DatasetAndUsage,
data::models::DatasetDTO,
data::models::DatasetUsageCount,
data::models::UserRole,
data::models::DatasetAndOrgWithSubAndPlan,
data::models::ClientDatasetConfiguration,
data::models::StripePlan,
data::models::StripeSubscription,
Expand All @@ -256,7 +238,7 @@ impl Modify for SecurityAddon {
(name = "health", description = "Health check endpoint. Used to check if the server is up and running."),
),
)]
struct ApiDoc;
pub struct ApiDoc;

#[actix_web::main]
pub async fn main() -> std::io::Result<()> {
Expand Down

0 comments on commit cc31e84

Please sign in to comment.