Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
sdankel committed Jan 10, 2025
1 parent 6ba1e32 commit c270583
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 45 deletions.
49 changes: 7 additions & 42 deletions src/db/package_version.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
use super::error::DatabaseError;
use super::{models, schema, DbConn};
use crate::api::publish::PublishRequest;
use crate::models::ApiToken;
use crate::schema::api_tokens::expires_at;
use crate::schema::package_versions::{package_description, urls};
use crate::schema::packages::package_name;

use super::error::DatabaseError;
use super::{api, models, schema, DbConn};
use diesel::prelude::*;
use diesel::upsert::excluded;
use std::time::{Duration, SystemTime};
use uuid::Uuid;

impl DbConn {
Expand All @@ -22,21 +17,21 @@ impl DbConn {
// Check if the package exists.
let pkg_name = request.package_name.clone();
let package = if let Some(existing_package) = schema::packages::table
.filter(schema::packages::package_name.eq(package_name.clone()))
.filter(schema::packages::package_name.eq(package_name))
.select(schema::packages::all_columns)
.first::<models::Package>(self.inner())
.optional()
.map_err(|err| DatabaseError::QueryFailed(pkg_name.clone(), err))?
{
if existing_package.user_owner != api_token.user_id.clone() {
if existing_package.user_owner != api_token.user_id {
// The package exists but the user is not the owner.
return Err(DatabaseError::InvalidPublishToken);
}
Ok(existing_package)
} else {
// Insert a new package.
let new_package: models::NewPackage = models::NewPackage {
user_owner: api_token.user_id.clone(),
user_owner: api_token.user_id,
package_name: pkg_name.clone(),
};

Expand All @@ -51,8 +46,8 @@ impl DbConn {
// Insert a new package version.
let new_version = models::NewPackageVersion {
package_id: package.id,
publish_token: api_token.id.clone(),
published_by: api_token.user_id.clone(),
publish_token: api_token.id,
published_by: api_token.user_id,
upload_id: request.upload_id,
num: request.num.clone(),
package_description: request.package_description.clone(),
Expand Down Expand Up @@ -105,34 +100,4 @@ impl DbConn {
.first::<models::Package>(self.inner())
.map_err(|err| DatabaseError::NotFound(name.clone(), err))
}

// /// Fetch a user given the user ID.
// pub fn get_session(&mut self, session_id: Uuid) -> Result<models::Session, DatabaseError> {
// schema::sessions::table
// .filter(schema::sessions::id.eq(session_id))
// .select(models::Session::as_returning())
// .first::<models::Session>(self.inner())
// .map_err(|_| DatabaseError::NotFound(session_id.to_string()))
// }

// /// Fetch a user from the database for a given session ID.
// pub fn get_user_for_session(
// &mut self,
// session_id: Uuid,
// ) -> Result<models::User, DatabaseError> {
// schema::sessions::table
// .inner_join(schema::users::table)
// .filter(schema::sessions::id.eq(session_id))
// .select(models::User::as_returning())
// .first::<models::User>(self.inner())
// .map_err(|_| DatabaseError::NotFound(session_id.to_string()))
// }

// /// Delete a session given its ID.
// pub fn delete_session(&mut self, session_id: Uuid) -> Result<(), DatabaseError> {
// diesel::delete(schema::sessions::table.filter(schema::sessions::id.eq(session_id)))
// .execute(self.inner())
// .map_err(|_| DatabaseError::NotFound(session_id.to_string()))?;
// Ok(())
// }
}
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use forc_pub::github::handle_login;
use forc_pub::middleware::cors::Cors;
use forc_pub::middleware::session_auth::{SessionAuth, SESSION_COOKIE_NAME};
use forc_pub::middleware::token_auth::TokenAuth;
use forc_pub::models::NewPackageVersion;
use forc_pub::pinata::{PinataClient, PinataClientImpl};
use forc_pub::upload::{handle_project_upload, install_forc_at_path, UploadError};
use forc_pub::util::validate_or_format_semver;
Expand Down
4 changes: 2 additions & 2 deletions src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ mod tests {
let forc_version = "0.66.5";
let forc_path_str = format!("forc-{forc_version}");
let forc_path = PathBuf::from(&forc_path_str);
fs::create_dir_all(forc_path.clone()).unwrap();
let forc_path = fs::canonicalize(forc_path.clone()).unwrap();
fs::create_dir_all(forc_path.clone()).ok();
let forc_path = fs::canonicalize(forc_path.clone()).expect("forc path ok");
install_forc_at_path(forc_version, &forc_path).expect("forc installed");

let mock_client = MockPinataClient::new().await.expect("mock pinata client");
Expand Down
4 changes: 4 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ mod tests {

#[test]
fn test_load_env() {
// Save the current directory
let original_dir = env::current_dir().unwrap();

// Create a temporary directory
let dir = tempdir().unwrap();
let env_path = dir.path().join(".env");
Expand All @@ -92,5 +95,6 @@ mod tests {

// Cleanup
env::remove_var("TEST_VAR");
env::set_current_dir(&original_dir).unwrap();
}
}

0 comments on commit c270583

Please sign in to comment.