Skip to content

Commit

Permalink
Merge pull request #98 from filecoin-project/template-accomodation
Browse files Browse the repository at this point in the history
Template accomodation
  • Loading branch information
jbesraa authored Dec 13, 2023
2 parents 2b69229 + a5aad63 commit 1f64657
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 91 deletions.
10 changes: 4 additions & 6 deletions fplus-http-server/src/router/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ pub async fn validate_application_flow(
let pr_number = info.pr_number.trim_matches('"').parse::<u64>();

match pr_number {
Ok(pr_number) => {
match LDNApplication::validate_flow(pr_number, &info.user_handle).await {
Ok(result) => HttpResponse::Ok().json(result),
Err(e) => HttpResponse::InternalServerError().json(e.to_string()),
}
}
Ok(pr_number) => match LDNApplication::validate_flow(pr_number, &info.user_handle).await {
Ok(result) => HttpResponse::Ok().json(result),
Err(e) => HttpResponse::InternalServerError().json(e.to_string()),
},
Err(_) => HttpResponse::BadRequest().json("Invalid PR Number"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion fplus-http-server/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use actix_web::{get, HttpResponse, Responder};

pub mod application;
pub mod blockchain;
pub mod rkh;
pub mod notary;
pub mod rkh;

/// Return server health status
#[get("/health")]
Expand Down
19 changes: 8 additions & 11 deletions fplus-http-server/src/router/notary.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
use actix_web::{get, post, HttpResponse, Responder};
use fplus_lib::core::{LDNApplication, application::file::LDNActorsResponse};
use fplus_lib::core::{application::file::LDNActorsResponse, LDNApplication};

#[get("/notaries")]
pub async fn notaries() -> actix_web::Result<impl Responder> {
match LDNApplication::fetch_notaries().await {
Ok(notaries) => {
Ok(HttpResponse::Ok().json(notaries))
}
Err(e) => {
Ok(HttpResponse::InternalServerError().body(e.to_string()))
}
Ok(notaries) => Ok(HttpResponse::Ok().json(notaries)),
Err(e) => Ok(HttpResponse::InternalServerError().body(e.to_string())),
}
}

#[get("/ldn-actors")]
pub async fn ldn_actors() -> actix_web::Result<impl Responder> {
match LDNApplication::fetch_rkh_and_notary_gh_users().await {
Ok((governance_gh_handles, notary_gh_handles)) => {
let response = LDNActorsResponse { governance_gh_handles, notary_gh_handles };
let response = LDNActorsResponse {
governance_gh_handles,
notary_gh_handles,
};
Ok(HttpResponse::Ok().json(response))
}
Err(e) => {
Ok(HttpResponse::InternalServerError().body(e.to_string()))
}
Err(e) => Ok(HttpResponse::InternalServerError().body(e.to_string())),
}
}

Expand Down
10 changes: 2 additions & 8 deletions fplus-http-server/src/router/rkh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ use fplus_lib::core::LDNApplication;
#[get("/rkhs")]
pub async fn rkhs() -> actix_web::Result<impl Responder> {
match LDNApplication::fetch_rkh().await {
Ok(notaries) => {
Ok(HttpResponse::Ok().json(notaries))
}
Err(e) => {
Ok(HttpResponse::InternalServerError().body(e.to_string()))
}
Ok(notaries) => Ok(HttpResponse::Ok().json(notaries)),
Err(e) => Ok(HttpResponse::InternalServerError().body(e.to_string())),
}
}


9 changes: 6 additions & 3 deletions fplus-lib/src/core/application/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ impl Client {
fn new(i: Client) -> Self {
Self { ..i }
}

fn validate(&self) -> bool {
//TODO: Check that none of the values are not default values
// Used after finished the parsing
pub fn validate(&self) -> bool {
let Client {
applicant,
name,
region,
industry,
Expand All @@ -15,7 +17,8 @@ impl Client {
social_media_type,
role,
} = self;
name.len() > 0
applicant.len() > 0
&& name.len() > 0
&& region.len() > 0
&& industry.len() > 0
&& website.len() > 0
Expand Down
97 changes: 76 additions & 21 deletions fplus-lib/src/core/application/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct ApplicationFile {
#[serde(rename = "Project")]
pub project: Project,
#[serde(rename = "Datacap")]
pub datacap: Datacap,
pub datacap: ApplicationDatacap,
#[serde(rename = "Lifecycle")]
pub lifecycle: LifeCycle,
#[serde(rename = "Allocation Requests")]
Expand All @@ -47,53 +47,108 @@ pub struct ApplicationFile {

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Client {
#[serde(rename = "Name")]
#[serde(rename = "DataCap Applicant")]
pub applicant: String,
#[serde(rename = "Data Owner Name")]
pub name: String,
#[serde(rename = "Region")]
#[serde(rename = "Data Owner Country/Region")]
pub region: String,
#[serde(rename = "Industry")]
#[serde(rename = "Data Owner Industry")]
pub industry: String,
#[serde(rename = "Website")]
pub website: String,
#[serde(rename = "Social Media")]
#[serde(rename = "Social Media Handle")]
pub social_media: String,
#[serde(rename = "Social Media Type")]
pub social_media_type: String,
#[serde(rename = "Role")]
#[serde(rename = "What is your role related to the dataset")]
pub role: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Datacap {
#[serde(rename = "Type")]
pub _group: DatacapGroup,
#[serde(rename = "Group")]
pub group: DatacapGroup,
#[serde(rename = "Data Type")]
pub data_type: DataType,
#[serde(rename = "Total Requested Amount")]
#[serde(rename = "Total amount of DataCap being requested")]
pub total_requested_amount: String,
#[serde(rename = "Single Size Dataset")]
#[serde(rename = "Unit for total amount of DataCap being requested")]
pub total_requested_amount_unit: String,
#[serde(rename = "Expected size of single dataset (one copy)")]
pub single_size_dataset: String,
#[serde(rename = "Replicas")]
#[serde(rename = "Unit for expected size of single dataset")]
pub single_size_dataset_unit: String,
#[serde(rename = "Number of Replicas to Store")]
pub replicas: u8,
#[serde(rename = "Weekly Allocation")]
#[serde(rename = "Weekly allocation of DataCap requested")]
pub weekly_allocation: String,
#[serde(rename = "Custom multisig", skip_serializing, default)]
#[serde(rename = "Unit for Weekly Allocation of DataCap Requested")]
pub weekly_allocation_unit: String,
#[serde(rename = "Custom Multisig", skip_serializing, default)]
pub custom_multisig: String,
#[serde(rename = "Identifier", skip_serializing, default)]
pub identifier: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ApplicationDatacap {
#[serde(rename = "Group")]
pub group: DatacapGroup,
#[serde(rename = "Data Type")]
pub data_type: DataType,
#[serde(rename = "Total amount of DataCap being requested")]
pub total_requested_amount: String,
#[serde(rename = "Expected size of single dataset (one copy)")]
pub single_size_dataset: String,
#[serde(rename = "Number of Replicas to Store")]
pub replicas: u8,
#[serde(rename = "Weekly allocation of DataCap requested")]
pub weekly_allocation: String,
#[serde(rename = "Custom Multisig", skip_serializing, default)]
pub custom_multisig: String,
#[serde(rename = "Identifier", skip_serializing, default)]
pub identifier: String,
}

impl From<Datacap> for ApplicationDatacap {
fn from(datacap: Datacap) -> Self {
ApplicationDatacap {
group: datacap.group,
data_type: datacap.data_type,
total_requested_amount: format!(
"{} {}",
datacap.total_requested_amount, datacap.total_requested_amount_unit
),
single_size_dataset: format!(
"{} {}",
datacap.single_size_dataset, datacap.single_size_dataset_unit
),
replicas: datacap.replicas,
weekly_allocation: format!(
"{} {}",
datacap.weekly_allocation, datacap.weekly_allocation_unit
),
custom_multisig: datacap.custom_multisig,
identifier: datacap.identifier,
}
}
}

impl Default for Datacap {
fn default() -> Self {
Self {
_group: DatacapGroup::LDN,
group: DatacapGroup::LDN,
data_type: DataType::Slingshot,
total_requested_amount: "0".to_string(),
single_size_dataset: "0".to_string(),
total_requested_amount: String::new(),
total_requested_amount_unit: String::new(),
single_size_dataset: String::new(),
single_size_dataset_unit: String::new(),
replicas: 0,
weekly_allocation: "0".to_string(),
custom_multisig: "0".to_string(),
identifier: "0".to_string(),
weekly_allocation: String::new(),
weekly_allocation_unit: String::new(),
custom_multisig: String::new(),
identifier: String::new(),
}
}
}
Expand Down Expand Up @@ -172,13 +227,13 @@ pub enum StorageProviders {
pub struct Project {
#[serde(rename = "Project Id")]
pub project_id: String,
#[serde(rename = "Brief history of your project and organization")]
#[serde(rename = "Share a brief history of your project and organization")]
pub history: String,
#[serde(rename = "Is this project associated with other projects/ecosystem stakeholders?")]
pub associated_projects: String,
#[serde(rename = "Describe the data being stored onto Filecoin")]
pub stored_data_desc: String,
#[serde(rename = "Where was the data currently stored in this dataset sourced from} ")]
#[serde(rename = "Where was the data currently stored in this dataset sourced from")]
pub previous_stoarge: String,
#[serde(rename = "How do you plan to prepare the dataset")]
pub dataset_prepare: String,
Expand Down
2 changes: 1 addition & 1 deletion fplus-lib/src/core/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl file::ApplicationFile {
id: String,
client: file::Client,
project: file::Project,
datacap: file::Datacap,
datacap: file::ApplicationDatacap,
) -> Self {
let allocation = Allocations::default();
let lifecycle = LifeCycle::submitted(id.clone(), multisig_address.clone());
Expand Down
Loading

0 comments on commit 1f64657

Please sign in to comment.