diff options
author | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-26 19:11:24 +0100 |
---|---|---|
committer | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2025-01-26 19:11:24 +0100 |
commit | c622eab39ac7dd9f794b5d60eb937e29c9b3bd6e (patch) | |
tree | a75067a661250a4ed74096929083948f65c01fdb /src/api/artist.rs | |
parent | 5891af7e8c1411029fe1ad9c6d3182f88bcf3dfd (diff) |
add api documentation
Diffstat (limited to 'src/api/artist.rs')
-rw-r--r-- | src/api/artist.rs | 53 |
1 files changed, 51 insertions, 2 deletions
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>, |