Skip to content

Commit

Permalink
refactor: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
azzamsa committed Apr 1, 2024
1 parent d05e56b commit d029260
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ impl Config {
};

let mut config = Self {
env,
base_url,
schema_location,
env,
http,
database,
};
Expand Down
2 changes: 1 addition & 1 deletion src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub async fn connect(database: &config::Database) -> Result<DB, Error> {

pub async fn migrate(db: &DB) -> Result<(), Error> {
match sqlx::migrate!("db/migrations").run(db).await {
Ok(_) => Ok(()),
Ok(()) => Ok(()),
Err(err) => {
tracing::error!("{}", &err);
Err(err)
Expand Down
18 changes: 9 additions & 9 deletions src/domain/user/repository/find_all_users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Repository {
}
// Last & before
(None, None, Some(last), Some(before)) => {
query = format!("select * from ( select * from user_ where id < '{before}' order by id desc limit {limit} ) as data order by id asc;", limit = last + 1)
query = format!("select * from ( select * from user_ where id < '{before}' order by id desc limit {limit} ) as data order by id asc;", limit = last + 1);
}
// Default page size
_ => query = format!("{query} limit {default_page_size}"),
Expand Down Expand Up @@ -65,20 +65,20 @@ impl Repository {
}
pub async fn has_previous_page(
&self,
rows: &Vec<entities::User>,
rows: &[entities::User],
last: Option<i32>,
) -> Result<bool, Error> {
let mut has_previous_page: bool = false;
if let Some(last) = last {
tracing::debug!("rows length: {}. last: {}", rows.len(), last);
has_previous_page = rows.len() > last as usize
has_previous_page = rows.len() > last as usize;
};
Ok(has_previous_page)
}
pub async fn find_page_info<'c, C: Queryer<'c> + Copy>(
&self,
db: C,
rows: &Vec<entities::User>,
rows: &[entities::User],
first: Option<i32>,
after: Option<Uuid>,
last: Option<i32>,
Expand Down Expand Up @@ -122,20 +122,20 @@ impl Repository {
};
};

let (start_cursor, end_cursor) = if !rows.is_empty() {
let (start_cursor, end_cursor) = if rows.is_empty() {
(None, None)
} else {
let start_cursor = Base64Cursor::new(rows[0].id).encode();
let end_cursor = Base64Cursor::new(rows[rows.len() - 1].id).encode();
(Some(start_cursor), Some(end_cursor))
} else {
(None, None)
};

let has_previous_page = self.has_previous_page(rows, last).await?;
let page_info = entities::PageInfo {
end_cursor,
has_next_page,
has_previous_page,
start_cursor,
end_cursor,
has_previous_page,
};

Ok(page_info)
Expand Down
2 changes: 1 addition & 1 deletion src/domain/user/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl UserQuery {
.await?;
let edges: Vec<model::UserEdge> = user_edges
.into_iter()
.map(|user| user.transmogrify())
.map(frunk::labelled::Transmogrifier::transmogrify)
.collect();

let user_connection = model::UserConnection {
Expand Down
2 changes: 1 addition & 1 deletion src/domain/user/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct Service {
impl Service {
pub fn new(db: DB, mailer: Mailer) -> Self {
let repo = Repository::new();
Self { db, repo, mailer }
Self { repo, db, mailer }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Base64Cursor {
let index = cursor
.split(':')
.last()
.map(|s| s.parse::<Uuid>())
.map(str::parse)
.ok_or(Base64CursorError::Invalid)?
.map_err(|_| Base64CursorError::Invalid)?;

Expand Down

0 comments on commit d029260

Please sign in to comment.