summaryrefslogtreecommitdiff
path: root/src/api/song.rs
diff options
context:
space:
mode:
authorniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2025-01-25 13:30:27 +0100
committerniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2025-01-25 13:30:27 +0100
commitef604ccb6e86b77517a78547bb50cdf9b82e03f0 (patch)
treeaf490a61546a38ad1fbb40e43e985cc6ff82fd34 /src/api/song.rs
parentc2786c4b9d704128da80ce4ed6513b9f5507b680 (diff)
add required authentication
Diffstat (limited to 'src/api/song.rs')
-rw-r--r--src/api/song.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/api/song.rs b/src/api/song.rs
index 698f27a..3748210 100644
--- a/src/api/song.rs
+++ b/src/api/song.rs
@@ -1,5 +1,6 @@
use crate::api::{get_response_from_query, Response};
use crate::database::{Delete, Song, SongPost, SongPut};
+use crate::extractors::auth_token::AuthenticationToken;
use crate::AppState;
use actix_web::{delete, get, post, put, web, HttpResponse};
use serde::Deserialize;
@@ -60,9 +61,13 @@ pub async fn get_song(
pub async fn post_song(
app_state: web::Data<AppState>,
request_data: web::Json<SongPost>,
+ _auth_token: AuthenticationToken,
) -> HttpResponse {
get_response_from_query(
- app_state.database.create_song(request_data.into_inner()).await,
+ app_state
+ .database
+ .create_song(request_data.into_inner())
+ .await,
"POST".to_string(),
)
}
@@ -71,9 +76,13 @@ pub async fn post_song(
pub async fn put_song(
app_state: web::Data<AppState>,
request_data: web::Json<SongPut>,
+ _auth_token: AuthenticationToken,
) -> HttpResponse {
get_response_from_query(
- app_state.database.edit_song(request_data.into_inner()).await,
+ app_state
+ .database
+ .edit_song(request_data.into_inner())
+ .await,
"PUT".to_owned(),
)
}
@@ -82,6 +91,7 @@ pub async fn put_song(
pub async fn delete_song(
app_state: web::Data<AppState>,
request_data: web::Json<Delete>,
+ _auth_token: AuthenticationToken,
) -> HttpResponse {
/* Check if ID is valid (return -1 if invalid) */
let id: i32 = request_data