Skip to content

Commit

Permalink
cilppy(backend): cargo clippy and some manual fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Jul 12, 2024
1 parent 5f71d16 commit 27316cb
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 53 deletions.
12 changes: 6 additions & 6 deletions backend/src/endpoint/announcement.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::tools::*;

use grpc::{backend::announcement_server::*, backend::*};
use grpc::backend::announcement_server::*;

use crate::{
entity::announcement::{Paginator, *},
Expand All @@ -13,11 +13,11 @@ impl From<Model> for AnnouncementFullInfo {
fn from(value: Model) -> Self {
AnnouncementFullInfo {
info: AnnouncementInfo {
id: value.id.into(),
id: value.id,
title: value.title,
update_date: into_prost(value.update_at),
},
author_id: value.user_id.into(),
author_id: value.user_id,
content: value.content,
public: value.public,
}
Expand All @@ -27,7 +27,7 @@ impl From<Model> for AnnouncementFullInfo {
impl From<Model> for AnnouncementInfo {
fn from(value: Model) -> Self {
AnnouncementInfo {
id: value.id.into(),
id: value.id,
title: value.title,
update_date: into_prost(value.update_at),
}
Expand All @@ -37,7 +37,7 @@ impl From<Model> for AnnouncementInfo {
impl From<PartialModel> for AnnouncementInfo {
fn from(value: PartialModel) -> Self {
AnnouncementInfo {
id: value.id.into(),
id: value.id,
title: value.title,
update_date: into_prost(value.update_at),
}
Expand All @@ -53,7 +53,7 @@ impl Announcement for ArcServer {
) -> Result<Response<ListAnnouncementResponse>, Status> {
let (auth, req) = self
.parse_request_fn(req, |req| {
((req.size as u64) + req.offset.saturating_abs() as u64 / 5 + 2)
(req.size + req.offset.saturating_abs() as u64 / 5 + 2)
.try_into()
.unwrap_or(u32::MAX)
})
Expand Down
10 changes: 5 additions & 5 deletions backend/src/endpoint/chat.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use super::tools::*;

use grpc::{backend::chat_server::*, backend::*};
use grpc::backend::chat_server::*;

use crate::entity::chat::{Paginator, *};

impl From<Model> for ChatInfo {
fn from(value: Model) -> Self {
ChatInfo {
id: value.id.into(),
user_id: value.user_id.into(),
problem_id: value.problem_id.into(),
id: value.id,
user_id: value.user_id,
problem_id: value.problem_id,
create_at: into_prost(value.create_at),
message: value.message,
}
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Chat for ArcServer {
) -> Result<Response<ListChatResponse>, Status> {
let (auth, req) = self
.parse_request_fn(req, |req| {
((req.size as u64) + req.offset.saturating_abs() as u64 / 5 + 2)
(req.size + req.offset.saturating_abs() as u64 / 5 + 2)
.try_into()
.unwrap_or(u32::MAX)
})
Expand Down
11 changes: 5 additions & 6 deletions backend/src/endpoint/contest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ use crate::entity::{
};

use grpc::backend::contest_server::*;
use grpc::backend::*;

impl From<Model> for ContestFullInfo {
fn from(value: Model) -> Self {
ContestFullInfo {
info: value.clone().into(),
content: value.content,
host: value.hoster.into(),
host: value.hoster,
}
}
}

impl From<user_contest::Model> for UserRank {
fn from(value: user_contest::Model) -> Self {
UserRank {
user_id: value.user_id.into(),
user_id: value.user_id,
score: value.score,
}
}
Expand All @@ -30,7 +29,7 @@ impl From<user_contest::Model> for UserRank {
impl From<Model> for ContestInfo {
fn from(value: Model) -> Self {
ContestInfo {
id: value.id.into(),
id: value.id,
title: value.title,
begin: into_prost(value.begin),
end: into_prost(value.end),
Expand All @@ -42,7 +41,7 @@ impl From<Model> for ContestInfo {
impl From<PartialModel> for ContestInfo {
fn from(value: PartialModel) -> Self {
ContestInfo {
id: value.id.into(),
id: value.id,
title: value.title,
begin: into_prost(value.begin),
end: into_prost(value.end),
Expand All @@ -60,7 +59,7 @@ impl Contest for ArcServer {
) -> Result<Response<ListContestResponse>, Status> {
let (auth, req) = self
.parse_request_fn(req, |req| {
((req.size as u64) + req.offset.saturating_abs() as u64 / 5 + 2)
(req.size + req.offset.saturating_abs() as u64 / 5 + 2)
.try_into()
.unwrap_or(u32::MAX)
})
Expand Down
7 changes: 3 additions & 4 deletions backend/src/endpoint/education.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use super::tools::*;

use grpc::backend::education_server::*;
use grpc::backend::*;

use crate::entity::{education::Paginator, education::*, *};

impl From<Model> for EducationFullInfo {
fn from(value: Model) -> Self {
EducationFullInfo {
info: EducationInfo {
id: value.id.into(),
id: value.id,
title: value.title,
},
content: value.content,
Expand All @@ -20,7 +19,7 @@ impl From<Model> for EducationFullInfo {
impl From<PartialModel> for EducationInfo {
fn from(value: PartialModel) -> Self {
EducationInfo {
id: value.id.into(),
id: value.id,
title: value.title,
}
}
Expand All @@ -34,7 +33,7 @@ impl Education for ArcServer {
) -> Result<Response<ListEducationResponse>, Status> {
let (auth, req) = self
.parse_request_fn(req, |req| {
((req.size as u64) + req.offset.saturating_abs() as u64 / 5 + 2)
(req.size + req.offset.saturating_abs() as u64 / 5 + 2)
.try_into()
.unwrap_or(u32::MAX)
})
Expand Down
1 change: 0 additions & 1 deletion backend/src/endpoint/imgur.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::tools::*;

use grpc::backend::image_server::*;
use grpc::backend::*;

#[async_trait]
impl Image for ArcServer {
Expand Down
7 changes: 2 additions & 5 deletions backend/src/endpoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod user;

mod tools {
pub use crate::NonZeroU32;
pub use grpc::backend::{Id, Order};
pub use grpc::backend::*;
pub use sea_orm::*;
pub use std::ops::Deref;
pub use tonic::*;
Expand All @@ -35,10 +35,7 @@ mod tools {
error::{atomic_fail, Error},
time::*,
};
pub use crate::{
fill_active_model, fill_exist_active_model, parse_pager_param, server::ArcServer,
TonicStream,
};
pub use crate::{fill_active_model, fill_exist_active_model, server::ArcServer, TonicStream};
}

// FIXME: currently we report transaction error as internal error,
Expand Down
2 changes: 0 additions & 2 deletions backend/src/endpoint/playground.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use super::tools::*;

use crate::controller::judger::PlaygroundPayload;

use grpc::backend::playground_server::*;
use grpc::backend::*;

Expand Down
10 changes: 4 additions & 6 deletions backend/src/endpoint/problem.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use super::tools::*;
use grpc::backend::problem_server::*;
use grpc::backend::*;

use crate::entity::{problem::Paginator, problem::*, *};
use list_problem_request::Sort;

impl From<PartialModel> for ProblemInfo {
fn from(value: PartialModel) -> Self {
ProblemInfo {
id: value.id.into(),
id: value.id,
title: value.title,
submit_count: value.submit_count,
ac_rate: value.ac_rate,
Expand All @@ -27,13 +25,13 @@ impl From<Model> for ProblemFullInfo {
time: value.time as u64,
memory: value.memory as u64,
info: ProblemInfo {
id: value.id.into(),
id: value.id,
title: value.title,
submit_count: value.submit_count,
ac_rate: value.ac_rate,
difficulty: value.difficulty,
},
author: value.user_id.into(),
author: value.user_id,
}
}
}
Expand All @@ -47,7 +45,7 @@ impl Problem for ArcServer {
) -> Result<Response<ListProblemResponse>, Status> {
let (auth, req) = self
.parse_request_fn(req, |req| {
((req.size as u64) + req.offset.saturating_abs() as u64 / 5 + 2)
(req.size + req.offset.saturating_abs() as u64 / 5 + 2)
.try_into()
.unwrap_or(u32::MAX)
})
Expand Down
7 changes: 3 additions & 4 deletions backend/src/endpoint/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::controller::judger::SubmitBuilder;
use crate::util::code::Code;
use grpc::backend::submit_server::*;
use grpc::backend::StateCode as BackendCode;
use grpc::backend::*;

use crate::entity::{
submit::{Paginator, *},
Expand All @@ -19,7 +18,7 @@ impl From<Model> for SubmitInfo {
// TODO: solve devation and uncommitted submit!
let db_code: Code = value.status.unwrap().try_into().unwrap();
SubmitInfo {
id: value.id.into(),
id: value.id,
upload_time: into_prost(value.upload_at),
score: value.score,
state: JudgeResult {
Expand All @@ -37,7 +36,7 @@ impl From<PartialModel> for SubmitInfo {
// TODO: solve devation and uncommitted submit!
let db_code: Code = value.status.unwrap().try_into().unwrap();
SubmitInfo {
id: value.id.into(),
id: value.id,
upload_time: into_prost(value.upload_at),
score: value.score,
state: JudgeResult {
Expand All @@ -59,7 +58,7 @@ impl Submit for ArcServer {
) -> Result<Response<ListSubmitResponse>, Status> {
let (auth, req) = self
.parse_request_fn(req, |req| {
((req.size as u64) + req.offset.saturating_abs() as u64 / 5 + 2)
(req.size + req.offset.saturating_abs() as u64 / 5 + 2)
.try_into()
.unwrap_or(u32::MAX)
})
Expand Down
5 changes: 2 additions & 3 deletions backend/src/endpoint/testcase.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use super::tools::*;

use grpc::backend::testcase_server::*;
use grpc::backend::*;

use crate::entity::{testcase::*, *};

impl From<Model> for TestcaseFullInfo {
fn from(value: Model) -> Self {
TestcaseFullInfo {
id: value.id.into(),
id: value.id,
score: value.score,
inputs: value.input,
outputs: value.output,
Expand All @@ -19,7 +18,7 @@ impl From<Model> for TestcaseFullInfo {
impl From<Model> for TestcaseInfo {
fn from(value: Model) -> Self {
TestcaseInfo {
id: value.id.into(),
id: value.id,
score: value.score,
}
}
Expand Down
5 changes: 2 additions & 3 deletions backend/src/endpoint/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::time::Duration;
use super::tools::*;

use grpc::backend::token_server::*;
use grpc::backend::*;

use crate::entity::token::*;
use crate::entity::*;
Expand Down Expand Up @@ -75,7 +74,7 @@ impl Token for ArcServer {
let (token, expiry) = self.token.add(&model, dur).in_current_span().await?;

Ok(Response::new(TokenInfo {
token: token.into(),
token,
role: model.permission,
expiry: into_prost(expiry),
}))
Expand Down Expand Up @@ -116,7 +115,7 @@ impl Token for ArcServer {

let (token, expiry) = self.token.add(&user, dur).in_current_span().await?;
return Ok(Response::new(TokenInfo {
token: token.into(),
token,
role: perm as i32,
expiry: into_prost(expiry),
}));
Expand Down
6 changes: 3 additions & 3 deletions backend/src/endpoint/user.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::tools::*;

use grpc::{backend::user_server::*, backend::*};
use grpc::backend::user_server::*;

use crate::{
entity::user,
Expand All @@ -13,7 +13,7 @@ impl From<Model> for UserInfo {
username: value.username,
// FIXME: capture Error(database corruption?) instead!
score: value.score.try_into().unwrap_or_default(),
id: value.id.into(),
id: value.id,
}
}
}
Expand All @@ -27,7 +27,7 @@ impl User for ArcServer {
) -> Result<Response<ListUserResponse>, Status> {
let (auth, req) = self
.parse_request_fn(req, |req| {
((req.size as u64) + req.offset.saturating_abs() as u64 / 5 + 2)
(req.size + req.offset.saturating_abs() as u64 / 5 + 2)
.try_into()
.unwrap_or(u32::MAX)
})
Expand Down
5 changes: 4 additions & 1 deletion backend/src/entity/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl util::paginator::PaginateRaw for ParentPaginator {
to_order(self.start_from_end ^ dir),
)
.offset(self.offset + offset)
.limit(size.abs() as u64)
.limit(size.unsigned_abs())
.all(db)
.await?;

Expand Down Expand Up @@ -382,6 +382,9 @@ impl Paginator {
start_from_end,
))
}
pub fn new(start_from_end: bool) -> Self {
Self::new_sort(Sort::Score, start_from_end)
}
}

impl<'a, 'b> WithDB<'a, WithAuth<'b, Paginator>> {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/entity/util/paginator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl<S: Source, R: Reflect<S::Entity>> PaginateRaw for PrimaryKeyPaginator<S, R>

let query = paginator
.apply(S::filter(auth, &self.data, db).await?)
.limit(size.abs() as u64)
.limit(size.unsigned_abs())
.offset(offset);
let models = R::all(query, db).await?;

Expand Down Expand Up @@ -295,7 +295,7 @@ impl<S: SortSource<R>, R: Reflect<S::Entity>> PaginateRaw for ColumnPaginator<S,

let query = paginator
.apply(S::filter(auth, &self.data, db).await?)
.limit(size.abs() as u64)
.limit(size.unsigned_abs())
.offset(offset);
let models = R::all(query, db)
.instrument(debug_span!("query").or_current())
Expand Down
2 changes: 0 additions & 2 deletions backend/src/entity/util/with.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::entity::problem::{Paginator, PartialModel};
use crate::util::auth::Auth;
use crate::util::error::Error;
use sea_orm::DatabaseConnection;

pub struct WithAuth<'a, T>(pub &'a Auth, pub T);
Expand Down

0 comments on commit 27316cb

Please sign in to comment.