Skip to content

Commit 085b5dd

Browse files
committed
update
1 parent b4710af commit 085b5dd

File tree

1 file changed

+53
-61
lines changed
  • crates/rs-tauri-vue/src-tauri/src/service

1 file changed

+53
-61
lines changed
Lines changed: 53 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,69 @@
1+
use crate::{proto::TodoEntity, storage::AppStorage};
2+
13
pub struct AppService {
2-
// pub storage: AppStorage,
4+
pub storage: AppStorage,
35
}
46

57
impl AppService {
68
pub async fn new() -> Self {
7-
// let storage = AppStorage::new().await;
8-
// Self { storage }
9-
Self {}
9+
let storage = AppStorage::new().await;
10+
Self { storage }
11+
}
12+
13+
pub async fn add_todo(&self, todo: &TodoEntity) -> anyhow::Result<i64> {
14+
self.storage.sql.todo.add_todo(todo).await
1015
}
1116

12-
// pub async fn add_todo(&self, todo: &TodoEntity) -> anyhow::Result<i64> {
13-
// self.storage.sql.todo.add_todo(todo).await
14-
// }
15-
//
16-
// pub async fn get_todo(&self, id: i64) -> anyhow::Result<TodoEntity> {
17-
// self.storage.sql.todo.get_todo(id).await
18-
// }
17+
pub async fn get_todo(&self, id: i64) -> anyhow::Result<TodoEntity> {
18+
self.storage.sql.todo.get_todo(id).await
19+
}
1920
}
2021

2122
#[cfg(test)]
2223
mod test {
2324
use super::*;
2425

25-
// async fn setup() {
26-
// // let mut db = SqlConn::new("app.db").await;
27-
// let mut db = SqlConn::default().await;
28-
//
29-
// db.init_migrations().await;
30-
// }
26+
#[tokio::test]
27+
async fn test_new_service() {
28+
let service = AppService::new().await;
29+
30+
let ret = service
31+
.storage
32+
.sql
33+
.todo
34+
.add_todo(&TodoEntity {
35+
id: 0,
36+
title: "add todo, by service".to_string(),
37+
description: "test desc".to_string(),
38+
done: false,
39+
completed: false,
40+
})
41+
.await
42+
.unwrap();
3143

32-
// #[tokio::test]
33-
// async fn test_new_service() {
34-
// setup().await;
35-
//
36-
// let service = AppService::new().await;
37-
//
38-
// let ret = service
39-
// .storage
40-
// .sql
41-
// .todo
42-
// .add_todo(&TodoEntity {
43-
// id: 0,
44-
// title: "add todo, by service".to_string(),
45-
// description: "test desc".to_string(),
46-
// done: false,
47-
// completed: false,
48-
// })
49-
// .await
50-
// .unwrap();
51-
//
52-
// println!("service add todo: {}", ret);
53-
//
54-
// let todo = service.storage.sql.todo.get_todo(ret).await.unwrap();
55-
//
56-
// println!("service get todo: {:?}", todo);
57-
// }
44+
println!("service add todo: {}", ret);
5845

59-
// #[tokio::test]
60-
// async fn test_service_add_todo() {
61-
// let service = AppService::new().await;
62-
// let ret = service
63-
// .add_todo(&TodoEntity {
64-
// id: 0,
65-
// title: "add todo, by service api".to_string(),
66-
// description: "test desc".to_string(),
67-
// done: false,
68-
// completed: false,
69-
// })
70-
// .await
71-
// .unwrap();
72-
// println!("service add todo: {}", ret);
73-
//
74-
// let todo = service.get_todo(ret).await.unwrap();
75-
// println!("service get todo: {:?}", todo);
76-
// }
46+
let todo = service.storage.sql.todo.get_todo(ret).await.unwrap();
47+
48+
println!("service get todo: {:?}", todo);
49+
}
50+
51+
#[tokio::test]
52+
async fn test_service_add_todo() {
53+
let service = AppService::new().await;
54+
let ret = service
55+
.add_todo(&TodoEntity {
56+
id: 0,
57+
title: "add todo, by service api".to_string(),
58+
description: "test desc".to_string(),
59+
done: false,
60+
completed: false,
61+
})
62+
.await
63+
.unwrap();
64+
println!("service add todo: {}", ret);
65+
66+
let todo = service.get_todo(ret).await.unwrap();
67+
println!("service get todo: {:?}", todo);
68+
}
7769
}

0 commit comments

Comments
 (0)