init: Initial commit

This commit is contained in:
Freezlex 2024-12-17 10:57:05 +01:00
commit ac1633fe4b
15 changed files with 279 additions and 0 deletions

View File

@ -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*"
}
}

9
.bruno/bruno.json Normal file
View File

@ -0,0 +1,9 @@
{
"version": "1",
"name": "deckard",
"type": "collection",
"ignore": [
"node_modules",
".git"
]
}

11
.bruno/health/Alive.bru Normal file
View File

@ -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
}

133
.gitignore vendored Normal file
View File

@ -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

8
.idea/.gitignore generated vendored Normal file
View File

@ -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

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/web-api.iml" filepath="$PROJECT_DIR$/.idea/web-api.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

11
.idea/web-api.iml generated Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

13
Cargo.toml Normal file
View File

@ -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"]}

15
src/controllers/auth.rs Normal file
View File

@ -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<auth::NewUser>) -> 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)
);
}

11
src/controllers/health.rs Normal file
View File

@ -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));
}

10
src/controllers/mod.rs Normal file
View File

@ -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);
}

14
src/main.rs Normal file
View File

@ -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
}

10
src/models/auth.rs Normal file
View File

@ -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<Uuid>
}

1
src/models/mod.rs Normal file
View File

@ -0,0 +1 @@
pub(crate) mod auth;