From 0972fa6eab8c9111311f082ba8abfdc6b4a40945 Mon Sep 17 00:00:00 2001 From: nil Date: Wed, 2 Oct 2024 17:48:56 +0200 Subject: commit changes --- src/main.rs | 35 +++++++++++++++++++++++++++++++++++ src/routes.rs | 0 src/routes/hello.rs | 11 +++++++++++ src/structs.rs | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 src/main.rs create mode 100644 src/routes.rs create mode 100644 src/routes/hello.rs create mode 100644 src/structs.rs (limited to 'src') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..af45779 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,35 @@ +mod structs; +mod routes; + +use actix_web::{web, App, HttpServer}; +use sqlx::mysql::{MySqlPool, MySqlPoolOptions}; + +#[derive(Clone)] +struct AppState { + pool: MySqlPool, +} + +#[actix_web::main] +async fn main() -> std::io::Result<()> { + let pool: MySqlPool = MySqlPoolOptions::new() + .max_connections(10) + .connect(DB_URL) + .await + .unwrap(); + + let app_state = AppState { pool }; + + HttpServer::new(move || { + App::new() + .app_data(web::Data::new(app_state.clone())) + .route("/", web::get().to(root)) + .service(routes::hello::hello_actix) + }) + .bind(("127.0.0.1", 8000))? + .run() + .await +} + +async fn root() -> String { + String::from("Server is up and running") +} diff --git a/src/routes.rs b/src/routes.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/routes/hello.rs b/src/routes/hello.rs new file mode 100644 index 0000000..c356081 --- /dev/null +++ b/src/routes/hello.rs @@ -0,0 +1,11 @@ +use crate::AppState; +use actix_web::{get, web, HttpResponse}; +use serde::Deserialize; + +#[get("/hello")] +pub async fn hello_actix(app_state: web::Data) -> HttpResponse { + struct Song { + } + + return HttpResponse::Ok().json(databases); +} diff --git a/src/structs.rs b/src/structs.rs new file mode 100644 index 0000000..7535bb4 --- /dev/null +++ b/src/structs.rs @@ -0,0 +1,35 @@ +#[allow(dead_code)] +struct Song { + //song variables + id: i32, + title: String, + lyrics: String, + + //album variables + album_id: i32, + genres: Vec, + album_cover: String, + + //artist variables + artist_id: i32, + artist_name: String, +} + +#[allow(dead_code)] +struct Album { + id: i32, + title: String, + genres: Vec, + cover: String, + songs: Vec, +} + +#[allow(dead_code)] +struct Artist { + id: i32, + name: String, + genres: Vec, + albums: Vec, +} + +// lepht anonym -- cgit v1.2.3