diff --git a/backend/src/endpoint/announcement.rs b/backend/src/endpoint/announcement.rs index bdbf90af..697a65d9 100644 --- a/backend/src/endpoint/announcement.rs +++ b/backend/src/endpoint/announcement.rs @@ -64,7 +64,9 @@ impl AnnouncementSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -82,7 +84,7 @@ impl AnnouncementSet for Arc { list_announcement_request::Request::Pager(old) => { let pager: ColPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; @@ -101,7 +103,9 @@ impl AnnouncementSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -111,7 +115,7 @@ impl AnnouncementSet for Arc { text_search_request::Request::Pager(old) => { let pager: TextPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; @@ -377,7 +381,8 @@ impl AnnouncementSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -396,7 +401,7 @@ impl AnnouncementSet for Arc { list_by_request::Request::Pager(old) => { let pager: ParentPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; diff --git a/backend/src/endpoint/chat.rs b/backend/src/endpoint/chat.rs index 5b316509..b9cf9d25 100644 --- a/backend/src/endpoint/chat.rs +++ b/backend/src/endpoint/chat.rs @@ -84,7 +84,9 @@ impl ChatSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -103,7 +105,7 @@ impl ChatSet for Arc { list_by_request::Request::Pager(old) => { let pager: ParentPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; diff --git a/backend/src/endpoint/contest.rs b/backend/src/endpoint/contest.rs index c076902e..ca0a9994 100644 --- a/backend/src/endpoint/contest.rs +++ b/backend/src/endpoint/contest.rs @@ -69,7 +69,9 @@ impl ContestSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -87,7 +89,7 @@ impl ContestSet for Arc { list_contest_request::Request::Pager(old) => { let pager: ColPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; @@ -103,7 +105,9 @@ impl ContestSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -113,7 +117,7 @@ impl ContestSet for Arc { text_search_request::Request::Pager(old) => { let pager: TextPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; diff --git a/backend/src/endpoint/education.rs b/backend/src/endpoint/education.rs index a032ae7f..1e0c6e9c 100644 --- a/backend/src/endpoint/education.rs +++ b/backend/src/endpoint/education.rs @@ -45,9 +45,10 @@ impl EducationSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); - let rev = req.reverse(); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { list_education_request::Request::Pager(pager) => { @@ -218,7 +219,9 @@ impl EducationSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -237,7 +240,7 @@ impl EducationSet for Arc { list_by_request::Request::Pager(old) => { let pager: ParentPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; diff --git a/backend/src/endpoint/mod.rs b/backend/src/endpoint/mod.rs index 48e17fad..4b070191 100644 --- a/backend/src/endpoint/mod.rs +++ b/backend/src/endpoint/mod.rs @@ -39,4 +39,7 @@ mod tools { pub use tonic::*; pub use tracing::instrument; pub use uuid::Uuid; + pub fn split_rev(raw:i64)->(bool,u64){ + return (raw <0,raw.abs().try_into().unwrap()); + } } diff --git a/backend/src/endpoint/problem.rs b/backend/src/endpoint/problem.rs index a3afe640..8e1a59ef 100644 --- a/backend/src/endpoint/problem.rs +++ b/backend/src/endpoint/problem.rs @@ -56,7 +56,9 @@ impl ProblemSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -74,7 +76,7 @@ impl ProblemSet for Arc { list_problem_request::Request::Pager(old) => { let pager: ColPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; @@ -90,7 +92,9 @@ impl ProblemSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -100,7 +104,7 @@ impl ProblemSet for Arc { text_search_request::Request::Pager(old) => { let pager: TextPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; @@ -369,9 +373,11 @@ impl ProblemSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); - let offset = bound!(req.offset(), 1024); + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); + let offset = bound!(req.offset(), 1024); + let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { list_by_request::Request::Create(create) => { tracing::debug!(id = create.parent_id); @@ -388,7 +394,7 @@ impl ProblemSet for Arc { list_by_request::Request::Pager(old) => { let pager: ParentPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; diff --git a/backend/src/endpoint/submit.rs b/backend/src/endpoint/submit.rs index 5c47a08b..51d9d452 100644 --- a/backend/src/endpoint/submit.rs +++ b/backend/src/endpoint/submit.rs @@ -69,7 +69,9 @@ impl SubmitSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -80,7 +82,7 @@ impl SubmitSet for Arc { list_submit_request::Request::Pager(old) => { let pager: ColPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; @@ -97,7 +99,9 @@ impl SubmitSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -115,7 +119,7 @@ impl SubmitSet for Arc { list_by_request::Request::Pager(old) => { let pager: ParentPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; diff --git a/backend/src/endpoint/testcase.rs b/backend/src/endpoint/testcase.rs index 4e8d05ca..2b1c96f4 100644 --- a/backend/src/endpoint/testcase.rs +++ b/backend/src/endpoint/testcase.rs @@ -44,14 +44,16 @@ impl TestcaseSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { list_testcase_request::Request::Pager(old) => { let pager: ColPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } list_testcase_request::Request::StartFromEnd(rev) => { @@ -250,7 +252,9 @@ impl TestcaseSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -268,7 +272,7 @@ impl TestcaseSet for Arc { list_by_request::Request::Pager(old) => { let pager: ParentPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; diff --git a/backend/src/endpoint/user.rs b/backend/src/endpoint/user.rs index f455cf63..3961bd61 100644 --- a/backend/src/endpoint/user.rs +++ b/backend/src/endpoint/user.rs @@ -29,18 +29,6 @@ impl From for UserInfo { } } -// impl From for Permission { -// fn from(value: RoleLv) -> Self { -// Permission { flags: value } -// } -// } - -// impl From for RoleLv { -// fn from(value: Permission) -> Self { -// RoleLv(value.flags) -// } -// } - #[async_trait] impl UserSet for Arc { #[instrument(skip_all, level = "debug")] @@ -49,7 +37,9 @@ impl UserSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -67,7 +57,7 @@ impl UserSet for Arc { list_user_request::Request::Pager(old) => { let pager: ColPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; @@ -83,7 +73,9 @@ impl UserSet for Arc { req: Request, ) -> Result, Status> { let (auth, req) = self.parse_request(req).await?; - let size = bound!(req.size, 64); + + let (rev,size)=split_rev(req.size); + let size = bound!(size, 64); let offset = bound!(req.offset(), 1024); let (pager, models) = match req.request.ok_or(Error::NotInPayload("request"))? { @@ -93,7 +85,7 @@ impl UserSet for Arc { text_search_request::Request::Pager(old) => { let pager: TextPaginator = self.crypto.decode(old.session)?; pager - .fetch(&auth, size, offset, old.reverse, &self.db) + .fetch(&auth, size, offset, rev, &self.db) .await } }?; diff --git a/proto/backend.proto b/proto/backend.proto index d5c6745f..dfdf955c 100644 --- a/proto/backend.proto +++ b/proto/backend.proto @@ -34,7 +34,6 @@ enum MatchRule { // (4, 3, false) => 5, 6, 7 message Paginator { required string session = 1; - required bool reverse = 2; } message TextSearchRequest { @@ -42,7 +41,7 @@ message TextSearchRequest { string text = 1; Paginator pager = 2; } - required uint64 size = 3; + required int64 size = 3; optional uint64 offset = 4; } @@ -55,7 +54,7 @@ message ListByRequest { Create create=1; Paginator pager = 2; } - required uint64 size = 3; + required int64 size = 3; optional uint64 offset = 4; optional bool reverse = 5 ; } @@ -150,7 +149,7 @@ message ListSubmitRequest { Create create = 1; Paginator pager = 2; } - required uint64 size = 3; + required int64 size = 3; optional uint64 offset = 4; optional bool reverse = 5 ; } @@ -232,7 +231,7 @@ message ListAnnouncementRequest { Create create = 1; Paginator pager = 2; } - required uint64 size = 3; + required int64 size = 3; optional uint64 offset = 4; optional bool reverse=5; } @@ -317,7 +316,7 @@ message ListEducationRequest { Paginator pager =2; } optional bool reverse = 5; - required uint64 size = 3; + required int64 size = 3; optional uint64 offset = 4; } @@ -417,7 +416,7 @@ message ListProblemRequest { Create create = 1; Paginator pager = 2; } - required uint64 size = 3; + required int64 size = 3; optional uint64 offset = 4; } @@ -493,7 +492,7 @@ message ListTestcaseRequest { Paginator pager = 5; } optional bool reverse = 6; - required uint64 size = 3; + required int64 size = 3; optional uint64 offset = 4; } @@ -598,7 +597,7 @@ message ListContestRequest { Paginator pager = 2; } optional bool reverse = 6; - required uint64 size = 3; + required int64 size = 3; optional uint64 offset = 4; } @@ -688,7 +687,7 @@ message ListUserRequest { Paginator pager = 2; } optional bool reverse = 6; - required uint64 size = 3; + required int64 size = 3; optional uint64 offset = 4; }