diff options
author | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-24 12:00:24 +0100 |
---|---|---|
committer | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-24 12:00:24 +0100 |
commit | c2786c4b9d704128da80ce4ed6513b9f5507b680 (patch) | |
tree | fe17ca91b195a7b55b4b30f343a5a6eea95a755e /src/api/mod.rs | |
parent | 8c4de2ddac066a072f376e9f30409b114aa9978c (diff) |
Diffstat (limited to 'src/api/mod.rs')
-rw-r--r-- | src/api/mod.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/api/mod.rs b/src/api/mod.rs new file mode 100644 index 0000000..d07079a --- /dev/null +++ b/src/api/mod.rs @@ -0,0 +1,43 @@ +use actix_web::{web, HttpResponse, Scope}; +use serde::{Deserialize, Serialize}; + +pub mod album; +pub mod artist; +pub mod search_results; +pub mod song; + +pub fn api_scope() -> Scope { + web::scope("/api") + .service(song::get_song) + .service(song::post_song) + .service(song::put_song) + .service(song::delete_song) + .service(album::get_album) + .service(album::post_album) + .service(album::put_album) + .service(album::delete_album) + .service(artist::get_artist) + .service(artist::post_artist) + .service(artist::put_artist) + .service(artist::delete_artist) + .service(search_results::search_results) +} + +#[derive(Serialize, Deserialize)] +pub struct Response { + message: String, +} + +pub fn get_response_from_query( + query: Result<sqlx::mysql::MySqlQueryResult, sqlx::Error>, + method: String, +) -> HttpResponse { + match query { + Ok(_) => HttpResponse::Ok().json(Response { + message: format!("{} request executed with no errors", method).to_owned(), + }), + Err(e) => HttpResponse::BadRequest().json(Response { + message: format!("There was an issue in the request: {}", e).to_owned(), + }), + } +} |