diff --git a/Cargo.lock b/Cargo.lock index e3db0595..01289245 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,7 +88,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" dependencies = [ "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -201,7 +201,7 @@ dependencies = [ "actix-router", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -491,7 +491,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -540,7 +540,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -557,7 +557,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -594,7 +594,7 @@ dependencies = [ "attribute-derive-macro", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -610,7 +610,7 @@ dependencies = [ "proc-macro2", "quote", "quote-use", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -844,7 +844,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", "syn_derive", ] @@ -1065,7 +1065,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -1365,7 +1365,7 @@ checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -1508,7 +1508,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -1788,7 +1788,7 @@ checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -2277,7 +2277,7 @@ checksum = "ce243b1bfa62ffc028f1cc3b6034ec63d649f3031bc8a4fbbb004e1ac17d1f68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -2564,7 +2564,7 @@ dependencies = [ "quote", "rstml", "serde", - "syn 2.0.41", + "syn 2.0.48", "walkdir", ] @@ -2600,7 +2600,7 @@ dependencies = [ "quote", "rstml", "server_fn_macro", - "syn 2.0.41", + "syn 2.0.48", "tracing", "uuid", ] @@ -2706,6 +2706,17 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libredox" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607" +dependencies = [ + "bitflags 2.4.1", + "libc", + "redox_syscall", +] + [[package]] name = "libsqlite3-sys" version = "0.27.0" @@ -2808,7 +2819,7 @@ dependencies = [ "manyhow-macros", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -3051,6 +3062,12 @@ dependencies = [ "libc", ] +[[package]] +name = "numtoa" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" + [[package]] name = "object" version = "0.32.1" @@ -3089,7 +3106,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -3183,9 +3200,9 @@ dependencies = [ [[package]] name = "opentelemetry_sdk" -version = "0.21.1" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "968ba3f2ca03e90e5187f5e4f46c791ef7f2c163ae87789c8ce5f5ca3b7b7de5" +checksum = "2f16aec8a98a457a52664d69e0091bac3a0abd18ead9b641cb00202ba4e0efe4" dependencies = [ "async-trait", "crossbeam-channel", @@ -3242,7 +3259,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -3340,7 +3357,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -3452,7 +3469,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -3501,9 +3518,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] @@ -3516,7 +3533,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", "version_check", "yansi", ] @@ -3580,7 +3597,7 @@ dependencies = [ "prost 0.12.3", "prost-types 0.12.3", "regex", - "syn 2.0.41", + "syn 2.0.48", "tempfile", "which", ] @@ -3608,7 +3625,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -3669,9 +3686,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -3684,7 +3701,7 @@ checksum = "a7b5abe3fe82fdeeb93f44d66a7b444dedf2e4827defb0a8e69c437b2de2ef94" dependencies = [ "quote", "quote-use-macros", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -3696,7 +3713,7 @@ dependencies = [ "derive-where", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -3753,6 +3770,12 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_termios" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20145670ba436b55d91fc92d25e71160fbfbdd57831631c8d7d36377a476f1cb" + [[package]] name = "regex" version = "1.10.2" @@ -3941,7 +3964,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.41", + "syn 2.0.48", "syn_derive", "thiserror", ] @@ -4103,7 +4126,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -4161,7 +4184,7 @@ dependencies = [ "proc-macro2", "quote", "sea-bae", - "syn 2.0.41", + "syn 2.0.48", "unicode-ident", ] @@ -4225,7 +4248,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", "thiserror", ] @@ -4336,7 +4359,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -4421,7 +4444,7 @@ dependencies = [ "serde_json", "serde_qs", "server_fn_macro_default", - "syn 2.0.41", + "syn 2.0.48", "thiserror", "xxhash-rust", ] @@ -4437,7 +4460,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.41", + "syn 2.0.48", "xxhash-rust", ] @@ -4448,7 +4471,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7256ba61dfadb220598db418376e7bc2a34b96df36c4dc48f24ffe161810fc0b" dependencies = [ "server_fn_macro", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -4856,9 +4879,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.41" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -4874,7 +4897,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -4932,6 +4955,18 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "termion" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417813675a504dfbbf21bfde32c03e5bf9f2413999962b479023c02848c1c7a5" +dependencies = [ + "libc", + "libredox", + "numtoa", + "redox_termios", +] + [[package]] name = "testsuit" version = "0.1.0" @@ -4950,6 +4985,8 @@ dependencies = [ "rustls", "rustls-pki-types", "serde", + "termion", + "thiserror", "tokio", "tokio-rustls", "tokio-stream", @@ -4963,22 +5000,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -5092,7 +5129,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -5276,7 +5313,7 @@ dependencies = [ "proc-macro2", "prost-build 0.12.3", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -5393,7 +5430,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -5489,7 +5526,7 @@ checksum = "982ee4197351b5c9782847ef5ec1fdcaf50503fb19d68f9771adae314e72b492" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] @@ -5667,7 +5704,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", "wasm-bindgen-shared", ] @@ -5701,7 +5738,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5737,9 +5774,9 @@ dependencies = [ [[package]] name = "web-time" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57099a701fb3a8043f993e8228dc24229c7b942e2b009a1b962e54489ba1d3bf" +checksum = "aa30049b1c872b72c89866d458eae9f20380ab280ffd1b1e18df2d3e2d98cfe0" dependencies = [ "js-sys", "wasm-bindgen", @@ -6004,7 +6041,7 @@ checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.48", ] [[package]] diff --git a/backend/entity/src/problem.rs b/backend/entity/src/problem.rs index da0be414..9b431502 100644 --- a/backend/entity/src/problem.rs +++ b/backend/entity/src/problem.rs @@ -25,6 +25,7 @@ pub struct Model { #[sea_orm(column_type = "Time", on_update = "current_timestamp")] pub update_at: chrono::NaiveDateTime, pub match_rule: i32, + pub order: f32, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/backend/justfile b/backend/justfile index b87c5baf..755f525f 100644 --- a/backend/justfile +++ b/backend/justfile @@ -18,8 +18,9 @@ entity-codegen: release-docker: just prepare + cp ../Cargo.toml ws-Cargo.toml cp ../proto/*.proto . - docker build . --build-arg ARCH=$(uname -m) -t mdoj-backend + sudo docker build . --build-arg ARCH=$(uname -m) -t mdoj-backend run: cargo run diff --git a/backend/migration/src/m20231207_000001_create_table.rs b/backend/migration/src/m20231207_000001_create_table.rs index ee4604ff..b01cde0e 100644 --- a/backend/migration/src/m20231207_000001_create_table.rs +++ b/backend/migration/src/m20231207_000001_create_table.rs @@ -82,6 +82,7 @@ enum Problem { CreateAt, UpdateAt, MatchRule, + Order, } #[derive(Iden)] @@ -351,6 +352,7 @@ impl MigrationTrait for Migration { .extra(UPDATE_AT.to_string()), ) .col(ColumnDef::new(Problem::MatchRule).integer().not_null()) + .col(ColumnDef::new(Problem::Order).float().not_null()) .to_owned(), ) .await?; @@ -609,6 +611,7 @@ impl MigrationTrait for Migration { index!(manager, Problem, AcRate); index!(manager, Problem, AcceptCount); index!(manager, Problem, Difficulty); + index!(manager, Problem, Order); index!(manager, Submit, Committed); index!(manager, Submit, Time); index!(manager, Submit, Memory); diff --git a/backend/src/endpoint/chat.rs b/backend/src/endpoint/chat.rs index ab2ae961..f20f3803 100644 --- a/backend/src/endpoint/chat.rs +++ b/backend/src/endpoint/chat.rs @@ -97,7 +97,7 @@ impl ChatSet for Arc { let mut pager: Pager = match req.request.ok_or(Error::NotInPayload("request"))? { list_by_request::Request::ParentId(ppk) => { tracing::debug!(id = ppk); - Pager::parent_search(ppk) + Pager::parent_search(ppk, false) } list_by_request::Request::Pager(old) => { reverse = old.reverse; diff --git a/backend/src/endpoint/education.rs b/backend/src/endpoint/education.rs index ca3a3e31..c5fb68a5 100644 --- a/backend/src/endpoint/education.rs +++ b/backend/src/endpoint/education.rs @@ -226,7 +226,7 @@ impl EducationSet for Arc { let mut pager: Pager = match req.request.ok_or(Error::NotInPayload("request"))? { list_by_request::Request::ParentId(ppk) => { tracing::debug!(id = ppk); - Pager::parent_search(ppk) + Pager::parent_search(ppk, false) } list_by_request::Request::Pager(old) => { reverse = old.reverse; diff --git a/backend/src/endpoint/problem.rs b/backend/src/endpoint/problem.rs index a603e370..a9bbabc1 100644 --- a/backend/src/endpoint/problem.rs +++ b/backend/src/endpoint/problem.rs @@ -201,7 +201,7 @@ impl ProblemSet for Arc { model.user_id = ActiveValue::Set(user_id); fill_active_model!( - model, req.info, title, difficulty, time, memory, tags, content, match_rule + model, req.info, title, difficulty, time, memory, tags, content, match_rule, order ); let model = model.save(db).await.map_err(Into::::into)?; @@ -244,7 +244,8 @@ impl ProblemSet for Arc { content, match_rule, ac_rate, - submit_count + submit_count, + order ); let model = model.update(db).await.map_err(Into::::into)?; @@ -404,7 +405,7 @@ impl ProblemSet for Arc { let mut pager: Pager = match req.request.ok_or(Error::NotInPayload("request"))? { list_by_request::Request::ParentId(ppk) => { tracing::debug!(id = ppk); - Pager::parent_search(ppk) + Pager::parent_sorted_search(ppk, SortBy::Order, false) } list_by_request::Request::Pager(old) => { reverse = old.reverse; diff --git a/backend/src/endpoint/submit.rs b/backend/src/endpoint/submit.rs index f46daf3b..fcddbfc0 100644 --- a/backend/src/endpoint/submit.rs +++ b/backend/src/endpoint/submit.rs @@ -105,7 +105,7 @@ impl SubmitSet for Arc { let mut pager: Pager = match req.request.ok_or(Error::NotInPayload("request"))? { list_by_request::Request::ParentId(ppk) => { tracing::debug!(id = ppk); - Pager::parent_search(ppk) + Pager::parent_search(ppk, false) } list_by_request::Request::Pager(old) => { reverse = old.reverse; diff --git a/backend/src/endpoint/testcase.rs b/backend/src/endpoint/testcase.rs index 05536bab..3966a7a7 100644 --- a/backend/src/endpoint/testcase.rs +++ b/backend/src/endpoint/testcase.rs @@ -288,7 +288,7 @@ impl TestcaseSet for Arc { let mut pager: Pager = match req.request.ok_or(Error::NotInPayload("request"))? { list_by_request::Request::ParentId(ppk) => { tracing::debug!(id = ppk); - Pager::parent_search(ppk) + Pager::parent_search(ppk, false) } list_by_request::Request::Pager(old) => { reverse = old.reverse; diff --git a/backend/src/endpoint/util/pager/impls.rs b/backend/src/endpoint/util/pager/impls.rs index 51a5db00..7ef697e4 100644 --- a/backend/src/endpoint/util/pager/impls.rs +++ b/backend/src/endpoint/util/pager/impls.rs @@ -39,6 +39,7 @@ impl PagerTrait for problem::Entity { SortBy::AcRate => problem::Column::AcRate, SortBy::SubmitCount => problem::Column::SubmitCount, SortBy::Difficulty => problem::Column::Difficulty, + SortBy::Order => problem::Column::Order, _ => problem::Column::Id, } } @@ -49,6 +50,7 @@ impl PagerTrait for problem::Entity { SortBy::AcRate => model.ac_rate.to_string(), SortBy::SubmitCount => model.submit_count.to_string(), SortBy::Difficulty => model.difficulty.to_string(), + SortBy::Order => model.order.to_string(), _ => model.id.to_string(), } } diff --git a/backend/src/endpoint/util/pager/mod.rs b/backend/src/endpoint/util/pager/mod.rs index 37db1636..1aeab2ee 100644 --- a/backend/src/endpoint/util/pager/mod.rs +++ b/backend/src/endpoint/util/pager/mod.rs @@ -96,8 +96,8 @@ pub trait HasParentPager where E: EntityTrait + PagerTrait>, { - fn parent_search(ppk: i32) -> Self; - fn parent_sorted_search(ppk: i32, sort: SortBy) -> Self; + fn parent_search(ppk: i32, rev: bool) -> Self; + fn parent_sorted_search(ppk: i32, sort: SortBy, rev: bool) -> Self; fn from_raw(s: String, server: &Server) -> Result, Error>; async fn fetch( &mut self, @@ -131,23 +131,23 @@ where P: Related, { #[instrument] - fn parent_search(ppk: i32) -> Self { + fn parent_search(ppk: i32, rev: bool) -> Self { Self { type_number: E::TYPE_NUMBER, sort: SearchDep::Parent(ppk), _entity: PhantomData, last_pk: None, - last_rev: true, + last_rev: rev, } } #[instrument] - fn parent_sorted_search(ppk: i32, sort: SortBy) -> Self { + fn parent_sorted_search(ppk: i32, sort: SortBy, rev: bool) -> Self { Self { type_number: E::TYPE_NUMBER, sort: SearchDep::ParentSort(ppk, sort, LastValue::default()), _entity: PhantomData, last_pk: None, - last_rev: false, + last_rev: rev, } } #[instrument(skip_all, name = "pagination_deserialize", level = "trace")] diff --git a/judger/justfile b/judger/justfile index d2bf0163..859b6096 100644 --- a/judger/justfile +++ b/judger/justfile @@ -3,7 +3,7 @@ release-docker: cd plugins/rlua-54 && sh ./build.sh cp ../proto/judger.proto . cp ../Cargo.toml ws-Cargo.toml - docker build . --build-arg ARCH=$(uname -m) -t mdoj-judger + sudo docker build . --build-arg ARCH=$(uname -m) -t mdoj-judger build-plugin: cd plugins && sh build-all.sh @@ -27,10 +27,10 @@ feodra-deps: clean: sudo rm -rf .temp cargo clean - docker images rm nsjail-3.1-$(uname -m)-linux-musl - docker images rm protobuf-3.21.1-$(uname -m)-linux-musl - docker images rm libnl-3.2.25-$(uname -m)-linux-musl - docker images rm musl-cross-make-$(uname -m)-linux-musl + sudo docker images rm nsjail-3.1-$(uname -m)-linux-musl + sudo docker images rm protobuf-3.21.1-$(uname -m)-linux-musl + sudo docker images rm libnl-3.2.25-$(uname -m)-linux-musl + sudo docker images rm musl-cross-make-$(uname -m)-linux-musl test: sudo rm -rf .temp/* diff --git a/proto/backend.proto b/proto/backend.proto index 7ad0cf20..87bf65b6 100644 --- a/proto/backend.proto +++ b/proto/backend.proto @@ -39,6 +39,7 @@ enum SortBy { Committed = 11; Time = 12; Memory = 13; + Order = 14; } // paginator is used to paginate list @@ -171,7 +172,7 @@ service SubmitSet { rpc Create(CreateSubmitRequest) returns (SubmitId); rpc Remove(SubmitId) returns (google.protobuf.Empty); - // list submit by problem, sorted by pirmary key(desc) + // list submit by problem, sorted by order(increasing) rpc ListByProblem(ListByRequest) returns (ListSubmitResponse); // are not guarantee to yield status @@ -241,6 +242,7 @@ service AnnouncementSet { rpc Publish(AnnouncementId) returns (google.protobuf.Empty); rpc Unpublish(AnnouncementId) returns (google.protobuf.Empty); + // paginate by id(increasing) rpc ListByContest(ListByRequest) returns (ListAnnouncementResponse); rpc FullInfoByContest(AnnouncementLink) returns (AnnouncementFullInfo); } @@ -307,6 +309,7 @@ service EducationSet { rpc Link(EducationLink) returns (google.protobuf.Empty); rpc Unlink(EducationLink) returns (google.protobuf.Empty); + // paginate by id(increasing) rpc ListByProblem(ListByRequest) returns (ListEducationResponse); rpc FullInfoByProblem(EducationLink) returns (EducationFullInfo); } @@ -350,6 +353,7 @@ message CreateProblemRequest { required string tags = 6; required string content = 7; required MatchRule match_rule = 9; + required float order = 10; }; required Info info = 1; required string request_id = 2; @@ -366,6 +370,7 @@ message UpdateProblemRequest { optional MatchRule match_rule = 10; optional uint32 submit_count = 3; optional float ac_rate = 8; + optional float order = 11; }; required Info info = 1; required ProblemId id = 2; @@ -388,6 +393,7 @@ service ProblemSet { rpc Unpublish(ProblemId) returns (google.protobuf.Empty); rpc FullInfoByContest(ProblemLink) returns (ProblemFullInfo); + // paginate by order(increasing) rpc ListByContest(ListByRequest) returns (ListProblemResponse); } @@ -448,6 +454,7 @@ service TestcaseSet { rpc Unlink(TestcaseLink) returns (google.protobuf.Empty); rpc FullInfoByProblem(TestcaseLink) returns (TestcaseFullInfo); + // paginate by id(increasing) rpc ListByProblem(ListByRequest) returns (ListTestcaseResponse); } @@ -692,5 +699,6 @@ service ChatSet { rpc Create(CreateChatRequest) returns (ChatId); rpc Remove(ChatId) returns (google.protobuf.Empty); + // paginate by id in increasing order rpc ListByProblem(ListByRequest) returns (ListChatResponse); } diff --git a/testsuit/Cargo.toml b/testsuit/Cargo.toml index 2ff8c370..529458d9 100644 --- a/testsuit/Cargo.toml +++ b/testsuit/Cargo.toml @@ -22,6 +22,8 @@ tokio-rustls = "0.24.1" rustls-pki-types = "1.0.1" rustls = "0.21.9" http-body = "0.4.6" +termion = "3.0.0" +thiserror = "1.0.56" [dependencies.tokio-stream] version = "0.1.14" diff --git a/testsuit/src/case.rs b/testsuit/src/case.rs index d5245897..ad3e2e58 100644 --- a/testsuit/src/case.rs +++ b/testsuit/src/case.rs @@ -1,50 +1,22 @@ use tonic::async_trait; -#[async_trait] -pub trait Case { - const NAME: &'static str; - - async fn run(&self, state: &mut S) -> Result<(), String>; +#[derive(Debug,thiserror::Error)] +pub enum Error{ + #[error("unreachable")] + Unreachable } -#[async_trait] -trait Runable { - async fn run(&self, state: &mut S) -> Result<(), String>; - fn name(&self) -> &'static str; -} +// pub struct StackedTestcase where Self:Sized{ +// next:Box> +// } -#[async_trait] -impl + Send + Sync + 'static> Runable for Rhs { - async fn run(&self, state: &mut S) -> Result<(), String> { - >::run(self, state).await - } +// impl Testcase for StackedTestcase { - fn name(&self) -> &'static str { - >::NAME - } -} +// } +// #[async_trait] +// pub trait Testcase{ +// fn run_inner(&self,state:I)->Result{ -#[derive(Default)] -pub struct CaseRunner { - case: Vec + Send + Sync + 'static>>, - state: S, -} - -impl CaseRunner { - pub fn add_case + Send + Sync + 'static>(&mut self, case: Rhs) { - self.case.push(Box::new(case)); - } - pub async fn run(mut self, title: &'static str) -> S { - log::info!("Start testsuit {}", title); - for (i, case) in self.case.into_iter().enumerate() { - log::info!("Running case {} {}", i, case.name()); - if let Err(err) = case.run(&mut self.state).await { - log::error!("test fail: {}", err); - break; - } - } - log::info!("End"); - - self.state - } -} +// } +// fn stack(self,state:I,next:Box>)->Resultwhere O:From; +// } \ No newline at end of file diff --git a/testsuit/src/main.rs b/testsuit/src/main.rs index 1efa5a98..b2fdbc9b 100644 --- a/testsuit/src/main.rs +++ b/testsuit/src/main.rs @@ -6,9 +6,9 @@ pub mod user; #[tokio::main(flavor = "current_thread")] async fn main() { - env_logger::builder() - .filter_module("testsuit", log::LevelFilter::Trace) - .init(); + // env_logger::builder() + // .filter_module("testsuit", log::LevelFilter::Trace) + // .init(); - user::run().await; + // user::run().await; } diff --git a/testsuit/src/user/login.rs b/testsuit/src/user/login.rs index 949860cb..a21d4714 100644 --- a/testsuit/src/user/login.rs +++ b/testsuit/src/user/login.rs @@ -1,46 +1,46 @@ -use crate::{ - case::Case, - client::connection, - constant, - grpc::backend::{token_set_client::TokenSetClient, LoginRequest}, -}; - -use super::State; - -pub struct AdminLogin; - -#[tonic::async_trait] -impl Case for AdminLogin { - const NAME: &'static str = "login as admin@admin"; - - async fn run(&self, state: &mut State) -> Result<(), String> { - let mut client = - TokenSetClient::with_origin(connection(), constant::SERVER.try_into().unwrap()); - - let res = client - .create(LoginRequest { - username: constant::ADMIN.to_string(), - password: constant::ADMIN_PWD.to_string(), - expiry: None, - }) - .await - .unwrap(); - - let res = res.into_inner(); - - assert!(res.permission.can_root); - assert!(!res.permission.can_link); - assert!(!res.permission.can_manage_announcement); - assert!(!res.permission.can_manage_chat); - assert!(!res.permission.can_manage_contest); - assert!(!res.permission.can_manage_education); - assert!(!res.permission.can_manage_problem); - assert!(!res.permission.can_manage_submit); - assert!(!res.permission.can_manage_user); - assert!(!res.permission.can_publish); - assert!(!res.permission.can_imgur); - - state.token = Some(res.token.signature); - Ok(()) - } -} +// use crate::{ +// case::Case, +// client::connection, +// constant, +// grpc::backend::{token_set_client::TokenSetClient, LoginRequest}, +// }; + +// use super::State; + +// pub struct AdminLogin; + +// #[tonic::async_trait] +// impl Case for AdminLogin { +// const NAME: &'static str = "login as admin@admin"; + +// async fn run(&self, state: &mut State) -> Result<(), String> { +// let mut client = +// TokenSetClient::with_origin(connection(), constant::SERVER.try_into().unwrap()); + +// let res = client +// .create(LoginRequest { +// username: constant::ADMIN.to_string(), +// password: constant::ADMIN_PWD.to_string(), +// expiry: None, +// }) +// .await +// .unwrap(); + +// let res = res.into_inner(); + +// assert!(res.permission.can_root); +// assert!(!res.permission.can_link); +// assert!(!res.permission.can_manage_announcement); +// assert!(!res.permission.can_manage_chat); +// assert!(!res.permission.can_manage_contest); +// assert!(!res.permission.can_manage_education); +// assert!(!res.permission.can_manage_problem); +// assert!(!res.permission.can_manage_submit); +// assert!(!res.permission.can_manage_user); +// assert!(!res.permission.can_publish); +// assert!(!res.permission.can_imgur); + +// state.token = Some(res.token.signature); +// Ok(()) +// } +// } diff --git a/testsuit/src/user/mod.rs b/testsuit/src/user/mod.rs index 0a21050f..fb576f96 100644 --- a/testsuit/src/user/mod.rs +++ b/testsuit/src/user/mod.rs @@ -1,15 +1,15 @@ -mod login; -use crate::{case::CaseRunner, user::login::AdminLogin}; +// mod login; +// use crate::{case::CaseRunner, user::login::AdminLogin}; -#[derive(Default)] -pub struct State { - token: Option, -} +// #[derive(Default)] +// pub struct State { +// token: Option, +// } -pub async fn run() -> State { - let mut user_runner = CaseRunner::::default(); +// pub async fn run() -> State { +// let mut user_runner = CaseRunner::::default(); - user_runner.add_case(AdminLogin); +// user_runner.add_case(AdminLogin); - user_runner.run("user").await -} +// user_runner.run("user").await +// }