diff --git a/bruno/group/folder.bru b/bruno/group/folder.bru new file mode 100644 index 0000000..0e46f1e --- /dev/null +++ b/bruno/group/folder.bru @@ -0,0 +1,3 @@ +meta { + name: group +} diff --git a/bruno/groups/folder.bru b/bruno/groups/folder.bru deleted file mode 100644 index 28b5117..0000000 --- a/bruno/groups/folder.bru +++ /dev/null @@ -1,3 +0,0 @@ -meta { - name: groups -} diff --git a/bruno/projects/Create Project.bru b/bruno/project/Create Project.bru similarity index 86% rename from bruno/projects/Create Project.bru rename to bruno/project/Create Project.bru index af88881..0974523 100644 --- a/bruno/projects/Create Project.bru +++ b/bruno/project/Create Project.bru @@ -5,7 +5,7 @@ meta { } post { - url: {{api_base}}/projects + url: {{api_base}}/project body: json auth: inherit } @@ -18,4 +18,4 @@ body:json { vars:pre-request { name: FillThisOutButDontCommitIt! -} \ No newline at end of file +} diff --git a/bruno/project/Delete Project.bru b/bruno/project/Delete Project.bru new file mode 100644 index 0000000..702cf94 --- /dev/null +++ b/bruno/project/Delete Project.bru @@ -0,0 +1,15 @@ +meta { + name: Delete Project + type: http + seq: 2 +} + +delete { + url: {{api_base}}/project/:id + body: none + auth: inherit +} + +params:path { + id: MyAwesomeUUIDHere! +} diff --git a/bruno/project/folder.bru b/bruno/project/folder.bru new file mode 100644 index 0000000..baebd27 --- /dev/null +++ b/bruno/project/folder.bru @@ -0,0 +1,3 @@ +meta { + name: project +} diff --git a/bruno/projects/folder.bru b/bruno/projects/folder.bru deleted file mode 100644 index 9aadbec..0000000 --- a/bruno/projects/folder.bru +++ /dev/null @@ -1,3 +0,0 @@ -meta { - name: projects -} diff --git a/bruno/user/folder.bru b/bruno/user/folder.bru new file mode 100644 index 0000000..13e6ad7 --- /dev/null +++ b/bruno/user/folder.bru @@ -0,0 +1,3 @@ +meta { + name: user +} diff --git a/bruno/users/folder.bru b/bruno/users/folder.bru deleted file mode 100644 index 0805f3a..0000000 --- a/bruno/users/folder.bru +++ /dev/null @@ -1,3 +0,0 @@ -meta { - name: users -} diff --git a/crates/backend/Cargo.toml b/crates/backend/Cargo.toml index 85c8684..8247638 100644 --- a/crates/backend/Cargo.toml +++ b/crates/backend/Cargo.toml @@ -17,6 +17,7 @@ argon2 = "0.5.3" thiserror = "2" env_logger = "0.11" +log = "0.4" serde = { version = "1", features = ["derive"] } sea-orm = { version = "1.1", features = [ diff --git a/crates/backend/src/controller.rs b/crates/backend/src/controller.rs index a129913..1845896 100644 --- a/crates/backend/src/controller.rs +++ b/crates/backend/src/controller.rs @@ -7,5 +7,9 @@ mod template; mod user; pub fn register_controllers(cfg: &mut ServiceConfig) { - cfg.service(web::scope("/projects").configure(project::setup)); + cfg.service(web::scope("/project").configure(project::setup)) + .service(web::scope("/group").configure(group::setup)) + .service(web::scope("/user").configure(user::setup)) + .service(web::scope("/class").configure(class::setup)) + .service(web::scope("/template").configure(template::setup)); } diff --git a/crates/backend/src/controller/class.rs b/crates/backend/src/controller/class.rs index ad7448a..e3e3498 100644 --- a/crates/backend/src/controller/class.rs +++ b/crates/backend/src/controller/class.rs @@ -1,5 +1,12 @@ use actix_web::{Responder, delete, get, post}; +pub fn setup(cfg: &mut actix_web::web::ServiceConfig) { + cfg.service(get_classes) + .service(get_class) + .service(create_class) + .service(delete_class); +} + #[get("")] async fn get_classes() -> impl Responder { "" diff --git a/crates/backend/src/controller/group.rs b/crates/backend/src/controller/group.rs index 3bda7e3..648788e 100644 --- a/crates/backend/src/controller/group.rs +++ b/crates/backend/src/controller/group.rs @@ -1,5 +1,12 @@ use actix_web::{Responder, delete, get, post}; +pub fn setup(cfg: &mut actix_web::web::ServiceConfig) { + cfg.service(get_groups) + .service(get_groups_for_project) + .service(create_group) + .service(delete_group); +} + #[get("")] async fn get_groups() -> impl Responder { "" diff --git a/crates/backend/src/controller/project.rs b/crates/backend/src/controller/project.rs index d588e67..887a440 100644 --- a/crates/backend/src/controller/project.rs +++ b/crates/backend/src/controller/project.rs @@ -1,4 +1,6 @@ use actix_web::{Responder, Result, delete, get, post, web}; +use log::info; +use sea_orm::prelude::Uuid; use serde::Deserialize; use crate::db::Database; @@ -10,7 +12,9 @@ struct CreateProject { } pub fn setup(cfg: &mut actix_web::web::ServiceConfig) { - cfg.service(create_project); + cfg.service(create_project) + .service(delete_project) + .service(get_projects); } #[post("")] @@ -24,8 +28,17 @@ async fn create_project( } #[delete("/{id}")] -async fn delete_project() -> impl Responder { - "" +async fn delete_project( + db: web::Data, + path: web::Path, +) -> Result, ApiError> { + let id = path.into_inner(); + let result = db.delete_project(&id).await?; + + Ok(web::Json(format!( + "Successfully deleted {} project/s with the id: {}", + result.rows_affected, id + ))) } #[get("")] diff --git a/crates/backend/src/controller/template.rs b/crates/backend/src/controller/template.rs index a0e5ea3..fa62dab 100644 --- a/crates/backend/src/controller/template.rs +++ b/crates/backend/src/controller/template.rs @@ -1,5 +1,12 @@ use actix_web::{Responder, delete, get, post}; +pub fn setup(cfg: &mut actix_web::web::ServiceConfig) { + cfg.service(get_templates) + .service(get_template) + .service(create_template) + .service(delete_template); +} + #[get("")] async fn get_templates() -> impl Responder { "" diff --git a/crates/backend/src/controller/user.rs b/crates/backend/src/controller/user.rs index 46902b8..3063bfa 100644 --- a/crates/backend/src/controller/user.rs +++ b/crates/backend/src/controller/user.rs @@ -1,12 +1,19 @@ use actix_web::{Responder, delete, get, post}; +pub fn setup(cfg: &mut actix_web::web::ServiceConfig) { + cfg.service(get_users) + .service(get_user) + .service(create_user) + .service(delete_user); +} + #[get("")] async fn get_users() -> impl Responder { "" } #[get("/{id}")] -async fn get_class() -> impl Responder { +async fn get_user() -> impl Responder { "" } diff --git a/crates/backend/src/db.rs b/crates/backend/src/db.rs index 3265f52..a9a326a 100644 --- a/crates/backend/src/db.rs +++ b/crates/backend/src/db.rs @@ -1,6 +1,8 @@ use sea_orm::{ConnectOptions, DatabaseConnection}; +mod group; mod project; +mod user; #[derive(Clone)] pub struct Database { diff --git a/crates/backend/src/db/group.rs b/crates/backend/src/db/group.rs new file mode 100644 index 0000000..0019a00 --- /dev/null +++ b/crates/backend/src/db/group.rs @@ -0,0 +1,3 @@ +fn add_user_to_group() {} + +fn create_group() {} diff --git a/crates/backend/src/db/project.rs b/crates/backend/src/db/project.rs index 763bf9f..c1f84d2 100644 --- a/crates/backend/src/db/project.rs +++ b/crates/backend/src/db/project.rs @@ -1,9 +1,11 @@ use super::Database; use crate::error::ApiError; +use log::info; use entity::project; -use sea_orm::ActiveModelTrait; use sea_orm::ActiveValue::{NotSet, Set}; +use sea_orm::prelude::Uuid; +use sea_orm::{ActiveModelTrait, DeleteResult, EntityTrait}; impl Database { pub async fn create_project(&self, name: &str) -> Result { @@ -15,4 +17,18 @@ impl Database { let project = project.insert(&self.conn).await?; Ok(project) } + + pub async fn delete_project(&self, id: &Uuid) -> Result { + info!("Deleting project with id: {}", id); + + let project = project::Entity::delete_by_id(id.to_owned()) + .exec(&self.conn) + .await?; + + if project.rows_affected == 0 { + return Err(ApiError::NotFound); + } + + Ok(project) + } } diff --git a/crates/backend/src/db/user.rs b/crates/backend/src/db/user.rs new file mode 100644 index 0000000..83052e7 --- /dev/null +++ b/crates/backend/src/db/user.rs @@ -0,0 +1,5 @@ +use super::Database; + +impl Database { + async fn create_user() {} +} diff --git a/crates/backend/src/error.rs b/crates/backend/src/error.rs index dd717e1..b54da1b 100644 --- a/crates/backend/src/error.rs +++ b/crates/backend/src/error.rs @@ -5,12 +5,15 @@ use thiserror::Error; pub enum ApiError { #[error("Database Error: {0}")] Database(#[from] sea_orm::DbErr), + #[error("Not Found")] + NotFound, } impl ResponseError for ApiError { fn status_code(&self) -> StatusCode { match self { ApiError::Database(..) => StatusCode::INTERNAL_SERVER_ERROR, + ApiError::NotFound => StatusCode::NOT_FOUND, } }