summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/album.rs51
-rw-r--r--src/api/artist.rs53
-rw-r--r--src/api/mod.rs6
-rw-r--r--src/api/search_results.rs12
-rw-r--r--src/api/song.rs51
5 files changed, 166 insertions, 7 deletions
diff --git a/src/api/album.rs b/src/api/album.rs
index 9094495..f8731fb 100644
--- a/src/api/album.rs
+++ b/src/api/album.rs
@@ -5,15 +5,25 @@ use crate::extractors::auth_token::AuthenticationToken;
use crate::AppState;
use actix_web::{delete, get, post, put, web, HttpResponse};
use serde::Deserialize;
+use utoipa::IntoParams;
/* Possible arguments ( /album?arg=value ) */
-#[derive(Deserialize)]
+#[derive(Deserialize, IntoParams)]
struct AlbumQueryOptions {
id: Option<String>,
name: Option<String>,
artist: Option<String>,
}
+#[utoipa::path(
+ params(AlbumQueryOptions),
+ context_path = "/api",
+ description = "Gets a list of the current albums and applies filters based on the url parameters recieved. It only accepts one parameter at a time.",
+ responses(
+ (status = 200, description = "Return a list of albums", body = Vec<Album>),
+ (status = 400, description = "Errors found, unfulfilled request"),
+ ),
+)]
#[get("/album")]
pub async fn get_album(
app_state: web::Data<AppState>,
@@ -53,6 +63,19 @@ pub async fn get_album(
}
}
+#[utoipa::path(
+ request_body = AlbumPost,
+ context_path = "/api",
+ description = "Creates a new album with the specified values.",
+ responses(
+ (status = 200, description = "Create new album", body = Response),
+ (status = 400, description = "Errors found, unfulfilled request"),
+ (status = 401, description = "Authentication failed"),
+ ),
+ security(
+ {"bearer_auth" = []}
+ ),
+)]
#[post("/album")]
pub async fn post_album(
app_state: web::Data<AppState>,
@@ -68,6 +91,19 @@ pub async fn post_album(
)
}
+#[utoipa::path(
+ request_body = AlbumPut,
+ context_path = "/api",
+ description = "Edits the values of the specified album.",
+ responses(
+ (status = 200, description = "Edit album values", body = Response),
+ (status = 400, description = "Errors found or album not found"),
+ (status = 401, description = "Authentication failed"),
+ ),
+ security(
+ {"bearer_auth" = []}
+ ),
+)]
#[put("/album")]
pub async fn put_album(
app_state: web::Data<AppState>,
@@ -83,6 +119,19 @@ pub async fn put_album(
)
}
+#[utoipa::path(
+ request_body = Delete,
+ context_path = "/api",
+ description = "Deletes the specified album.",
+ responses(
+ (status = 200, description = "Delete existing album", body = Response),
+ (status = 400, description = "Errors found or album not found"),
+ (status = 401, description = "Authentication failed"),
+ ),
+ security(
+ {"bearer_auth" = []}
+ ),
+)]
#[delete("/album")]
pub async fn delete_album(
app_state: web::Data<AppState>,
diff --git a/src/api/artist.rs b/src/api/artist.rs
index d36ccf4..1fdae37 100644
--- a/src/api/artist.rs
+++ b/src/api/artist.rs
@@ -5,14 +5,24 @@ use crate::extractors::auth_token::AuthenticationToken;
use crate::AppState;
use actix_web::{delete, get, post, put, web, HttpResponse};
use serde::Deserialize;
+use utoipa::IntoParams;
/* Possible arguments ( /artist?arg=value ) */
-#[derive(Deserialize)]
-struct ArtistQueryOptions {
+#[derive(Deserialize, IntoParams)]
+pub struct ArtistQueryOptions {
id: Option<String>,
name: Option<String>,
}
+#[utoipa::path(
+ params(ArtistQueryOptions),
+ context_path = "/api",
+ description = "Gets a list of the current artists and applies filters based on the url parameters recieved. It only accepts one parameter at a time.",
+ responses(
+ (status = 200, description = "Return a list of artists", body = Vec<Artist>),
+ (status = 400, description = "Errors found, unfulfilled request"),
+ ),
+)]
#[get("/artist")]
pub async fn get_artist(
app_state: web::Data<AppState>,
@@ -48,6 +58,19 @@ pub async fn get_artist(
}
}
+#[utoipa::path(
+ request_body = ArtistPost,
+ context_path = "/api",
+ description = "Creates a new artist with the specified name.",
+ responses(
+ (status = 200, description = "Create new artist", body = Response),
+ (status = 400, description = "Errors found, unfulfilled request"),
+ (status = 401, description = "Authentication failed"),
+ ),
+ security(
+ {"bearer_auth" = []}
+ ),
+)]
#[post("/artist")]
pub async fn post_artist(
app_state: web::Data<AppState>,
@@ -63,6 +86,19 @@ pub async fn post_artist(
)
}
+#[utoipa::path(
+ request_body = ArtistPut,
+ context_path = "/api",
+ description = "Edits the name of the specified artist.",
+ responses(
+ (status = 200, description = "Edit artist name", body = Response),
+ (status = 400, description = "Errors found or artist not found"),
+ (status = 401, description = "Authentication failed"),
+ ),
+ security(
+ {"bearer_auth" = []}
+ ),
+)]
#[put("/artist")]
pub async fn put_artist(
app_state: web::Data<AppState>,
@@ -78,6 +114,19 @@ pub async fn put_artist(
)
}
+#[utoipa::path(
+ request_body = Delete,
+ context_path = "/api",
+ description = "Deletes the specified artist.",
+ responses(
+ (status = 200, description = "Delete existing artist", body = Response),
+ (status = 400, description = "Errors found or artist not found"),
+ (status = 401, description = "Authentication failed"),
+ ),
+ security(
+ {"bearer_auth" = []}
+ ),
+)]
#[delete("/artist")]
pub async fn delete_artist(
app_state: web::Data<AppState>,
diff --git a/src/api/mod.rs b/src/api/mod.rs
index 2a7c3a8..fc97f47 100644
--- a/src/api/mod.rs
+++ b/src/api/mod.rs
@@ -1,5 +1,6 @@
use actix_web::{web, HttpResponse, Scope};
use serde::{Deserialize, Serialize};
+use utoipa::ToSchema;
pub mod album;
pub mod artist;
@@ -24,9 +25,10 @@ pub fn api_scope() -> Scope {
.service(search_results::search_results)
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, ToSchema)]
pub struct Response {
- message: String,
+ #[schema(default = "response")]
+ pub message: String,
}
pub fn get_response_from_query(
diff --git a/src/api/search_results.rs b/src/api/search_results.rs
index f53bce8..cd47054 100644
--- a/src/api/search_results.rs
+++ b/src/api/search_results.rs
@@ -4,12 +4,22 @@ use crate::database::song::Song;
use crate::AppState;
use actix_web::{get, web, HttpResponse};
use serde::Deserialize;
+use utoipa::IntoParams;
-#[derive(Deserialize)]
+#[derive(Deserialize, IntoParams)]
struct SearchQueryOptions {
name: Option<String>,
}
+#[utoipa::path(
+ params(SearchQueryOptions),
+ context_path = "/api",
+ description = "Performs a search based on the 'name' parameter and returns a list.",
+ responses(
+ (status = 200, description = "Return a list of artists, albums and songs"),
+ (status = 400, description = "Errors found, unfulfilled request"),
+ ),
+)]
#[get("/search-results")]
pub async fn search_results(
app_state: web::Data<AppState>,
diff --git a/src/api/song.rs b/src/api/song.rs
index 1fec41c..06bc4b6 100644
--- a/src/api/song.rs
+++ b/src/api/song.rs
@@ -5,9 +5,10 @@ use crate::extractors::auth_token::AuthenticationToken;
use crate::AppState;
use actix_web::{delete, get, post, put, web, HttpResponse};
use serde::Deserialize;
+use utoipa::IntoParams;
/* Possible arguments ( /song?arg=value ) */
-#[derive(Deserialize)]
+#[derive(Deserialize, IntoParams)]
struct SongQueryOptions {
id: Option<String>,
name: Option<String>,
@@ -15,6 +16,15 @@ struct SongQueryOptions {
album: Option<String>,
}
+#[utoipa::path(
+ params(SongQueryOptions),
+ context_path = "/api",
+ description = "Gets a list of the current songs and applies filters based on the url parameters recieved. It only accepts one parameter at a time.",
+ responses(
+ (status = 200, description = "Return a list of songs", body = Vec<Song>),
+ (status = 400, description = "Errors found, unfulfilled request"),
+ ),
+)]
#[get("/song")]
pub async fn get_song(
app_state: web::Data<AppState>,
@@ -58,6 +68,19 @@ pub async fn get_song(
}
}
+#[utoipa::path(
+ request_body = SongPost,
+ context_path = "/api",
+ description = "Creates a new song with the specified values.",
+ responses(
+ (status = 200, description = "Create new song", body = Response),
+ (status = 400, description = "Errors found, unfulfilled request"),
+ (status = 401, description = "Authentication failed"),
+ ),
+ security(
+ {"bearer_auth" = []}
+ ),
+)]
#[post("/song")]
pub async fn post_song(
app_state: web::Data<AppState>,
@@ -73,6 +96,19 @@ pub async fn post_song(
)
}
+#[utoipa::path(
+ request_body = SongPut,
+ context_path = "/api",
+ description = "Edits the values of the specified song.",
+ responses(
+ (status = 200, description = "Edit song values", body = Response),
+ (status = 400, description = "Errors found or song not found"),
+ (status = 401, description = "Authentication failed"),
+ ),
+ security(
+ {"bearer_auth" = []}
+ ),
+)]
#[put("/song")]
pub async fn put_song(
app_state: web::Data<AppState>,
@@ -88,6 +124,19 @@ pub async fn put_song(
)
}
+#[utoipa::path(
+ request_body = Delete,
+ context_path = "/api",
+ description = "Deletes the specified song.",
+ responses(
+ (status = 200, description = "Delete existing song", body = Response),
+ (status = 400, description = "Errors found or song not found"),
+ (status = 401, description = "Authentication failed"),
+ ),
+ security(
+ {"bearer_auth" = []}
+ ),
+)]
#[delete("/song")]
pub async fn delete_song(
app_state: web::Data<AppState>,