feat: add repo validation

This commit is contained in:
2026-01-20 15:58:10 -08:00
parent 856bde3d97
commit 43c9b7c238
8 changed files with 83 additions and 23 deletions

View File

@@ -17,7 +17,7 @@ pub struct UserRepository {
#[derive(Serialize, Deserialize)]
pub struct RepositorySchema {
pub id: String,
pub name: String,
pub full_name: String,
}
impl UserRepository {
@@ -58,7 +58,7 @@ impl UserRepository {
.ok()?
.strip_prefix("REPO#")?
.to_string(),
name: item.get("full_name")?.as_s().ok()?.to_string(),
full_name: item.get("full_name")?.as_s().ok()?.to_string(),
})
})
.collect::<Vec<RepositorySchema>>();
@@ -66,6 +66,20 @@ impl UserRepository {
Ok(response)
}
pub async fn global_repositories(&self) -> Result<HttpResponse> {
let response = self
.dynamodb_client
.query()
.key_condition_expression("pk = :pk")
.expression_attribute_values(":pk", AttributeValue::S("REPOS".into()))
.send()
.await?
.items()
.iter()
.filter_map(|item| Some(item.get("full_name")?.as_s().ok()?.to_string()))
.collect::<Vec<String>>();
}
pub async fn add_repository(
&self,
user_id: &str,
@@ -79,7 +93,7 @@ impl UserRepository {
.condition_expression("attribute_not_exists(sk)")
.item("pk", AttributeValue::S(format!("USER#{user_id}")))
.item("sk", AttributeValue::S(format!("REPO#{}", repo.id)))
.item("full_name", AttributeValue::S(repo.name.to_string()))
.item("full_name", AttributeValue::S(repo.full_name.to_string()))
.item("gsi1pk", AttributeValue::S("REPOS".into()))
.item("gsi1sk", AttributeValue::S(now.clone()))
.item("imported_at", AttributeValue::S(now))