Skip to content

Commit c467551

Browse files
committed
some working
1 parent 81aed55 commit c467551

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2893
-239
lines changed

Cargo.lock

+306-31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ members = [
1212
"crates/jz-iris",
1313
"crates/jz-jobs",
1414
"crates/jz-migration",
15-
"crates/jz-model",
15+
"crates/jz-model", "crates/jz-model-sqlx",
1616
"crates/jz-module",
1717
"crates/jz-openapi", "crates/jz-service",
1818
"crates/jz-smart",
@@ -47,6 +47,9 @@ jz-jobs = { path = "crates/jz-jobs" }
4747
jz-email = { path = "crates/jz-email" }
4848
jz-migration = { path = "crates/jz-migration" }
4949
jz-dragonfly = { path = "crates/jz-dragonfly" }
50+
jz-iris = { path = "crates/jz-iris" }
51+
jz-service = { path = "crates/jz-service" }
52+
jz-model-sqlx = { path = "crates/jz-model-sqlx" }
5053
[dependencies]
5154
tokio = { version = "1", features = ["full"] }
5255
tracing = "0.1.41"
@@ -75,6 +78,11 @@ workspace = true
7578
workspace = true
7679
[dependencies.jz-migration]
7780
workspace = true
78-
7981
[dependencies.jz-dragonfly]
8082
workspace = true
83+
[dependencies.jz-iris]
84+
workspace = true
85+
[dependencies.jz-service]
86+
workspace = true
87+
[dependencies.jz-model-sqlx]
88+
workspace = true

crates/jz-api/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ workspace = true
4949
workspace = true
5050

5151
[dependencies.jz-openapi]
52+
workspace = true
53+
[dependencies.jz-service]
5254
workspace = true

crates/jz-api/src/lib.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ use jz_module::AppModule;
77

88
pub mod utils;
99
pub mod v1;
10+
pub mod v2;
1011
pub use actix_settings::*;
1112
use actix_web::cookie::time::Duration;
1213
use actix_web::cookie::Key;
1314
use jz_dragonfly::Dragonfly;
1415
use log::info;
1516
use lazy_static::lazy_static;
17+
use jz_service::app::AppService;
1618

1719
pub struct Api {
1820
pub module: AppModule,
1921
pub config: Settings,
22+
pub service: AppService,
2023
}
2124

2225
lazy_static!{
@@ -25,8 +28,8 @@ lazy_static!{
2528

2629

2730
impl Api {
28-
pub fn init(module: AppModule, config: Settings) -> Api {
29-
Api { module, config }
31+
pub fn init(module: AppModule, config: Settings, service: AppService) -> Api {
32+
Api { module, config , service }
3033
}
3134
pub async fn run(&self) -> anyhow::Result<()> {
3235
use anyhow::Context;
@@ -57,7 +60,16 @@ impl Api {
5760
.build()
5861
)
5962
.route("/", actix_web::web::get().to(|| async { "Hello World!" }))
60-
.service(scope("/api").configure(v1::v1_route))
63+
.service(
64+
scope("/api")
65+
.service(
66+
scope("/v1")
67+
.configure(v1::v1_route)
68+
)
69+
.service(
70+
scope("/v2")
71+
)
72+
)
6173
.service(scope("/git").configure(jz_smart::git_router))
6274
.service(scope("/openapi").configure(jz_openapi::openapi_router))
6375
})
@@ -68,20 +80,4 @@ impl Api {
6880
.context("Failed to run actix service")?;
6981
Ok(())
7082
}
71-
}
72-
73-
#[cfg(test)]
74-
mod tests {
75-
use crate::Api;
76-
use jz_module::AppModule;
77-
78-
#[tokio::test]
79-
async fn test_api() -> anyhow::Result<()> {
80-
let module = AppModule::init_env().await.expect("Failed to init module");
81-
let _api = Api::init(module, actix_settings::Settings::from_default_template());
82-
dbg!("APi Init Ok");
83-
// _api.run().await?;
84-
dbg!("APi End Ok");
85-
Ok(())
86-
}
87-
}
83+
}

crates/jz-api/src/v1/mod.rs

+95-97
Original file line numberDiff line numberDiff line change
@@ -10,103 +10,101 @@ pub mod issues;
1010
mod explore;
1111

1212
pub fn v1_route(config: &mut actix_web::web::ServiceConfig) {
13-
config.service(
14-
scope("/v1")
15-
.route("", get().to(v1_hello))
16-
.route("/explore", get().to(explore::explore))
17-
.route("/check/{name}", get().to(utils::check_name::check_name))
18-
.service(
19-
scope("/merge").route("/users/{username}", get().to(merge::users::merge_users)),
20-
)
21-
.service(
22-
scope("/users")
23-
.route("/sigck", post().to(users::sigops::sigin_check_by_username))
24-
.route("/sigin", post().to(users::sigops::sigin)) // must captcha
25-
.route("/sigup", post().to(users::sigops::sigup)) // must captcha
26-
.route("/sigout", post().to(users::sigops::sigout))
27-
.route("/check", get().to(users::sigops::sigin_check))
28-
.route("/profile",post().to(users::profile::update_profile::update_profile))
29-
.route("/profile", get().to(users::profile::get_profile::get_profile))
30-
.route("/orgs", post().to(org::member::list::org_owner_list))
31-
.route("/passwd",post().to(users::passwd::update_password::update_password))
32-
.route("/ssh_key",post().to(users::ssh_key::create_owner_ssh_token))
33-
.route("/ssh_key",get().to(users::ssh_key::list_owner_ssh_key))
34-
.route("/ssh_key/{uid}",delete().to(users::ssh_key::delete_owner_ssh_token))
35-
.route("/token",post().to(users::token::create_owner_token))
36-
.route("/token",get().to(users::token::list_owner_token))
37-
.route("/token",delete().to(users::token::delete_owner_token))
38-
.service(
39-
scope("/{owner}")
40-
.route("/repo", post().to(repo::list::repo_user_list))
41-
.route("/orgs", post().to(org::member::list::org_user_list))
42-
)
43-
)
44-
.service(
45-
scope("/context")
46-
.route("/current", get().to(users::context::current_context))
47-
.route("/list", get().to(users::context::list_context))
48-
.route("/switch/{uid}", post().to(users::context::switch_context)),
49-
)
50-
.service(
51-
scope("/utils")
52-
.route("/base64_captcha", get().to(utils::base64_captcha::utils_captcha))
53-
.route("/email_captcha_send", post().to(utils::email_captcha::email_captcha))
54-
.route("/email_captcha_check", post().to(utils::email_captcha::email_captcha_check)),
55-
)
56-
.service(
57-
scope("/repo")
58-
.route("", post().to(repo::init::repo_init))
59-
.route("/access", post().to(repo::init::repo_access))
60-
.service(
61-
scope("/{owner}/{repo}")
62-
.route("", post().to(repo::info::repo_info))
63-
.route("/blob", post().to(repo::fsops::blob::repo_blob))
64-
.route("/star", post().to(repo::soc::star::repo_star))
65-
.route("/watch", post().to(repo::soc::watch::repo_watch))
66-
.route("/can_setting", get().to(repo::info::repo_can_setting))
67-
.service(
68-
scope("/branch")
69-
.route("/list", get().to(repo::fsops::branch::list_branch))
70-
.route("/create", post().to(repo::fsops::branch::create_branch))
71-
.route(
72-
"/delete/{name}",
73-
post().to(repo::fsops::branch::delete_branch),
74-
)
75-
.route(
76-
"/rename/{name}/{new_name}",
77-
post().to(repo::fsops::branch::rename_branch),
78-
)
79-
.route(
80-
"/checkout/{name}",
81-
post().to(repo::fsops::branch::checkout_head),
82-
),
83-
)
84-
.service(
85-
scope("/tree")
86-
.route("/list", post().to(repo::fsops::tree::repo_tree))
87-
.route(
88-
"/message",
89-
post().to(repo::fsops::tree::repo_tree_message),
90-
),
91-
),
92-
),
93-
)
94-
.service(
95-
scope("/static")
96-
.route("/upload_avatar", post().to(rstatic::avatar::upload_avatar))
97-
.route("/img/{path}", get().to(rstatic::avatar::down_avatar))
98-
)
99-
.service(
100-
scope("/orgs")
101-
.route("",post().to(org::create::create_org))
102-
.service(
103-
scope("/{org}")
104-
.route("", get().to(org::info::org_info))
105-
.route("/can_setting", get().to(org::info::org_can_setting))
106-
.route("/member",post().to(org::member::list::org_member_list))
107-
)
108-
)
109-
);
13+
config
14+
.route("", get().to(v1_hello))
15+
.route("/explore", get().to(explore::explore))
16+
.route("/check/{name}", get().to(utils::check_name::check_name))
17+
.service(
18+
scope("/merge").route("/users/{username}", get().to(merge::users::merge_users)),
19+
)
20+
.service(
21+
scope("/users")
22+
.route("/sigck", post().to(users::sigops::sigin_check_by_username))
23+
.route("/sigin", post().to(users::sigops::sigin)) // must captcha
24+
.route("/sigup", post().to(users::sigops::sigup)) // must captcha
25+
.route("/sigout", post().to(users::sigops::sigout))
26+
.route("/check", get().to(users::sigops::sigin_check))
27+
.route("/profile",post().to(users::profile::update_profile::update_profile))
28+
.route("/profile", get().to(users::profile::get_profile::get_profile))
29+
.route("/orgs", post().to(org::member::list::org_owner_list))
30+
.route("/passwd",post().to(users::passwd::update_password::update_password))
31+
.route("/ssh_key",post().to(users::ssh_key::create_owner_ssh_token))
32+
.route("/ssh_key",get().to(users::ssh_key::list_owner_ssh_key))
33+
.route("/ssh_key/{uid}",delete().to(users::ssh_key::delete_owner_ssh_token))
34+
.route("/token",post().to(users::token::create_owner_token))
35+
.route("/token",get().to(users::token::list_owner_token))
36+
.route("/token",delete().to(users::token::delete_owner_token))
37+
.service(
38+
scope("/{owner}")
39+
.route("/repo", post().to(repo::list::repo_user_list))
40+
.route("/orgs", post().to(org::member::list::org_user_list))
41+
)
42+
)
43+
.service(
44+
scope("/context")
45+
.route("/current", get().to(users::context::current_context))
46+
.route("/list", get().to(users::context::list_context))
47+
.route("/switch/{uid}", post().to(users::context::switch_context)),
48+
)
49+
.service(
50+
scope("/utils")
51+
.route("/base64_captcha", get().to(utils::base64_captcha::utils_captcha))
52+
.route("/email_captcha_send", post().to(utils::email_captcha::email_captcha))
53+
.route("/email_captcha_check", post().to(utils::email_captcha::email_captcha_check)),
54+
)
55+
.service(
56+
scope("/repo")
57+
.route("", post().to(repo::init::repo_init))
58+
.route("/access", post().to(repo::init::repo_access))
59+
.service(
60+
scope("/{owner}/{repo}")
61+
.route("", post().to(repo::info::repo_info))
62+
.route("/blob", post().to(repo::fsops::blob::repo_blob))
63+
.route("/star", post().to(repo::soc::star::repo_star))
64+
.route("/watch", post().to(repo::soc::watch::repo_watch))
65+
.route("/can_setting", get().to(repo::info::repo_can_setting))
66+
.service(
67+
scope("/branch")
68+
.route("/list", get().to(repo::fsops::branch::list_branch))
69+
.route("/create", post().to(repo::fsops::branch::create_branch))
70+
.route(
71+
"/delete/{name}",
72+
post().to(repo::fsops::branch::delete_branch),
73+
)
74+
.route(
75+
"/rename/{name}/{new_name}",
76+
post().to(repo::fsops::branch::rename_branch),
77+
)
78+
.route(
79+
"/checkout/{name}",
80+
post().to(repo::fsops::branch::checkout_head),
81+
),
82+
)
83+
.service(
84+
scope("/tree")
85+
.route("/list", post().to(repo::fsops::tree::repo_tree))
86+
.route(
87+
"/message",
88+
post().to(repo::fsops::tree::repo_tree_message),
89+
),
90+
),
91+
),
92+
)
93+
.service(
94+
scope("/static")
95+
.route("/upload_avatar", post().to(rstatic::avatar::upload_avatar))
96+
.route("/img/{path}", get().to(rstatic::avatar::down_avatar))
97+
)
98+
.service(
99+
scope("/orgs")
100+
.route("",post().to(org::create::create_org))
101+
.service(
102+
scope("/{org}")
103+
.route("", get().to(org::info::org_info))
104+
.route("/can_setting", get().to(org::info::org_can_setting))
105+
.route("/member",post().to(org::member::list::org_member_list))
106+
)
107+
);
110108
}
111109

112110
async fn v1_hello() -> String {

0 commit comments

Comments
 (0)