Skip to content

Commit

Permalink
Merge pull request #44 from filecoin-project/schema-update
Browse files Browse the repository at this point in the history
adding v1 file schema
  • Loading branch information
jbesraa authored Oct 30, 2023
2 parents accf593 + 969ba8a commit 7630568
Show file tree
Hide file tree
Showing 15 changed files with 1,378 additions and 1,306 deletions.
9 changes: 6 additions & 3 deletions fplus-http-server/src/router/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use fplus_lib::core::{

#[post("/application")]
pub async fn create(info: web::Json<CreateApplicationInfo>) -> impl Responder {
match LDNApplication::new(info.into_inner()).await {
match LDNApplication::new_from_issue(info.into_inner()).await {
Ok(app) => HttpResponse::Ok().body(format!(
"Created new application for issue: {}",
app.application_id.clone()
Expand Down Expand Up @@ -37,13 +37,15 @@ pub async fn trigger(
return HttpResponse::BadRequest().body(e.to_string());
}
};
dbg!(&ldn_application);
match ldn_application
.complete_governance_review(info.into_inner())
.await
{
Ok(app) => HttpResponse::Ok().body(serde_json::to_string_pretty(&app).unwrap()),
Err(_) => {
return HttpResponse::BadRequest().body("Application is not in the correct state");
Err(e) => {
return HttpResponse::BadRequest()
.body(format!("Application is not in the correct state {}", e));
}
}
}
Expand Down Expand Up @@ -81,6 +83,7 @@ pub async fn approve(
return HttpResponse::BadRequest().body(e.to_string());
}
};
dbg!(&ldn_application);
match ldn_application
.complete_new_application_approval(info.into_inner())
.await
Expand Down
2 changes: 1 addition & 1 deletion fplus-lib/src/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::Cursor;

use base64;

use crate::core::application::ApplicationFile;
use crate::core::application::file::ApplicationFile;

pub fn decode(i: &str) -> Option<ApplicationFile> {
let mut binding = Cursor::new(i);
Expand Down
128 changes: 128 additions & 0 deletions fplus-lib/src/core/application/allocation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
use chrono::Utc;

use super::file::{
Allocation, AllocationRequest, AllocationRequestType, Allocations, Notaries, Notary,
};

impl Default for Notaries {
fn default() -> Self {
Self(vec![])
}
}

impl Notaries {
pub fn add(&self, signer: Notary) -> Self {
let mut res = self.0.clone();
res.push(signer);
Self(res)
}
}

impl AllocationRequest {
pub fn new(
actor: String,
id: String,
kind: AllocationRequestType,
allocation_amount: String,
) -> Self {
Self {
actor,
id,
kind,
allocation_amount,
is_active: true,
}
}
}

impl Allocation {
pub fn new(request_information: AllocationRequest) -> Self {
Self {
id: request_information.id,
request_type: request_information.kind,
created_at: Utc::now().to_string(),
updated_at: Utc::now().to_string(),
is_active: true,
amount: request_information.allocation_amount,
signers: Notaries::default(),
}
}
}

impl Default for Allocations {
fn default() -> Self {
Self(vec![])
}
}

impl Allocations {
pub fn init(request_information: AllocationRequest) -> Self {
let allocation = Allocation::new(request_information);
Self(vec![allocation])
}

// should be changed to option
pub fn find_one(&self, request_id: String) -> Option<Allocation> {
let curr: Vec<Allocation> = self.0.clone();
let mut allocation: Option<Allocation> = None;
for alloc in curr.iter() {
if alloc.id == request_id {
allocation = Some(alloc.clone());
break;
}
}
allocation
}

// should be changed to option
pub fn is_active(&self, request_id: String) -> bool {
let curr: Vec<Allocation> = self.0.clone();
let mut is_active = false;
for alloc in curr.iter() {
if alloc.id == request_id {
is_active = alloc.is_active;
break;
}
}
is_active
}

pub fn add_signer(&self, request_id: String, signer: Notary) -> Self {
let mut res: Vec<Allocation> = self.0.clone();
for allocation in res.iter_mut() {
if allocation.id == request_id && allocation.is_active {
allocation.signers = allocation.signers.add(signer);
break;
}
}
Self(res)
}

pub fn add_signer_and_complete(&self, request_id: String, signer: Notary) -> Self {
let mut res: Vec<Allocation> = self.0.clone();
for allocation in res.iter_mut() {
if allocation.id == request_id && allocation.is_active {
allocation.signers = allocation.signers.add(signer);
allocation.is_active = false;
break;
}
}
Self(res)
}

pub fn complete_allocation(&self, request_id: String) -> Self {
let mut res: Vec<Allocation> = self.0.clone();
for allocation in res.iter_mut() {
if allocation.id == request_id && allocation.is_active {
allocation.is_active = false;
}
}
Self(res)
}

pub fn push(&mut self, request: AllocationRequest) -> Self {
let allocation = Allocation::new(request);
self.0.push(allocation);
self.clone()
}
}
169 changes: 0 additions & 169 deletions fplus-lib/src/core/application/allocations.rs

This file was deleted.

24 changes: 24 additions & 0 deletions fplus-lib/src/core/application/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use super::file::Client;

impl Client {
fn new(i: Client) -> Self {
Self { ..i }
}

fn validate(&self) -> bool {
let Client {
name,
region,
industry,
website,
social_media,
role,
} = self;
name.len() > 0
&& region.len() > 0
&& industry.len() > 0
&& website.len() > 0
&& social_media.len() > 0
&& role.len() > 0
}
}
Loading

0 comments on commit 7630568

Please sign in to comment.