From ac1633fe4b6fca0b7d51e70a05e44d4e8cfb9652 Mon Sep 17 00:00:00 2001 From: Freezlex Date: Tue, 17 Dec 2024 10:57:05 +0100 Subject: [PATCH] init: Initial commit --- .bruno/auth/Create new user.bru | 19 +++++ .bruno/bruno.json | 9 +++ .bruno/health/Alive.bru | 11 +++ .gitignore | 133 ++++++++++++++++++++++++++++++++ .idea/.gitignore | 8 ++ .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 ++ .idea/web-api.iml | 11 +++ Cargo.toml | 13 ++++ src/controllers/auth.rs | 15 ++++ src/controllers/health.rs | 11 +++ src/controllers/mod.rs | 10 +++ src/main.rs | 14 ++++ src/models/auth.rs | 10 +++ src/models/mod.rs | 1 + 15 files changed, 279 insertions(+) create mode 100644 .bruno/auth/Create new user.bru create mode 100644 .bruno/bruno.json create mode 100644 .bruno/health/Alive.bru create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/web-api.iml create mode 100644 Cargo.toml create mode 100644 src/controllers/auth.rs create mode 100644 src/controllers/health.rs create mode 100644 src/controllers/mod.rs create mode 100644 src/main.rs create mode 100644 src/models/auth.rs create mode 100644 src/models/mod.rs diff --git a/.bruno/auth/Create new user.bru b/.bruno/auth/Create new user.bru new file mode 100644 index 0000000..805bcdb --- /dev/null +++ b/.bruno/auth/Create new user.bru @@ -0,0 +1,19 @@ +meta { + name: Create new user + type: http + seq: 1 +} + +post { + url: http://127.0.0.1:3000/auth/new + body: json + auth: none +} + +body:json { + { + "username": "someone", + "email": "someone@deck.ard", + "password": "*S@me@nePassw@rd*" + } +} diff --git a/.bruno/bruno.json b/.bruno/bruno.json new file mode 100644 index 0000000..9afdc9e --- /dev/null +++ b/.bruno/bruno.json @@ -0,0 +1,9 @@ +{ + "version": "1", + "name": "deckard", + "type": "collection", + "ignore": [ + "node_modules", + ".git" + ] +} \ No newline at end of file diff --git a/.bruno/health/Alive.bru b/.bruno/health/Alive.bru new file mode 100644 index 0000000..bbe3420 --- /dev/null +++ b/.bruno/health/Alive.bru @@ -0,0 +1,11 @@ +meta { + name: Alive + type: http + seq: 1 +} + +get { + url: http://127.0.0.1:3000/health/alive + body: none + auth: none +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0f22051 --- /dev/null +++ b/.gitignore @@ -0,0 +1,133 @@ +# Created by https://www.toptal.com/developers/gitignore/api/rust,intellij +# Edit at https://www.toptal.com/developers/gitignore?templates=rust,intellij + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# End of https://www.toptal.com/developers/gitignore/api/rust,intellij diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..04302a4 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/web-api.iml b/.idea/web-api.iml new file mode 100644 index 0000000..cf84ae4 --- /dev/null +++ b/.idea/web-api.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..5d40407 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "web-api" +version = "0.1.0" +edition = "2021" + +[dependencies] +server = {path = "../server"} +security = {path = "../security"} +actix-web = "4.9.0" +serde = { version = "1.0.216", features = ["derive"] } +serde_json = "1.0.133" +uuid = {version = "1.11.0", features = ["v4", "serde"]} +tokio = {version="1.42.0", features = ["full"]} \ No newline at end of file diff --git a/src/controllers/auth.rs b/src/controllers/auth.rs new file mode 100644 index 0000000..7c9a24e --- /dev/null +++ b/src/controllers/auth.rs @@ -0,0 +1,15 @@ +use actix_web::{post, web, HttpResponse, Responder}; +use uuid::Uuid; +use crate::models::{auth}; + +#[post("/new")] +async fn register(mut model: web::Json) -> impl Responder { + model.id = Option::from(Uuid::new_v4()); + HttpResponse::Ok().json(model) +} + +pub fn config_auth_controller(cfg: &mut web::ServiceConfig) { + cfg.service(web::scope("/auth") + .service(register) + ); +} \ No newline at end of file diff --git a/src/controllers/health.rs b/src/controllers/health.rs new file mode 100644 index 0000000..fdc4139 --- /dev/null +++ b/src/controllers/health.rs @@ -0,0 +1,11 @@ +use actix_web::{get, web, HttpResponse, Responder}; + +#[get("")] +async fn alive() -> impl Responder { + HttpResponse::Ok().body("Alive") +} + +pub fn config_health_router(cfg: &mut web::ServiceConfig) { + cfg.service(web::scope("/health") + .service(alive)); +} \ No newline at end of file diff --git a/src/controllers/mod.rs b/src/controllers/mod.rs new file mode 100644 index 0000000..002f04d --- /dev/null +++ b/src/controllers/mod.rs @@ -0,0 +1,10 @@ +use actix_web::web; + +mod auth; +mod health; + +pub fn config_routers(cfg: &mut web::ServiceConfig){ + cfg + .configure(health::config_health_router) + .configure(auth::config_auth_controller); +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..d7c530d --- /dev/null +++ b/src/main.rs @@ -0,0 +1,14 @@ +mod controllers; +mod models; + +use core; +use actix_web::{App, HttpServer}; + +#[actix_web::main] +async fn main() -> std::io::Result<()> { + println!("Server running at http://{}:{}", "127.0.0.1", "3000"); + HttpServer::new(|| { App::new().configure(controllers::config_routers) }) + .bind(("127.0.0.1", 3000))? + .run() + .await +} diff --git a/src/models/auth.rs b/src/models/auth.rs new file mode 100644 index 0000000..5e785a3 --- /dev/null +++ b/src/models/auth.rs @@ -0,0 +1,10 @@ +use serde::{Serialize, Deserialize}; +use uuid::Uuid; + +#[derive(Debug, Serialize, Deserialize)] +pub struct NewUser { + pub username: String, + pub password: String, + pub email: String, + pub id: Option +} \ No newline at end of file diff --git a/src/models/mod.rs b/src/models/mod.rs new file mode 100644 index 0000000..4da6aa0 --- /dev/null +++ b/src/models/mod.rs @@ -0,0 +1 @@ +pub(crate) mod auth; \ No newline at end of file