pub struct Breaks { /* private fields */ }Expand description
Database operations for manual break management.
Provides CRUD operations for break records with proper error handling and integration with the existing database infrastructure.
Implementations§
Source§impl Breaks
impl Breaks
Sourcepub fn insert(&self, break_record: &Break) -> Result<i64>
pub fn insert(&self, break_record: &Break) -> Result<i64>
Insert a new break record into the database.
Creates a new break record with the provided information. The break duration is calculated and stored automatically based on start and end times.
§Arguments
break_record- The break information to insert
§Returns
Returns Ok(()) on successful insertion, or an error if the database
operation fails or validation errors occur.
§Examples
let break_record = Break {
id: None,
date: date,
start: start_time,
end: end_time,
duration: Duration::minutes(30),
reason: Some("Lunch break".to_string()),
created_at: None,
};
breaks_db.insert(&break_record)?;Sourcepub fn get_daily_breaks(&self, date: NaiveDate) -> Result<Vec<Break>>
pub fn get_daily_breaks(&self, date: NaiveDate) -> Result<Vec<Break>>
Retrieve all breaks for a specific date.
Returns all manual break records for the given date, ordered by start time. This is typically used for daily productivity calculations and reporting.
§Arguments
date- The date to retrieve breaks for
§Returns
Returns a vector of Break records for the specified date, or an error if the database query fails.
§Examples
let today = chrono::Local::now().date_naive();
let breaks = breaks_db.get_daily_breaks(today)?;Sourcepub fn delete(&self, id: i64) -> Result<()>
pub fn delete(&self, id: i64) -> Result<()>
Delete a break record by ID.
Removes a break record from the database. This is typically used for correcting mistakes or adjusting productivity calculations.
§Arguments
id- The ID of the break record to delete
§Returns
Returns Ok(()) on successful deletion, or an error if the record
doesn’t exist or the database operation fails.
§Examples
breaks_db.delete(break_id)?;