Skip to content

Commit 0f821dd

Browse files
committed
Add Router
1 parent b926663 commit 0f821dd

File tree

10 files changed

+36
-24
lines changed

10 files changed

+36
-24
lines changed

__tests__/api/index.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ describe('api', () => {
1010
it('should return devup models', async () => {
1111
const res = await fetch('http://localhost:8000/devup-models')
1212
const data = await res.json()
13-
expect(data).toEqual(['Board', 'User'])
13+
expect(data).toEqual(
14+
expect.arrayContaining(['Board', 'User', 'GlobalInfo']),
15+
)
1416
})
1517
})

core/api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod auth;
33
pub mod router;
44

55
use crate::router::{
6-
AuthRouter, CrudRouter, CustomRouter, DevupRouter, ProxyRouter, SingletonRouter,
6+
AuthRouter, CrudRouter, CustomRouter, ProxyRouter, SingletonRouter,
77
};
88
use once_cell::sync::Lazy;
99
use schema::DevupSchema;

libs/python/core/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
mod py_utils;
22
mod router;
3-
use std::collections::HashSet;
43
use std::sync::Mutex;
54

6-
use crate::py_utils::get_route_path;
75
use crate::router::auth_router::{get_all_auth_routers, PyAuthRouter};
86
use crate::router::crud_router::{get_all_crud_routers, PyCrudRouter};
97
use crate::router::custom_router::{get_all_custom_routers, PyCustomRouter};
108
use crate::router::proxy_router::{get_all_proxy_routers, PyProxyRouter};
119
use crate::router::singleton_router::{get_all_singleton_routers, PySingletonRouter};
1210
use ::utils::collect_files;
13-
use api::{
14-
add_auth_router, add_crud_router, add_custom_router, add_model, add_proxy_router,
15-
add_singleton_router,
16-
};
11+
use api::add_model;
1712
use model::column::{DevupModelColumn, DevupModelColumnType, DevupModelFieldType};
1813
use model::DevupModel;
1914
use once_cell::sync::Lazy;

libs/python/core/src/py_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub fn convert_to_route_path(path: &str) -> String {
7272
result
7373
}
7474

75+
#[cfg(test)]
7576
mod tests {
7677
use super::*;
7778

libs/python/core/src/router/crud_router.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::py_utils::{convert_to_route_path, get_route_path};
2-
use crate::Model;
32
use api::add_crud_router;
43
use api::router::CrudRouter;
54
use pyo3::prelude::*;

libs/python/core/src/router/singleton_router.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
11
use api::{add_singleton_router, router::SingletonRouter};
2-
use pyo3::prelude::*;
2+
use pyo3::{prelude::*, types::PyType};
33
use std::sync::Arc;
44

5-
use crate::py_utils::get_route_path;
5+
use crate::py_utils::{convert_to_route_path, get_route_path};
66

77
// routes
88
#[pyclass(name = "SingletonRouter")]
99
pub struct PySingletonRouter(Arc<SingletonRouter>);
1010
#[pymethods]
1111
impl PySingletonRouter {
1212
#[new]
13-
fn new() -> PyResult<Self> {
13+
fn new(model: &Bound<'_, PyType>) -> PyResult<Self> {
14+
let model_name = model.getattr("name")?.extract::<String>()?;
15+
let path = convert_to_route_path(get_route_path()?.as_str());
1416
Ok(Self(
1517
add_singleton_router(SingletonRouter {
16-
path: get_route_path()?,
17-
name: "test".to_string(),
18-
model: "test".to_string(),
18+
path,
19+
name: model_name.clone(),
20+
model: model_name.clone(),
1921
default: Default::default(),
2022
route: Default::default(),
2123
auth: Default::default(),
2224
})
2325
.map_err(|e| PyErr::new::<pyo3::exceptions::PyValueError, _>(e.to_string()))?,
2426
))
2527
}
28+
29+
#[getter]
30+
fn path(&self) -> &str {
31+
&self.0.path
32+
}
33+
34+
#[getter]
35+
fn name(&self) -> &str {
36+
&self.0.name
37+
}
38+
39+
#[getter]
40+
fn model(&self) -> &str {
41+
&self.0.model
42+
}
2643
}
2744

2845
#[pyfunction]

project/python/fastapi/routes/(singleton)/global_info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from devup_api_core import SingletonRouter
2-
from devup_api_fastapi import GlobalInfo
2+
3+
from models.global_info import GlobalInfo
34

45
SingletonRouter(
56
GlobalInfo

sql/core/devup_database/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::time::Duration;
22

33
use sqlx::{
4-
Any, Database, Error, Executor, Pool, Transaction,
4+
Any, Error, Pool, Transaction,
55
any::{AnyPoolOptions, install_default_drivers},
66
};
77

sql/core/devup_sql/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,11 @@ pub fn generate_sql(
137137
fields.to_sql()
138138
}
139139

140+
#[cfg(test)]
140141
mod test {
141142

142-
use model::column::{
143-
DevupModelColumn, DevupModelColumnType, DevupModelFieldType, DevupModelRelation,
144-
};
145-
146143
use super::*;
144+
use model::column::{DevupModelColumn, DevupModelColumnType, DevupModelRelation};
147145

148146
#[test]
149147
fn test_generate_sql() {

sql/libs/node/pool/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ use std::collections::HashMap;
22

33
use devup_database::{DevupSqlPool, DevupSqlPoolOptions};
44
use napi::{
5-
Env, Error, JsUndefined, Result, Status, Task,
6-
bindgen_prelude::{AsyncTask, Undefined},
5+
Error, Result, Status,
76
};
8-
use sqlx::{Any, AnyConnection, Column, Execute, Executor, Pool, Row, Transaction, query};
7+
use sqlx::{Any, Column, Executor, Pool, Row, Transaction, query};
98

109
#[macro_use]
1110
extern crate napi_derive;

0 commit comments

Comments
 (0)