Skip to content

Commit

Permalink
feat(Backend): ✨ use negative value for reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Feb 4, 2024
1 parent 23822d6 commit 743b51e
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 57 deletions.
17 changes: 11 additions & 6 deletions backend/src/endpoint/announcement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ impl AnnouncementSet for Arc<Server> {
req: Request<ListAnnouncementRequest>,
) -> Result<Response<ListAnnouncementResponse>, 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"))? {
Expand All @@ -82,7 +84,7 @@ impl AnnouncementSet for Arc<Server> {
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
}
}?;
Expand All @@ -101,7 +103,9 @@ impl AnnouncementSet for Arc<Server> {
req: Request<TextSearchRequest>,
) -> Result<Response<ListAnnouncementResponse>, 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"))? {
Expand All @@ -111,7 +115,7 @@ impl AnnouncementSet for Arc<Server> {
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
}
}?;
Expand Down Expand Up @@ -377,7 +381,8 @@ impl AnnouncementSet for Arc<Server> {
req: Request<ListByRequest>,
) -> Result<Response<ListAnnouncementResponse>, 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"))? {
Expand All @@ -396,7 +401,7 @@ impl AnnouncementSet for Arc<Server> {
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
}
}?;
Expand Down
6 changes: 4 additions & 2 deletions backend/src/endpoint/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ impl ChatSet for Arc<Server> {
req: Request<ListByRequest>,
) -> Result<Response<ListChatResponse>, 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"))? {
Expand All @@ -103,7 +105,7 @@ impl ChatSet for Arc<Server> {
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
}
}?;
Expand Down
12 changes: 8 additions & 4 deletions backend/src/endpoint/contest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ impl ContestSet for Arc<Server> {
req: Request<ListContestRequest>,
) -> Result<Response<ListContestResponse>, 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"))? {
Expand All @@ -87,7 +89,7 @@ impl ContestSet for Arc<Server> {
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
}
}?;
Expand All @@ -103,7 +105,9 @@ impl ContestSet for Arc<Server> {
req: Request<TextSearchRequest>,
) -> Result<Response<ListContestResponse>, 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"))? {
Expand All @@ -113,7 +117,7 @@ impl ContestSet for Arc<Server> {
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
}
}?;
Expand Down
11 changes: 7 additions & 4 deletions backend/src/endpoint/education.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ impl EducationSet for Arc<Server> {
req: Request<ListEducationRequest>,
) -> Result<Response<ListEducationResponse>, 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) => {
Expand Down Expand Up @@ -218,7 +219,9 @@ impl EducationSet for Arc<Server> {
req: Request<ListByRequest>,
) -> Result<Response<ListEducationResponse>, 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"))? {
Expand All @@ -237,7 +240,7 @@ impl EducationSet for Arc<Server> {
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
}
}?;
Expand Down
3 changes: 3 additions & 0 deletions backend/src/endpoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
20 changes: 13 additions & 7 deletions backend/src/endpoint/problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ impl ProblemSet for Arc<Server> {
req: Request<ListProblemRequest>,
) -> Result<Response<ListProblemResponse>, 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"))? {
Expand All @@ -74,7 +76,7 @@ impl ProblemSet for Arc<Server> {
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
}
}?;
Expand All @@ -90,7 +92,9 @@ impl ProblemSet for Arc<Server> {
req: Request<TextSearchRequest>,
) -> Result<Response<ListProblemResponse>, 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"))? {
Expand All @@ -100,7 +104,7 @@ impl ProblemSet for Arc<Server> {
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
}
}?;
Expand Down Expand Up @@ -369,9 +373,11 @@ impl ProblemSet for Arc<Server> {
req: Request<ListByRequest>,
) -> Result<Response<ListProblemResponse>, 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);
Expand All @@ -388,7 +394,7 @@ impl ProblemSet for Arc<Server> {
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
}
}?;
Expand Down
12 changes: 8 additions & 4 deletions backend/src/endpoint/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ impl SubmitSet for Arc<Server> {
req: Request<ListSubmitRequest>,
) -> Result<Response<ListSubmitResponse>, 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"))? {
Expand All @@ -80,7 +82,7 @@ impl SubmitSet for Arc<Server> {
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
}
}?;
Expand All @@ -97,7 +99,9 @@ impl SubmitSet for Arc<Server> {
req: Request<ListByRequest>,
) -> Result<Response<ListSubmitResponse>, 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"))? {
Expand All @@ -115,7 +119,7 @@ impl SubmitSet for Arc<Server> {
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
}
}?;
Expand Down
12 changes: 8 additions & 4 deletions backend/src/endpoint/testcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ impl TestcaseSet for Arc<Server> {
req: Request<ListTestcaseRequest>,
) -> Result<Response<ListTestcaseResponse>, 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) => {
Expand Down Expand Up @@ -250,7 +252,9 @@ impl TestcaseSet for Arc<Server> {
req: Request<ListByRequest>,
) -> Result<Response<ListTestcaseResponse>, 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"))? {
Expand All @@ -268,7 +272,7 @@ impl TestcaseSet for Arc<Server> {
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
}
}?;
Expand Down
24 changes: 8 additions & 16 deletions backend/src/endpoint/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ impl From<Model> for UserInfo {
}
}

// impl From<RoleLv> for Permission {
// fn from(value: RoleLv) -> Self {
// Permission { flags: value }
// }
// }

// impl From<Permission> for RoleLv {
// fn from(value: Permission) -> Self {
// RoleLv(value.flags)
// }
// }

#[async_trait]
impl UserSet for Arc<Server> {
#[instrument(skip_all, level = "debug")]
Expand All @@ -49,7 +37,9 @@ impl UserSet for Arc<Server> {
req: Request<ListUserRequest>,
) -> Result<Response<ListUserResponse>, 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"))? {
Expand All @@ -67,7 +57,7 @@ impl UserSet for Arc<Server> {
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
}
}?;
Expand All @@ -83,7 +73,9 @@ impl UserSet for Arc<Server> {
req: Request<TextSearchRequest>,
) -> Result<Response<ListUserResponse>, 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"))? {
Expand All @@ -93,7 +85,7 @@ impl UserSet for Arc<Server> {
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
}
}?;
Expand Down
Loading

0 comments on commit 743b51e

Please sign in to comment.