Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
sdankel committed Feb 5, 2025
1 parent 4f6bc41 commit 6f8bd67
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/api/publish.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rocket::serde::{Deserialize, Serialize};
use semver::Version;
use url::Url;
use uuid::Uuid;

Expand All @@ -9,6 +10,13 @@ pub struct PublishRequest {
pub urls: Option<Vec<Url>>,
}

/// The publish response.
#[derive(Serialize, Deserialize, Debug)]
pub struct PublishResponse {
pub name: String,
pub version: Version,
}

/// The response to an upload_project request.
#[derive(Serialize, Debug)]
pub struct UploadResponse {
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/publish.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::api::publish::PublishRequest;
use crate::db::error::DatabaseError;
use crate::db::Database;
use crate::models::{ApiToken, NewPackageDep, PackageVersion};
use crate::models::{ApiToken, NewPackageDep};
use forc_pkg::PackageManifest;
use semver::Version;
use thiserror::Error;
Expand Down Expand Up @@ -51,7 +51,7 @@ pub async fn handle_publish(
db: &Database,
request: &PublishRequest,
token: &ApiToken,
) -> Result<PackageVersion, PublishError> {
) -> Result<PublishInfo, PublishError> {
// Parse the forc manifest file and verify that the version is set.
let upload = db.conn().get_upload(request.upload_id)?;
// For now, only package manifests are supported. Workspace manifests will be supported in the future.
Expand Down Expand Up @@ -120,5 +120,5 @@ pub async fn handle_publish(

// TODO [https://github.com/FuelLabs/forc.pub/issues/28]: Publish to GitHub index repo.

Ok(package_version)
Ok(publish_info)
}
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate rocket;
use chrono::{DateTime, Utc};
use forc_pub::api::api_token::{CreateTokenRequest, CreateTokenResponse, Token, TokensResponse};
use forc_pub::api::pagination::{PaginatedResponse, Pagination};
use forc_pub::api::publish::{PublishRequest, UploadResponse};
use forc_pub::api::publish::{PublishRequest, PublishResponse, UploadResponse};
use forc_pub::api::search::{FullPackage, RecentPackagesResponse};
use forc_pub::api::ApiError;
use forc_pub::api::{
Expand Down Expand Up @@ -112,9 +112,12 @@ async fn publish(
db: &State<Database>,
request: Json<PublishRequest>,
auth: TokenAuth,
) -> ApiResult<EmptyResponse> {
) -> ApiResult<PublishResponse> {
match handle_publish(db, &request, &auth.token).await {
Ok(_) => Ok(Json(EmptyResponse)),
Ok(info) => Ok(Json(PublishResponse {
name: info.package_name,
version: info.num,
})),
Err(e) => Err(ApiError::Publish(e)),
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/db_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use forc_pub::api::pagination::Pagination;
use forc_pub::db::{Database, DbConn};
use forc_pub::handlers::publish::PublishInfo;
use forc_pub::models::{FullPackage, NewUpload, PackageVersion};
use semver::Version;
use serial_test::serial;
use url::Url;

Expand Down Expand Up @@ -178,7 +179,7 @@ fn test_package_versions() {
let request = PublishInfo {
package_name: TEST_PACKAGE_NAME.into(),
upload_id: upload.id,
num: TEST_VERSION_1.into(),
num: Version::parse(TEST_VERSION_1).unwrap(),
package_description: Some(TEST_DESCRIPTION.into()),
repository: Url::parse(TEST_URL_REPO).ok(),
documentation: Url::parse(TEST_URL_DOC).ok(),
Expand Down Expand Up @@ -243,7 +244,7 @@ fn test_package_versions() {
let request = PublishInfo {
package_name: TEST_PACKAGE_NAME.into(),
upload_id: upload.id,
num: TEST_VERSION_2.into(),
num: Version::parse(TEST_VERSION_2).unwrap(),
package_description: Some("test description 2".into()),
repository: Url::parse(TEST_URL_REPO).ok(),
documentation: Url::parse(TEST_URL_DOC).ok(),
Expand Down

0 comments on commit 6f8bd67

Please sign in to comment.