Skip to content

Commit

Permalink
Merge pull request #1212 from YuliaProkopovych/unitore
Browse files Browse the repository at this point in the history
READY(unitore): Separate entities
  • Loading branch information
Wandalen authored Mar 19, 2024
2 parents 7fe345e + 4539324 commit 98d1c3b
Show file tree
Hide file tree
Showing 20 changed files with 510 additions and 685 deletions.
5 changes: 3 additions & 2 deletions module/move/unitore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Feed reader with the ability to set updates frequency.
categories = [ "development-tools" ]
keywords = [ "rss-feed", "atom-feed" ]

[lints]
workspace = true
# [lints]
# workspace = true

[package.metadata.docs.rs]
features = [ "full" ]
Expand All @@ -39,6 +39,7 @@ http-body-util = "0.1"
feed-rs = "1.4.0"
toml = "0.8.10"
serde = "1.0.196"
url = { version = "2.0", features = ["serde"] }
humantime-serde = "1.1.1"
gluesql = "0.15.0"
async-trait = "0.1.41"
Expand Down
32 changes: 27 additions & 5 deletions module/move/unitore/src/executor/actions/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use crate::*;
use super::*;
use error_tools::{ err, for_app::Context, BasicError, Result };
use executor::FeedManager;
use storage::{ FeedStorage, FeedStore, config::{ ConfigStore, Config } };
use storage::
{
FeedStorage,
feed::{ FeedStore, Feed },
config::{ ConfigStore, Config },
};
use gluesql::{ prelude::Payload, sled_storage::SledStorage };

/// Add configuration file with subscriptions to storage.
Expand All @@ -15,9 +20,26 @@ pub async fn add_config( storage : FeedStorage< SledStorage >, args : &wca::Args
.ok_or_else::< BasicError, _ >( || err!( "Cannot get path argument for command .config.add" ) )?
.into()
;
let path = path.canonicalize().context( format!( "Invalid path for config file {:?}", path ) )?;
let config = Config::new( path.to_string_lossy().to_string() );

let mut err_str = format!( "Invalid path for config file {:?}", path );

let start = path.components().next();
if let Some( start ) = start
{
let abs_path : &std::path::Path = start.as_ref();
let abs_path = abs_path.canonicalize();
if let Ok( mut abs_path ) = abs_path
{
for component in path.components().skip( 1 )
{
abs_path.push( component );
}
err_str = format!( "Invalid path for config file {:?}", abs_path );
}
}
let path = path.canonicalize().context( err_str )?;

let config = Config::new( path.to_string_lossy().to_string() );
let mut manager = FeedManager::new( storage );

let config_report = manager.storage
Expand All @@ -28,11 +50,11 @@ pub async fn add_config( storage : FeedStorage< SledStorage >, args : &wca::Args

let feeds = feed_config::read( config.path() )?
.into_iter()
.map( | feed | crate::storage::model::FeedRow::new( feed.link, feed.update_period ) )
.map( | feed | Feed::new( feed.link, feed.update_period ) )
.collect::< Vec< _ > >()
;

let new_feeds = manager.storage.add_feeds( feeds ).await?;
let new_feeds = manager.storage.save_feeds( feeds ).await?;

Ok( ConfigReport{ payload : config_report, new_feeds : Some( new_feeds ) } )
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::*;
use executor::
{
FeedManager,
actions::{ Report, frames::SelectedEntries },
actions::{ Report, frame::SelectedEntries },
};
use storage::{ FeedStorage, FeedStore };
use storage::{ FeedStorage, feed::FeedStore };
use error_tools::Result;

/// List all feeds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use executor::FeedManager;
use storage::
{
FeedStorage,
feed::FeedStore,
config::ConfigStore,
frame::{ FrameStore, RowValue }
};
Expand Down Expand Up @@ -59,13 +60,21 @@ pub async fn download_frames

if subscriptions.is_empty()
{
return Err( err!( format!(
"Failed to download frames.\n Config files {} contain no feed subscriptions!",
return Err( err!( format!
(
"Failed to download frames.\n Config file(s) {} contain no feed subscriptions!",
configs.join( ", " )
) ) )
}

manager.update_feed( subscriptions ).await
let mut feeds = Vec::new();
let client = retriever::FeedClient;
for i in 0..subscriptions.len()
{
let feed = retriever::FeedFetch::fetch(&client, subscriptions[ i ].link.clone()).await?;
feeds.push( ( feed, subscriptions[ i ].update_period.clone(), subscriptions[ i ].link.clone() ) );
}
manager.storage.process_feeds( feeds ).await

}

Expand Down
4 changes: 2 additions & 2 deletions module/move/unitore/src/executor/actions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Endpoint for command execution.
pub mod frames;
pub mod feeds;
pub mod frame;
pub mod feed;
pub mod config;
pub mod query;
pub mod table;
Expand Down
7 changes: 4 additions & 3 deletions module/move/unitore/src/executor/actions/query.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! Query command endpoint and report.
use crate::*;
use super::*;
use gluesql::core::executor::Payload;
use super::Report;
use storage::{ FeedStorage, FeedStore };
use storage::{ FeedStorage, Store };
use executor::FeedManager;
use error_tools::{ err, BasicError, Result };

/// Execute query specified in query string.
pub async fn execute_query(
pub async fn execute_query
(
storage : FeedStorage< gluesql::sled_storage::SledStorage >,
args : &wca::Args,
) -> Result< impl Report >
Expand Down
Loading

0 comments on commit 98d1c3b

Please sign in to comment.