Skip to content

Commit

Permalink
NPM Support Work
Browse files Browse the repository at this point in the history
  • Loading branch information
wyatt-herkamp committed Aug 28, 2024
1 parent d0796c2 commit 53e223a
Show file tree
Hide file tree
Showing 43 changed files with 1,937 additions and 511 deletions.
100 changes: 40 additions & 60 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions crates/core/src/builder_error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use derive_builder::UninitializedFieldError;
use thiserror::Error;

#[derive(Debug, Clone, Error)]
pub enum BuilderError {
#[error("Uninitialized Field: {0}.")]
UninitializedField(&'static str),
#[error("Invalid Field: {0}.")]
InvalidField(String),
}

impl From<UninitializedFieldError> for BuilderError {
fn from(err: UninitializedFieldError) -> Self {
BuilderError::UninitializedField(err.field_name())
}
}
3 changes: 3 additions & 0 deletions crates/core/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

pub mod project;
pub mod repository;
pub mod storage;
Expand Down
11 changes: 11 additions & 0 deletions crates/core/src/database/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,15 @@ impl DBProjectVersion {
.await?;
Ok(version)
}
pub async fn get_all_versions(
project_id: Uuid,
database: &PgPool,
) -> Result<Vec<Self>, sqlx::Error> {
let versions =
sqlx::query_as::<_, Self>(r#"SELECT * FROM project_versions WHERE project_id = $1"#)
.bind(project_id)
.fetch_all(database)
.await?;
Ok(versions)
}
}
10 changes: 7 additions & 3 deletions crates/core/src/database/project/new.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use crate::builder_error::BuilderError;
use crate::repository::project::{ReleaseType, VersionData};
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use sqlx::{types::Json, PgPool};
use tracing::info;
use utoipa::ToSchema;
use uuid::Uuid;

use crate::repository::project::{ReleaseType, VersionData};

use super::DBProject;
#[derive(Debug, Clone, PartialEq, Eq, Builder)]
#[builder(build_fn(error = "BuilderError"))]

pub struct NewProject {
#[builder(default)]
pub scope: Option<String>,
Expand Down Expand Up @@ -111,6 +113,8 @@ impl NewProjectMember {
}

#[derive(Debug, Clone, PartialEq, Eq, Builder)]
#[builder(build_fn(error = "BuilderError"))]

pub struct NewVersion {
pub project_id: Uuid,
/// The version of the project
Expand Down Expand Up @@ -159,7 +163,7 @@ impl NewVersion {
sqlx::query(
r#"
UPDATE projects
SET latest_release = $1 AND latest_pre_release = $1
SET latest_release = $1, latest_pre_release = $1
WHERE id = $2
"#,
)
Expand Down
20 changes: 10 additions & 10 deletions crates/core/src/database/project/update.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use derive_builder::Builder;
use http::version;
use sqlx::{types::Json, Execute, PgPool, QueryBuilder};
use tracing::{info, instrument, warn};

Expand All @@ -8,10 +6,8 @@ use crate::repository::project::{ReleaseType, VersionData};
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct UpdateProjectVersion {
pub release_type: Option<ReleaseType>,
//#[builder(default)]
//pub publisher: Option<i32>,
//#[builder(default)]
//pub version_page: Option<String>,
pub publisher: Option<Option<i32>>,
pub version_page: Option<Option<String>>,
pub extra: Option<VersionData>,
}

Expand All @@ -24,14 +20,18 @@ impl UpdateProjectVersion {
separated.push("release_type = ");
separated.push_bind_unseparated(release_type);
}
//if let Some(version_page) = self.version_page {
// separated.push("user_manager = ");
// separated.push_bind_unseparated(version_page);
//}
if let Some(extra) = self.extra {
separated.push("extra = ");
separated.push_bind_unseparated(Json(extra));
}
if let Some(version_page) = self.version_page {
separated.push("user_manager = ");
separated.push_bind_unseparated(version_page);
}
if let Some(publisher) = self.publisher {
separated.push("publisher = ");
separated.push_bind_unseparated(publisher);
}
query.push(" WHERE id = ");
query.push_bind(version_id);
let query: sqlx::query::Query<sqlx::Postgres, sqlx::postgres::PgArguments> = query.build();
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod user;
pub type ConfigTimeStamp = chrono::DateTime<chrono::FixedOffset>;
pub mod builder_error;
pub mod database;
pub mod repository;
pub mod storage;
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/repository/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub enum ProjectState {
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema, Default, Builder)]
#[serde(default)]
#[builder(build_fn(error = "crate::builder_error::BuilderError"))]

pub struct VersionData {
#[builder(default)]
pub documentation_url: Option<String>,
Expand Down
Loading

0 comments on commit 53e223a

Please sign in to comment.