Skip to content

Commit e186f45

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/auto-clone-repo
2 parents efa8c38 + aeb43e7 commit e186f45

File tree

16 files changed

+862
-435
lines changed

16 files changed

+862
-435
lines changed

fplus-database/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ serde = { version = "1.0.164", features = ["derive", "std",
2424
serial_test = "3.0.0"
2525
sha1 = "0.10.6"
2626
serde_json = "1.0.96"
27-

fplus-database/src/database/allocators.rs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub async fn get_allocators() ->Result<Vec<AllocatorModel>, sea_orm::DbErr> {
2222
* @param installation_id: Option<i64> - The installation ID
2323
* @param multisig_address: Option<String> - The multisig address
2424
* @param verifiers_gh_handles: Option<String> - The GitHub handles of the verifiers
25+
* @param multisig_threshold: Option<i32> - The multisig threshold
2526
*
2627
* # Returns
2728
* @return Result<AllocatorModel, sea_orm::DbErr> - The result of the operation
@@ -32,16 +33,30 @@ pub async fn update_allocator(
3233
installation_id: Option<i64>,
3334
multisig_address: Option<String>,
3435
verifiers_gh_handles: Option<String>,
36+
multisig_threshold: Option<i32>
3537
) -> Result<AllocatorModel, sea_orm::DbErr> {
3638
let conn = get_database_connection().await?;
3739

3840
let existing_allocator = get_allocator(owner, repo).await?;
3941
if let Some(allocator_model) = existing_allocator {
4042
let mut allocator_active_model = allocator_model.into_active_model();
4143

42-
allocator_active_model.installation_id = Set(installation_id);
43-
allocator_active_model.multisig_address = Set(multisig_address);
44-
allocator_active_model.verifiers_gh_handles = Set(verifiers_gh_handles);
44+
//if fields are not None, update them
45+
if Some(installation_id) != None {
46+
allocator_active_model.installation_id = Set(installation_id);
47+
}
48+
49+
if Some(multisig_address.clone()) != None {
50+
allocator_active_model.multisig_address = Set(multisig_address);
51+
}
52+
53+
if Some(verifiers_gh_handles.clone()) != None {
54+
allocator_active_model.verifiers_gh_handles = Set(verifiers_gh_handles);
55+
}
56+
57+
if Some(multisig_threshold) != None {
58+
allocator_active_model.multisig_threshold = Set(multisig_threshold);
59+
}
4560

4661
let updated_model = allocator_active_model.update(&conn).await?;
4762

@@ -92,6 +107,7 @@ pub async fn create_or_update_allocator(
92107
installation_id: Option<i64>,
93108
multisig_address: Option<String>,
94109
verifiers_gh_handles: Option<String>,
110+
multisig_threshold: Option<i32>
95111
) -> Result<AllocatorModel, sea_orm::DbErr> {
96112

97113
let existing_allocator = get_allocator(&owner, &repo).await?;
@@ -102,20 +118,34 @@ pub async fn create_or_update_allocator(
102118
allocator_active_model.installation_id = Set(installation_id);
103119
allocator_active_model.multisig_address = Set(multisig_address);
104120
allocator_active_model.verifiers_gh_handles = Set(verifiers_gh_handles);
121+
allocator_active_model.multisig_threshold = Set(multisig_threshold);
105122

106123
let updated_model = allocator_active_model.update(&conn).await?;
107124

108125
Ok(updated_model)
109126
} else {
110-
let new_allocator = ActiveModel {
127+
let mut new_allocator = ActiveModel {
111128
owner: Set(owner),
112129
repo: Set(repo),
113-
installation_id: Set(installation_id),
114-
multisig_address: Set(multisig_address),
115-
verifiers_gh_handles: Set(verifiers_gh_handles),
116130
..Default::default()
117131
};
132+
133+
if installation_id.is_some() {
134+
new_allocator.installation_id = Set(installation_id);
135+
}
136+
137+
if multisig_address.is_some() {
138+
new_allocator.multisig_address = Set(multisig_address);
139+
}
140+
141+
if verifiers_gh_handles.is_some() {
142+
new_allocator.verifiers_gh_handles = Set(verifiers_gh_handles);
143+
}
118144

145+
if multisig_threshold.is_some() {
146+
new_allocator.multisig_threshold = Set(multisig_threshold);
147+
}
148+
119149
let conn = get_database_connection().await.expect("Failed to get DB connection");
120150
new_allocator.insert(&conn).await
121151
}

fplus-database/src/database/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pub mod allocators;
2-
pub mod applications;
2+
pub mod applications;

fplus-database/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ mod tests {
103103
let installation_id = Some(1234);
104104
let multisig_address = Some("0x1234567890".to_string());
105105
let verifiers_gh_handles = Some("test_verifier_1, test_verifier_2".to_string());
106+
let multisig_threshold = Some(2);
106107

107108
let result = database::allocators::create_or_update_allocator(
108109
owner,
109110
repo,
110111
installation_id,
111112
multisig_address,
112113
verifiers_gh_handles,
114+
multisig_threshold
113115
).await;
114116
assert!(result.is_ok());
115117
}
@@ -150,13 +152,15 @@ mod tests {
150152
let multisig_address = Some
151153
("0x1234567890".to_string());
152154
let verifiers_gh_handles = Some("test_verifier_1, test_verifier_2".to_string());
155+
let multisig_threshold = Some(2);
153156

154157
let result = database::allocators::create_or_update_allocator(
155158
owner.clone(),
156159
repo.clone(),
157160
installation_id,
158161
multisig_address,
159162
verifiers_gh_handles,
163+
multisig_threshold
160164
).await;
161165
assert!(result.is_ok());
162166
}
@@ -166,13 +170,15 @@ mod tests {
166170
let installation_id = Some(1234);
167171
let multisig_address = Some("0x0987654321".to_string());
168172
let verifiers_gh_handles = Some("test_verifier_3, test_verifier_4".to_string());
173+
let multisig_threshold = Some(1);
169174

170175
let result = database::allocators::update_allocator(
171176
&owner,
172177
&repo,
173178
installation_id,
174179
multisig_address,
175180
verifiers_gh_handles,
181+
multisig_threshold
176182
).await;
177183
assert!(result.is_ok());
178184
}
@@ -217,13 +223,15 @@ mod tests {
217223
let installation_id = Some(1234);
218224
let multisig_address = Some("0x1234567890".to_string());
219225
let verifiers_gh_handles = Some("test_verifier_1, test_verifier_2".to_string());
226+
let multisig_threshold = Some(2);
220227

221228
let result = database::allocators::create_or_update_allocator(
222229
owner.clone(),
223230
repo.clone(),
224231
installation_id,
225232
multisig_address,
226233
verifiers_gh_handles,
234+
multisig_threshold
227235
).await;
228236

229237
assert!(result.is_ok());

fplus-database/src/models/allocators.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct Model {
1414
pub multisig_address: Option<String>,
1515
#[sea_orm(column_type = "Text", nullable)]
1616
pub verifiers_gh_handles: Option<String>,
17+
pub multisig_threshold: Option<i32>,
1718
}
1819

1920
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

fplus-http-server/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ async fn main() -> std::io::Result<()> {
5858
.service(router::allocator::allocator)
5959
.service(router::allocator::delete)
6060
.service(router::allocator::create_from_json)
61+
.service(router::application::propose)
6162
})
6263
.bind(("0.0.0.0", 8080))?
6364
.run()

fplus-http-server/src/router/allocator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub async fn create_from_json(file: web::Json<ChangedAllocator>) -> actix_web::R
5050
Some(model.installation_id as i64),
5151
Some(model.multisig_address),
5252
verifiers_gh_handles,
53+
model.multisig_threshold
5354
).await {
5455
Ok(allocator_model) => allocator_model,
5556
Err(e) => return Ok(HttpResponse::BadRequest().body(e.to_string())),
@@ -97,6 +98,7 @@ pub async fn update(
9798
info.installation_id,
9899
info.multisig_address.clone(),
99100
info.verifiers_gh_handles.clone(),
101+
info.multisig_threshold
100102
).await {
101103
Ok(allocator_model) => HttpResponse::Ok().json(allocator_model),
102104
Err(e) => {

0 commit comments

Comments
 (0)