From 4a550904bf93fe6642c8babde77db49aae206ec1 Mon Sep 17 00:00:00 2001 From: Mika Date: Wed, 2 Apr 2025 10:29:51 +0200 Subject: [PATCH] add projects controller and API endpoint for project creation --- bruno/bruno.json | 9 +++++++++ bruno/environments/local-dev.bru | 4 ++++ bruno/groups/folder.bru | 3 +++ bruno/projects/Create Project.bru | 11 +++++++++++ bruno/projects/folder.bru | 3 +++ bruno/users/folder.bru | 3 +++ crates/backend/src/controller.rs | 4 +++- crates/backend/src/controller/projects.rs | 10 ++++++++++ crates/backend/src/main.rs | 6 +++--- dev-compose.yml | 1 - 10 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 bruno/bruno.json create mode 100644 bruno/environments/local-dev.bru create mode 100644 bruno/groups/folder.bru create mode 100644 bruno/projects/Create Project.bru create mode 100644 bruno/projects/folder.bru create mode 100644 bruno/users/folder.bru create mode 100644 crates/backend/src/controller/projects.rs diff --git a/bruno/bruno.json b/bruno/bruno.json new file mode 100644 index 0000000..7dd5cbe --- /dev/null +++ b/bruno/bruno.json @@ -0,0 +1,9 @@ +{ + "version": "1", + "name": "pgg-bruno", + "type": "collection", + "ignore": [ + "node_modules", + ".git" + ] +} \ No newline at end of file diff --git a/bruno/environments/local-dev.bru b/bruno/environments/local-dev.bru new file mode 100644 index 0000000..92ab347 --- /dev/null +++ b/bruno/environments/local-dev.bru @@ -0,0 +1,4 @@ +vars { + api_base: http://localhost:8080/api/{{api_version}} + api_version: v1 +} diff --git a/bruno/groups/folder.bru b/bruno/groups/folder.bru new file mode 100644 index 0000000..28b5117 --- /dev/null +++ b/bruno/groups/folder.bru @@ -0,0 +1,3 @@ +meta { + name: groups +} diff --git a/bruno/projects/Create Project.bru b/bruno/projects/Create Project.bru new file mode 100644 index 0000000..7ad2fa6 --- /dev/null +++ b/bruno/projects/Create Project.bru @@ -0,0 +1,11 @@ +meta { + name: Create Project + type: http + seq: 1 +} + +post { + url: {{api_base}}/projects + body: none + auth: inherit +} diff --git a/bruno/projects/folder.bru b/bruno/projects/folder.bru new file mode 100644 index 0000000..9aadbec --- /dev/null +++ b/bruno/projects/folder.bru @@ -0,0 +1,3 @@ +meta { + name: projects +} diff --git a/bruno/users/folder.bru b/bruno/users/folder.bru new file mode 100644 index 0000000..0805f3a --- /dev/null +++ b/bruno/users/folder.bru @@ -0,0 +1,3 @@ +meta { + name: users +} diff --git a/crates/backend/src/controller.rs b/crates/backend/src/controller.rs index 32d5768..c0fd585 100644 --- a/crates/backend/src/controller.rs +++ b/crates/backend/src/controller.rs @@ -1,5 +1,7 @@ use actix_web::web::{self, ServiceConfig}; +mod projects; + pub fn register_controllers(cfg: &mut ServiceConfig) { - cfg.service(web::scope("/users")); + cfg.service(web::scope("/projects").configure(projects::setup)); } diff --git a/crates/backend/src/controller/projects.rs b/crates/backend/src/controller/projects.rs new file mode 100644 index 0000000..b28bf74 --- /dev/null +++ b/crates/backend/src/controller/projects.rs @@ -0,0 +1,10 @@ +use actix_web::Result; + +pub fn setup(cfg: &mut actix_web::web::ServiceConfig) { + cfg.service(create_project); +} + +#[actix_web::post("")] +async fn create_project() -> Result { + Ok(actix_web::HttpResponse::Ok().finish()) +} diff --git a/crates/backend/src/main.rs b/crates/backend/src/main.rs index cefd4d6..2eeea00 100644 --- a/crates/backend/src/main.rs +++ b/crates/backend/src/main.rs @@ -1,6 +1,6 @@ use actix_files::NamedFile; -use actix_session::{storage::RedisSessionStore, SessionMiddleware}; -use actix_web::{cookie::Key, middleware::Logger, web, App, HttpResponse, HttpServer}; +use actix_session::{SessionMiddleware, storage::RedisSessionStore}; +use actix_web::{App, HttpResponse, HttpServer, cookie::Key, middleware::Logger, web}; use argon2::Argon2; use db::Database; use std::env; @@ -32,7 +32,7 @@ async fn main() -> std::io::Result<()> { redis_conn.clone(), secret_key.clone(), )) - .configure(controller::register_controllers); + .service(web::scope("/api/v1").configure(controller::register_controllers)); #[cfg(feature = "serve")] let app = { diff --git a/dev-compose.yml b/dev-compose.yml index cf84951..296bc54 100644 --- a/dev-compose.yml +++ b/dev-compose.yml @@ -1,7 +1,6 @@ services: db: image: postgres:latest - container_name: database restart: unless-stopped env_file: - .env