Skip to content

Commit

Permalink
Removed all locks from service configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTV12345 committed Dec 24, 2024
1 parent b4d7522 commit d3dceb3
Show file tree
Hide file tree
Showing 21 changed files with 171 additions and 404 deletions.
10 changes: 2 additions & 8 deletions src/command_line_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub async fn start_command_line(mut args: Args) {

match podcast_rss_feed {
Some(feed) => {
let mut podcast_service = PodcastService::new();
let conn = &mut get_connection();

let replaced_feed = feed.replace(['\'', ' '], "");
Expand All @@ -53,9 +52,7 @@ pub async fn start_command_line(mut args: Args) {

PodcastEpisodeService::insert_podcast_episodes(podcast.clone())
.unwrap();
podcast_service
.schedule_episode_download(podcast, None)
.unwrap();
PodcastService::schedule_episode_download(podcast, None).unwrap();
}
None => {
println!("Please provide a podcast rss feed url");
Expand All @@ -65,14 +62,11 @@ pub async fn start_command_line(mut args: Args) {
}
"refresh-all" => {
let podcasts = Podcast::get_all_podcasts();
let mut podcast_service = PodcastService::new();
for podcast in podcasts.unwrap() {
println!("Refreshing podcast {}", podcast.name);

PodcastEpisodeService::insert_podcast_episodes(podcast.clone()).unwrap();
podcast_service
.schedule_episode_download(podcast, None)
.unwrap();
PodcastService::schedule_episode_download(podcast, None).unwrap();
}
}
"list" => {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/api_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::models::misc_models::{
};
use crate::models::notification::Notification;
use crate::models::opml_model::OpmlModel;
use crate::models::podcast_dto::PodcastDto;
use crate::models::podcast_episode::PodcastEpisode;
use crate::models::settings::Setting;
use crate::models::tag::Tag;
Expand All @@ -35,7 +36,6 @@ use utoipa::{
openapi::security::{ApiKey, ApiKeyValue, SecurityScheme},
Modify, OpenApi,
};
use crate::models::podcast_dto::PodcastDto;

#[derive(OpenApi)]
#[openapi(
Expand Down
18 changes: 3 additions & 15 deletions src/controllers/notification_controller.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use crate::models::notification::Notification;
use crate::mutex::LockResultExt;
use crate::service::notification_service::NotificationService;
use crate::utils::error::CustomError;
use actix_web::web::Data;
use actix_web::{get, put, web, HttpResponse};
use std::sync::Mutex;
use utoipa::ToSchema;
#[utoipa::path(
context_path="/api/v1",
Expand All @@ -13,13 +10,8 @@ responses(
tag="notifications"
)]
#[get("/notifications/unread")]
pub async fn get_unread_notifications(
notification_service: Data<Mutex<NotificationService>>,
) -> Result<HttpResponse, CustomError> {
let notifications = notification_service
.lock()
.ignore_poison()
.get_unread_notifications()?;
pub async fn get_unread_notifications() -> Result<HttpResponse, CustomError> {
let notifications = NotificationService::get_unread_notifications()?;
Ok(HttpResponse::Ok().json(notifications))
}

Expand All @@ -37,11 +29,7 @@ tag="notifications"
#[put("/notifications/dismiss")]
pub async fn dismiss_notifications(
id: web::Json<NotificationId>,
notification_service: Data<Mutex<NotificationService>>,
) -> Result<HttpResponse, CustomError> {
notification_service
.lock()
.ignore_poison()
.update_status_of_notification(id.id, "dismissed")?;
NotificationService::update_status_of_notification(id.id, "dismissed")?;
Ok(HttpResponse::Ok().body(""))
}
Loading

0 comments on commit d3dceb3

Please sign in to comment.