formatting and adding video model
This commit is contained in:
parent
de34c6818a
commit
887fc733e7
8 changed files with 196 additions and 84 deletions
|
@ -1,3 +1,8 @@
|
|||
use crate::model::Model;
|
||||
use crate::model::Modeling;
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::eyre::Result;
|
||||
use std::mem::replace;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
|
@ -9,9 +14,54 @@ pub struct Video {
|
|||
looping: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct VideoModel {
|
||||
videos: Vec<Video>
|
||||
impl Model<Video> {}
|
||||
|
||||
impl Modeling for Model<Video> {
|
||||
type Item = Video;
|
||||
|
||||
fn add_item(&mut self, item: Self::Item) -> Result<()> {
|
||||
self.items.push(item);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn add_to_db(&mut self, item: Self::Item) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn update_item(
|
||||
&mut self,
|
||||
item: Self::Item,
|
||||
index: i32,
|
||||
) -> Result<()> {
|
||||
if let Some(current_item) = self.items.get_mut(index as usize)
|
||||
{
|
||||
let _old_song = replace(current_item, item);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(eyre!(
|
||||
"Song doesn't exist in model. Id was {}",
|
||||
index
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn get_item(&self, index: i32) -> Option<&Self::Item> {
|
||||
self.items.get(index as usize)
|
||||
}
|
||||
|
||||
fn remove_item(&mut self, index: i32) -> Result<()> {
|
||||
self.items.remove(index as usize);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn insert_item(
|
||||
&mut self,
|
||||
item: Self::Item,
|
||||
index: i32,
|
||||
) -> Result<()> {
|
||||
self.items.insert(index as usize, item);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue