Fix build issue due to csv parsing

This commit is contained in:
Joshua Coles 2024-03-01 21:23:51 +00:00
parent ee21753411
commit f08397ab15

View File

@ -1,3 +1,4 @@
use anyhow::anyhow;
use chrono::{NaiveDate, NaiveTime};
use csv::StringRecord;
use crate::utils::Result;
@ -19,10 +20,10 @@ mod headings {
}
fn parse_csv_row(row: StringRecord) -> Result<crate::entity::time_entry::Model> {
let start_date = row.get(headings::START_DATE).unwrap();
let start_time = row.get(headings::START_TIME).unwrap();
let end_date = row.get(headings::END_DATE).unwrap();
let end_time = row.get(headings::END_TIME).unwrap();
let start_date = row.get(headings::START_DATE).ok_or(anyhow!("Missing start date in CSV"))?;
let start_time = row.get(headings::START_TIME).ok_or(anyhow!("Missing start time in CSV"))?;
let end_date = row.get(headings::END_DATE).ok_or(anyhow!("Missing end date in CSV"))?;
let end_time = row.get(headings::END_TIME).ok_or(anyhow!("Missing end time in CSV"))?;
let start_time = NaiveTime::parse_from_str(start_time, "%H:%M:%S")?;
let end_time = NaiveTime::parse_from_str(end_time, "%H:%M:%S")?;
@ -32,14 +33,16 @@ fn parse_csv_row(row: StringRecord) -> Result<crate::entity::time_entry::Model>
let start = start_date.and_time(start_time);
let end = end_date.and_time(end_time);
let description = row.get(headings::DESCRIPTION)?;
let project_name = row.get(headings::PROJECT_NAME)?;
let client_name = row.get(headings::CLIENT_NAME)?;
let tags = row.get(headings::TAGS)?;
let task_name = row.get(headings::TASK_NAME)?;
let billable = match row.get(headings::BILLABLE)? {
let description = row.get(headings::DESCRIPTION).ok_or(anyhow!("Missing description in CSV"))?;
let project_name = row.get(headings::PROJECT_NAME).ok_or(anyhow!("Missing project name in CSV"))?;
let client_name = row.get(headings::CLIENT_NAME).ok_or(anyhow!("Missing client name in CSV"))?;
let tags = row.get(headings::TAGS).ok_or(anyhow!("Missing tags in CSV"))?;
let task_name = row.get(headings::TASK_NAME).ok_or(anyhow!("Missing task name in CSV"))?;
let billable = match row.get(headings::BILLABLE).ok_or(anyhow!("Missing billable in CSV"))? {
"Yes" => true,
"No" => false,
_ => unimplemented!("Unknown billable value")
};
unimplemented!("Refactor model to support non-json sources")
}