Skip to content

Commit

Permalink
fix(file): Removed unwrap on user because he is always set
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTV12345 committed Dec 30, 2024
1 parent adb0b51 commit 55cabd4
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 112 deletions.
24 changes: 12 additions & 12 deletions src/controllers/playlist_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ tag="playlist"
)]
#[post("/playlist")]
pub async fn add_playlist(
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
playlist: web::Json<PlaylistDtoPost>,
) -> Result<HttpResponse, CustomError> {
let user = requester.unwrap().into_inner();
let user = requester.into_inner();
let playlist = playlist.into_inner();

let res = Playlist::create_new_playlist(playlist, user)?;
Expand All @@ -50,11 +50,11 @@ tag="playlist"
)]
#[put("/playlist/{playlist_id}")]
pub async fn update_playlist(
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
playlist: web::Json<PlaylistDtoPost>,
playlist_id: web::Path<String>,
) -> Result<HttpResponse, CustomError> {
let user = requester.unwrap().into_inner();
let user = requester.into_inner();
let playlist = playlist.into_inner();

let res = Playlist::update_playlist(playlist, playlist_id.clone(), user)?;
Expand All @@ -70,9 +70,9 @@ tag="playlist"
)]
#[get("/playlist")]
pub async fn get_all_playlists(
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
Playlist::get_playlists(requester.unwrap().into_inner().id)
Playlist::get_playlists(requester.into_inner().id)
.map(|playlists| HttpResponse::Ok().json(playlists))
}

Expand All @@ -84,10 +84,10 @@ tag="playlist"
)]
#[get("/playlist/{playlist_id}")]
pub async fn get_playlist_by_id(
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
playlist_id: web::Path<String>,
) -> Result<HttpResponse, CustomError> {
let user_id = requester.clone().unwrap();
let user_id = requester;
let playlist =
Playlist::get_playlist_by_user_and_id(playlist_id.clone(), user_id.clone().into_inner())?;
let playlist =
Expand All @@ -103,10 +103,10 @@ tag="playlist"
)]
#[delete("/playlist/{playlist_id}")]
pub async fn delete_playlist_by_id(
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
playlist_id: web::Path<String>,
) -> Result<HttpResponse, CustomError> {
let user_id = requester.clone().unwrap().id;
let user_id = requester.id;
Playlist::delete_playlist_by_id(playlist_id.clone(), user_id)?;
Ok(HttpResponse::Ok().json(()))
}
Expand All @@ -119,10 +119,10 @@ tag="playlist"
)]
#[delete("/playlist/{playlist_id}/episode/{episode_id}")]
pub async fn delete_playlist_item(
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
path: web::Path<(String, i32)>,
) -> Result<HttpResponse, CustomError> {
let user_id = requester.clone().unwrap().id;
let user_id = requester.id;
let unwrapped_path = path.into_inner();
Playlist::delete_playlist_item(unwrapped_path.0, unwrapped_path.1, user_id).await?;
Ok(HttpResponse::Ok().json(()))
Expand Down
74 changes: 37 additions & 37 deletions src/controllers/podcast_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ tag="podcasts"
)]
#[get("/podcasts/filter")]
pub async fn get_filter(
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
let filter = Filter::get_filter_by_username(requester.unwrap().username.clone()).await?;
let filter = Filter::get_filter_by_username(&requester.username).await?;
Ok(HttpResponse::Ok().json(filter))
}

Expand All @@ -72,22 +72,22 @@ tag="podcasts"
#[get("/podcasts/search")]
pub async fn search_podcasts(
query: web::Query<PodcastSearchModel>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
let query = query.into_inner();
let _order = query.order.unwrap_or(OrderCriteria::Asc);
let _latest_pub = query.order_option.unwrap_or(OrderOption::Title);
let tag = query.tag;

let opt_filter =
Filter::get_filter_by_username(requester.clone().unwrap().username.clone()).await?;
Filter::get_filter_by_username(&requester.username).await?;

let only_favored = match opt_filter {
Some(filter) => filter.only_favored,
None => true,
};

let username = requester.unwrap().username.clone();
let username = requester.username.clone();
let filter = Filter::new(
username.clone(),
query.title.clone(),
Expand Down Expand Up @@ -137,14 +137,14 @@ tag="podcasts"
#[get("/podcast/{id}")]
pub async fn find_podcast_by_id(
id: Path<String>,
user: Option<web::ReqData<User>>,
user: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
let id_num = from_str::<i32>(&id).unwrap();
let username = user.unwrap().username.clone();
let username = &user.username;

let podcast = PodcastService::get_podcast(id_num)?;
let tags = Tag::get_tags_of_podcast(id_num, &username)?;
let favorite = Favorite::get_favored_podcast_by_username_and_podcast_id(&username, id_num)?;
let tags = Tag::get_tags_of_podcast(id_num, username)?;
let favorite = Favorite::get_favored_podcast_by_username_and_podcast_id(username, id_num)?;
let podcast_dto: PodcastDto = (podcast, favorite, tags).into();
Ok(HttpResponse::Ok().json(podcast_dto))
}
Expand All @@ -158,9 +158,9 @@ tag="podcasts"
)]
#[get("/podcasts")]
pub async fn find_all_podcasts(
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
let username = requester.unwrap().username.clone();
let username = &requester.username;

let podcasts = PodcastService::get_podcasts(username)?;

Expand All @@ -177,9 +177,9 @@ tag="podcasts"
#[get("/podcasts/{type_of}/{podcast}/search")]
pub async fn find_podcast(
podcast_col: Path<(i32, String)>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}

Expand Down Expand Up @@ -215,9 +215,9 @@ tag="podcasts"
pub async fn add_podcast(
track_id: web::Json<PodcastAddModel>,
lobby: Data<ChatServerHandle>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}

Expand Down Expand Up @@ -261,9 +261,9 @@ tag="podcasts"
pub async fn add_podcast_by_feed(
rss_feed: web::Json<PodcastRSSAddModel>,
lobby: Data<ChatServerHandle>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}
let mut header_map = HeaderMap::new();
Expand Down Expand Up @@ -315,9 +315,9 @@ tag="podcasts"
pub async fn import_podcasts_from_opml(
opml: Json<OpmlModel>,
lobby: Data<ChatServerHandle>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}
let document = OPML::from_str(&opml.content).unwrap();
Expand Down Expand Up @@ -347,9 +347,9 @@ tag="podcasts"
pub async fn add_podcast_from_podindex(
id: web::Json<PodcastAddModel>,
lobby: Data<ChatServerHandle>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}

Expand Down Expand Up @@ -396,9 +396,9 @@ tag="podcasts"
#[post("/podcast/all")]
pub async fn refresh_all_podcasts(
lobby: Data<ChatServerHandle>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}

Expand Down Expand Up @@ -433,9 +433,9 @@ tag="podcasts"
pub async fn download_podcast(
id: Path<String>,
lobby: Data<ChatServerHandle>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}

Expand Down Expand Up @@ -471,12 +471,12 @@ tag="podcasts"
#[put("/podcast/favored")]
pub async fn favorite_podcast(
update_model: Json<PodcastFavorUpdateModel>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
PodcastService::update_favor_podcast(
update_model.id,
update_model.favored,
requester.unwrap().username.clone(),
&requester.username,
)?;
Ok(HttpResponse::Ok().json("Favorited podcast"))
}
Expand All @@ -489,9 +489,9 @@ tag="podcasts"
)]
#[get("/podcasts/favored")]
pub async fn get_favored_podcasts(
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
let podcasts = PodcastService::get_favored_podcasts(requester.unwrap().username.clone())?;
let podcasts = PodcastService::get_favored_podcasts(requester.username.clone())?;
Ok(HttpResponse::Ok().json(podcasts))
}

Expand All @@ -505,9 +505,9 @@ tag="podcasts"
#[put("/podcast/{id}/active")]
pub async fn update_active_podcast(
id: Path<String>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}

Expand Down Expand Up @@ -658,9 +658,9 @@ tag="podcasts"
pub async fn delete_podcast(
data: web::Json<DeletePodcast>,
id: Path<i32>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}

Expand Down Expand Up @@ -780,9 +780,9 @@ pub(crate) async fn proxy_podcast(
pub async fn update_podcast_settings(
id: Path<i32>,
settings: Json<PodcastSetting>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}

Expand All @@ -797,9 +797,9 @@ pub async fn update_podcast_settings(
#[get("/podcasts/{id}/settings")]
pub async fn get_podcast_settings(
id: Path<i32>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}

Expand Down
20 changes: 10 additions & 10 deletions src/controllers/podcast_episode_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ tag = "podcast_episodes"
#[get("/podcast/{id}/episodes")]
pub async fn find_all_podcast_episodes_of_podcast(
id: web::Path<String>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
last_podcast_episode: Query<OptionalId>,
) -> Result<HttpResponse, CustomError> {
let last_podcast_episode = last_podcast_episode.into_inner();
let id_num = from_str(&id).unwrap();
let res = PodcastEpisodeService::get_podcast_episodes_of_podcast(
id_num,
last_podcast_episode.last_podcast_episode,
requester.unwrap().into_inner(),
requester.into_inner(),
)?;
let mapped_podcasts = res
.into_iter()
Expand All @@ -78,9 +78,9 @@ pub struct TimeLinePodcastEpisode {

#[get("/podcast/available/gpodder")]
pub async fn get_available_podcasts_not_in_webview(
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}
let found_episodes = Episode::find_episodes_not_in_webview()?;
Expand Down Expand Up @@ -111,11 +111,11 @@ tag = "podcasts"
)]
#[get("/podcasts/timeline")]
pub async fn get_timeline(
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
favored_only: Query<TimelineQueryParams>,
) -> Result<HttpResponse, CustomError> {
let res = TimelineItem::get_timeline(
requester.unwrap().username.clone(),
requester.username.clone(),
favored_only.into_inner(),
)?;

Expand Down Expand Up @@ -153,9 +153,9 @@ tag = "podcast_episodes"
#[put("/podcast/{id}/episodes/download")]
pub async fn download_podcast_episodes_of_podcast(
id: web::Path<String>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}

Expand Down Expand Up @@ -184,10 +184,10 @@ tag = "podcast_episodes"
#[delete("/episodes/{id}/download")]
pub async fn delete_podcast_episode_locally(
id: web::Path<String>,
requester: Option<web::ReqData<User>>,
requester: web::ReqData<User>,
lobby: Data<ChatServerHandle>,
) -> Result<HttpResponse, CustomError> {
if !requester.unwrap().is_privileged_user() {
if !requester.is_privileged_user() {
return Err(CustomError::Forbidden);
}

Expand Down
Loading

0 comments on commit 55cabd4

Please sign in to comment.