-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod firestore; | ||
pub mod firestore_store; | ||
pub mod store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::async_trait; | ||
|
||
use crate::{ | ||
model::{self, CheckList}, | ||
use_case::{self, StoreTrait}, | ||
}; | ||
|
||
use super::firestore::client::Client; | ||
|
||
#[derive(serde::Deserialize, serde::Serialize)] | ||
pub struct CheckListDocumentData { | ||
pub date: String, | ||
pub id: String, | ||
} | ||
|
||
impl From<CheckListDocumentData> for model::CheckList { | ||
fn from(CheckListDocumentData { date, id }: CheckListDocumentData) -> Self { | ||
Self { date, id } | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct FirestoreStore { | ||
client: Arc<tokio::sync::Mutex<Client>>, | ||
} | ||
|
||
#[async_trait] | ||
impl StoreTrait for FirestoreStore { | ||
async fn find_all_check_lists(&self) -> Result<Vec<model::CheckList>, use_case::Error> { | ||
let mut client = self.client.lock().await; | ||
let collection_path = client.collection("check_lists").unwrap(); | ||
// TODO: unwrap | ||
// TODO: pagination | ||
Ok(client | ||
.list::<CheckListDocumentData>(&collection_path) | ||
.await | ||
.unwrap() | ||
.0 | ||
.into_iter() | ||
.map(|doc| doc.data()) | ||
.map(CheckList::from) | ||
.collect()) | ||
} | ||
|
||
async fn find_all_checks(&self) -> Result<Vec<model::Check>, use_case::Error> { | ||
todo!() | ||
} | ||
|
||
async fn find_all_items(&self) -> Result<Vec<model::Item>, use_case::Error> { | ||
todo!() | ||
} | ||
} |