Skip to content

Commit

Permalink
[server] Split server into modules #807 (#819)
Browse files Browse the repository at this point in the history
* refactoring

* more refactoring

* split tests

* fix paths
  • Loading branch information
michaelvlach authored Nov 30, 2023
1 parent 7b144a4 commit 0ef8506
Show file tree
Hide file tree
Showing 23 changed files with 1,165 additions and 1,107 deletions.
2 changes: 1 addition & 1 deletion agdb_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ categories = ["database", "database-interfaces"]

[dependencies]
agdb = { version = "0.5.1", path = "../agdb" }
anyhow = "1"
axum = { version = "0.7", features = ["http2"] }
axum-extra = { version = "0.9", features = ["typed-header"] }
http-body-util = "0.1"
Expand All @@ -31,3 +30,4 @@ uuid = { version = "1", features = ["v4"] }
[dev-dependencies]
assert_cmd = "2"
reqwest = { version = "0.11", features = ["json", "blocking"] }
anyhow = "1"
167 changes: 90 additions & 77 deletions agdb_server/openapi/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,25 @@
"version": "0.1.0"
},
"paths": {
"/add_db": {
"/api/v1/admin/shutdown": {
"get": {
"tags": [
"crate::routes::admin"
],
"operationId": "shutdown",
"responses": {
"200": {
"description": "Server is shutting down"
}
}
}
},
"/api/v1/db/add": {
"post": {
"tags": [
"crate::app"
"crate::routes::db"
],
"operationId": "add_db",
"operationId": "add",
"requestBody": {
"content": {
"application/json": {
Expand All @@ -38,123 +51,149 @@
}
}
},
"/change_password": {
"/api/v1/db/delete": {
"post": {
"tags": [
"crate::app"
"crate::routes::db"
],
"operationId": "change_password",
"operationId": "delete",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ChangePassword"
"$ref": "#/components/schemas/ServerDatabaseName"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Password changed"
},
"401": {
"description": "Invalid password"
"description": "Database deleted"
},
"403": {
"description": "User not found"
},
"462": {
"description": "Password too short (<8)"
"description": "Database not found for user"
}
}
}
},
"/create_user": {
"/api/v1/db/list": {
"post": {
"tags": [
"crate::app"
"crate::routes::db"
],
"operationId": "create_user",
"operationId": "list",
"responses": {
"200": {
"description": "Ok",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ServerDatabase"
}
}
}
}
}
}
}
},
"/api/v1/db/remove": {
"post": {
"tags": [
"crate::routes::db"
],
"operationId": "remove",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserCredentials"
"$ref": "#/components/schemas/DeleteServerDatabase"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "User created"
},
"461": {
"description": "Name too short (<3)"
},
"462": {
"description": "Password too short (<8)"
"200": {
"description": "Database removed"
},
"463": {
"description": "User already exists"
"403": {
"description": "Database not found for user"
}
}
}
},
"/delete_db": {
"api/v1/user/change_password": {
"post": {
"tags": [
"crate::app"
"crate::routes::user"
],
"operationId": "delete_db",
"operationId": "change_password",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ServerDatabaseName"
"$ref": "#/components/schemas/ChangePassword"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Database deleted"
"description": "Password changed"
},
"401": {
"description": "Invalid password"
},
"403": {
"description": "Database not found for user"
"description": "User not found"
},
"462": {
"description": "Password too short (<8)"
}
}
}
},
"/list": {
"api/v1/user/create": {
"post": {
"tags": [
"crate::app"
"crate::routes::user"
],
"operationId": "list",
"responses": {
"200": {
"description": "Ok",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ServerDatabase"
}
}
"operationId": "create",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserCredentials"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "User created"
},
"461": {
"description": "Name too short (<3)"
},
"462": {
"description": "Password too short (<8)"
},
"463": {
"description": "User already exists"
}
}
}
},
"/login": {
"api/v1/user/login": {
"post": {
"tags": [
"crate::app"
"crate::routes::user"
],
"operationId": "login",
"requestBody": {
Expand Down Expand Up @@ -186,32 +225,6 @@
}
}
}
},
"/remove_db": {
"post": {
"tags": [
"crate::app"
],
"operationId": "remove_db",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DeleteServerDatabase"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Database removed"
},
"403": {
"description": "Database not found for user"
}
}
}
}
},
"components": {
Expand Down
27 changes: 14 additions & 13 deletions agdb_server/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ use utoipa::OpenApi;
#[derive(OpenApi)]
#[openapi(
paths(
crate::app::add_db,
crate::app::change_password,
crate::app::create_user,
crate::app::delete_db,
crate::app::list,
crate::app::login,
crate::app::remove_db
crate::routes::admin::shutdown,
crate::routes::user::create,
crate::routes::user::login,
crate::routes::user::change_password,
crate::routes::db::add,
crate::routes::db::delete,
crate::routes::db::list,
crate::routes::db::remove,
),
components(schemas(
crate::app::ChangePassword,
crate::app::DbType,
crate::app::ServerDatabase,
crate::app::ServerDatabaseName,
crate::app::UserCredentials,
crate::app::UserToken
crate::routes::user::ChangePassword,
crate::routes::user::UserCredentials,
crate::routes::user::UserToken,
crate::routes::db::DbType,
crate::routes::db::ServerDatabase,
crate::routes::db::ServerDatabaseName,
))
)]
pub(crate) struct Api;
Loading

0 comments on commit 0ef8506

Please sign in to comment.