Skip to content

Commit

Permalink
cargo clippy && cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
djkato committed Jan 10, 2025
1 parent 6cb8f51 commit 5a3dee2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 28 deletions.
18 changes: 14 additions & 4 deletions app-template-ui/src/routes/api/webhooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use axum::{
};
use cynic::{http::SurfExt, MutationBuilder};
use saleor_app_sdk::{
headers::{SALEOR_API_URL_HEADER,SALEOR_EVENT_HEADER},
headers::{SALEOR_API_URL_HEADER, SALEOR_EVENT_HEADER},
webhooks::{
utils::{get_webhook_event_type, EitherWebhookType},
AsyncWebhookEventType,
Expand All @@ -14,7 +14,15 @@ use saleor_app_sdk::{
use tracing::{debug, info};

use crate::{
app::AppState, error_template::AxumError, queries::{event_products_updated::ProductUpdated, product_metadata_update::{MetadataInput, UpdateProductMetadata, UpdateProductMetadataVariables}} };
app::AppState,
error_template::AxumError,
queries::{
event_products_updated::ProductUpdated,
product_metadata_update::{
MetadataInput, UpdateProductMetadata, UpdateProductMetadataVariables,
},
},
};

pub async fn webhooks(
headers: HeaderMap,
Expand All @@ -27,8 +35,10 @@ pub async fn webhooks(
debug!("headers: {:?}", headers);

let url = headers
.get(SALEOR_API_URL_HEADER).ok_or(AxumError::MissingHeader(SALEOR_API_URL_HEADER.to_owned()))?;
let event_type = get_webhook_event_type(&headers).map_err(|_|AxumError::MissingHeader(SALEOR_EVENT_HEADER.to_owned()))?;
.get(SALEOR_API_URL_HEADER)
.ok_or(AxumError::MissingHeader(SALEOR_API_URL_HEADER.to_owned()))?;
let event_type = get_webhook_event_type(&headers)
.map_err(|_| AxumError::MissingHeader(SALEOR_EVENT_HEADER.to_owned()))?;
if let EitherWebhookType::Async(a) = event_type {
match a {

Check failure on line 43 in app-template-ui/src/routes/api/webhooks.rs

View workflow job for this annotation

GitHub Actions / Clippy

this `match` can be collapsed into the outer `if let`
AsyncWebhookEventType::ProductUpdated
Expand Down
2 changes: 1 addition & 1 deletion app-template/src/routes/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{extract::State, Json};
use saleor_app_sdk::{manifest::AppManifest};
use saleor_app_sdk::manifest::AppManifest;

use crate::app::{AppError, AppState};

Expand Down
5 changes: 3 additions & 2 deletions bulk-price-manipulator/src/routes/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ pub async fn register(
info!("Starting caching and generation process");
let cloned_state = state.clone();

let _ = tokio::task::spawn(async {
std::mem::drop(tokio::task::spawn(async {
if let Err(e) = update_prices(cloned_state, saleor_api_url).await {
error!("{:?}", e);
}
});
}));

Ok(StatusCode::OK)
}
9 changes: 3 additions & 6 deletions bulk-price-manipulator/src/updater/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ pub async fn update_prices(state: AppState, saleor_api_url: String) -> anyhow::R
(Ok(price), Ok(cost_price)) => {
let mut used_cost_price = None;
if variant.channel_listings.is_some_and(|c| {
c.iter()
.find(|f| {
f.cost_price.is_some()
&& f.channel.id.inner() == channel_id.inner()
})
.is_some()
c.iter().any(|f| {
f.cost_price.is_some() && f.channel.id.inner() == channel_id.inner()
})
}) {
used_cost_price = Some(cost_price as f32);
};
Expand Down
12 changes: 6 additions & 6 deletions sdk/src/apl/file_apl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct FileApl {
impl APL for FileApl {
async fn set(&self, auth_data: crate::AuthData) -> Result<(), AplError> {
let path = std::path::Path::new(&self.path);
#[cfg(feature = "tracing")]
#[cfg(feature = "tracing")]
debug!("reading from {:?}", &path);
let mut auths: FileStructure;
match path.is_file() {
Expand All @@ -38,7 +38,7 @@ impl APL for FileApl {

auths.insert(auth_data.saleor_api_url.clone(), auth_data);

#[cfg(feature = "tracing")]
#[cfg(feature = "tracing")]
debug!("writing to {:?}", &path);
std::fs::write(
path,
Expand All @@ -52,7 +52,7 @@ impl APL for FileApl {

async fn get(&self, saleor_api_url: &str) -> Result<crate::AuthData, AplError> {
let path = std::path::Path::new(&self.path);
#[cfg(feature = "tracing")]
#[cfg(feature = "tracing")]
debug!("reading from {:?}", &path);
let auth_data: FileStructure = serde_json::from_str(
&std::fs::read_to_string(path).map_err(|e| AplError::IO(e.to_string()))?,
Expand All @@ -68,7 +68,7 @@ impl APL for FileApl {

async fn get_all(&self) -> Result<Vec<crate::AuthData>, AplError> {
let path = std::path::Path::new(&self.path);
#[cfg(feature = "tracing")]
#[cfg(feature = "tracing")]
debug!("reading from {:?}", &path);
let auth_data: FileStructure = serde_json::from_str(
&std::fs::read_to_string(path).map_err(|e| AplError::IO(e.to_string()))?,
Expand All @@ -79,15 +79,15 @@ impl APL for FileApl {

async fn delete(&self, saleor_api_url: &str) -> Result<(), AplError> {
let path = std::path::Path::new(&self.path);
#[cfg(feature = "tracing")]
#[cfg(feature = "tracing")]
debug!("reading from {:?}", &path);
let mut auths: FileStructure = serde_json::from_str(
&std::fs::read_to_string(path).map_err(|e| AplError::IO(e.to_string()))?,
)
.map_err(|e| AplError::Serialization(e.to_string()))?;
auths.remove(saleor_api_url);

#[cfg(feature = "tracing")]
#[cfg(feature = "tracing")]
debug!("writing to {:?}", &path);
std::fs::write(
path,
Expand Down
8 changes: 3 additions & 5 deletions sdk/src/middleware/verify_webhook_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ pub async fn webhook_signature_verifier(request: Request, next: Next) -> Respons

let jwks_url = request
.headers()
.get(SALEOR_API_URL_HEADER).and_then(|h| {
h.to_str()
.map_or(None, |h| url::Url::parse(h).ok())
});
.get(SALEOR_API_URL_HEADER)
.and_then(|h| h.to_str().map_or(None, |h| url::Url::parse(h).ok()));

debug!("request came from {:?}",jwks_url);
debug!("request came from {:?}", jwks_url);
//get jwk from saleor api
let jwks: Value = 'block: {
if let Some(mut jwks_url) = jwks_url {
Expand Down
2 changes: 1 addition & 1 deletion simple-payment-gateway/src/routes/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{extract::State, Json};
use saleor_app_sdk::{manifest::AppManifest};
use saleor_app_sdk::manifest::AppManifest;

use crate::app::{AppError, AppState};

Expand Down
7 changes: 4 additions & 3 deletions sitemap-generator/src/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,17 @@ pub fn gen_random_url_set(
// If there is a category url already, use that for relation instead of always a
let mut is_using_existing_category = false;
// new one
if res.iter().any(|r| r.1.data.typ == ItemType::Category) {
if rand::random::<bool>() == true { loop {
if res.iter().any(|r| r.1.data.typ == ItemType::Category) && rand::random::<bool>()
{
loop {
let r = res.choose(&mut rand::thread_rng()).unwrap().clone();
if r.1.data.typ == ItemType::Category {
rel_slug = r.1.data.slug;
rel_id = cynic::Id::new(r.1.data.id);
is_using_existing_category = true;
break;
}
} };
}
}
let product_updated = ProductUpdated {
product: Some(Product {
Expand Down

0 comments on commit 5a3dee2

Please sign in to comment.