Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/update application schema #20

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/core/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct ApplicationFile {
pub id: String,
pub _type: ApplicationType,
pub info: ApplicationInfo,
pub version: u64,
}

impl ApplicationFile {
Expand All @@ -28,6 +29,7 @@ impl ApplicationFile {
id: application_id,
_type: ApplicationType::LDN,
info: app_info,
version: 1,
}
}

Expand All @@ -46,6 +48,7 @@ impl ApplicationFile {
id: self.id.clone(),
_type: self._type.clone(),
info,
version: 1,
}
}

Expand All @@ -67,6 +70,7 @@ impl ApplicationFile {
id: self.id.clone(),
_type: self._type.clone(),
info,
version: 1,
};
}
ApplicationAllocationTypes::Removal => {
Expand Down Expand Up @@ -98,6 +102,7 @@ impl ApplicationFile {
id: self.id.clone(),
_type: self._type.clone(),
info,
version: 1,
}
}
}
71 changes: 45 additions & 26 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ use actix_web::{
web::Bytes,
};
use chrono::Utc;
use octocrab::models::{pulls::{PullRequest, FileDiff}, repos::ContentItems};
use futures::future;
use octocrab::models::{
pulls::{FileDiff, PullRequest},
repos::ContentItems,
};
use reqwest::Response;

use self::application::{
Expand Down Expand Up @@ -134,37 +137,53 @@ impl LDNApplication {
let gh: GithubWrapper = GithubWrapper::new();
let mut apps: Vec<ApplicationFile> = Vec::new();
let pull_requests = gh.list_pull_requests().await.unwrap();
let pull_requests = future::try_join_all(pull_requests
.into_iter()
.map(|pr: PullRequest| {
let number = pr.number;
gh.get_pull_request_files(number)
})
.collect::<Vec<_>>()).await.unwrap().into_iter().flatten();
let pull_requests: Vec<Response> = match future::try_join_all(pull_requests
.into_iter()
.map(|fd: FileDiff| {
reqwest::Client::new()
.get(&fd.raw_url.to_string())
.send()
})
.collect::<Vec<_>>()).await {
Ok(res) => res,
Err(_) => return Err(LDNApplicationError::LoadApplicationError("Failed to get pull request files".to_string()))
let pull_requests = future::try_join_all(
pull_requests
.into_iter()
.map(|pr: PullRequest| {
let number = pr.number;
gh.get_pull_request_files(number)
})
.collect::<Vec<_>>(),
)
.await
.unwrap()
.into_iter()
.flatten();
let pull_requests: Vec<Response> = match future::try_join_all(
pull_requests
.into_iter()
.map(|fd: FileDiff| reqwest::Client::new().get(&fd.raw_url.to_string()).send())
.collect::<Vec<_>>(),
)
.await
{
Ok(res) => res,
Err(_) => {
return Err(LDNApplicationError::LoadApplicationError(
"Failed to get pull request files".to_string(),
))
}
};
let pull_requests = match future::try_join_all(pull_requests
.into_iter()
.map(|r: Response| {
r.text()
})
.collect::<Vec<_>>()).await {
let pull_requests = match future::try_join_all(
pull_requests
.into_iter()
.map(|r: Response| r.text())
.collect::<Vec<_>>(),
)
.await
{
Ok(res) => res,
Err(_) => return Err(LDNApplicationError::LoadApplicationError("Failed to get pull request files".to_string()))
Err(_) => {
return Err(LDNApplicationError::LoadApplicationError(
"Failed to get pull request files".to_string(),
))
}
};
for r in pull_requests {
match serde_json::from_str::<ApplicationFile>(&r) {
Ok(app) => apps.push(app),
Err(_) => continue
Err(_) => continue,
}
}
Ok(apps)
Expand Down
1 change: 1 addition & 0 deletions src/db/collections/logs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion src/external_services/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl GithubWrapper<'static> {

pub async fn get_pull_request_files(
&self,
pr_number: u64
pr_number: u64,
) -> Result<Vec<octocrab::models::pulls::FileDiff>, OctocrabError> {
let iid: Page<octocrab::models::pulls::FileDiff> = self
.inner
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate markdown;
use std::sync::Mutex;

use actix_web::middleware::Logger;
use actix_web::{App, HttpServer, web};
use actix_web::{web, App, HttpServer};
use env_logger;

pub(crate) mod base64;
Expand All @@ -29,7 +29,7 @@ pub(crate) mod router;
#[tokio::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("debug"));
let client =match db::setup::setup().await {
let client = match db::setup::setup().await {
Ok(client) => client,
Err(e) => panic!("Error setting up database: {}", e),
};
Expand Down
28 changes: 14 additions & 14 deletions src/router/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use actix_web::{get, post, web, HttpResponse, Responder};
///
/// # Example
/// ```plaintext
/// curl --header "Content-Type: application/json"
/// --request POST
/// --data '{"application_id": "0x1234"}'
/// curl --header "Content-Type: application/json"
/// --request POST
/// --data '{"application_id": "0x1234"}'
/// http://localhost:8080/application
/// ```
///
Expand All @@ -39,9 +39,9 @@ pub async fn create_application(info: web::Json<CreateApplicationInfo>) -> impl
///
/// # Example
/// ```plaintext
/// curl --header "Content-Type: application/json"
/// --request POST
/// --data '{"actor": "JohnDoe"}'
/// curl --header "Content-Type: application/json"
/// --request POST
/// --data '{"actor": "JohnDoe"}'
/// http://localhost:8080/application/0x1234/trigger
/// ```
///
Expand Down Expand Up @@ -82,16 +82,16 @@ pub async fn trigger_application(
///
/// # Example
/// ```plaintext
/// curl --header "Content-Type: application/json"
/// --request POST
/// curl --header "Content-Type: application/json"
/// --request POST
/// --data '{
/// "signer": {
/// "signing_address": "0x1234567890abcdef1234567890abcdef12345678",
/// "time_of_signature": "2023-08-07T14:30:00Z",
/// "message_cid": "QmXYZ1234567890abcdef1234567890abcdef12345678"
/// },
/// "request_id": "exampleRequestId123"
/// }'
/// }'
/// http://localhost:8080/application/0x1234/propose
/// ```
///
Expand Down Expand Up @@ -131,16 +131,16 @@ pub async fn propose_application(
///
/// # Example
/// ```plaintext
/// curl --header "Content-Type: application/json"
/// --request POST
/// curl --header "Content-Type: application/json"
/// --request POST
/// --data '{
/// "signer": {
/// "signing_address": "0x1234567890abcdef1234567890abcdef12345678",
/// "time_of_signature": "2023-08-07T14:30:00Z",
/// "message_cid": "QmXYZ1234567890abcdef1234567890abcdef12345678"
/// },
/// "request_id": "exampleRequestId123"
/// }'
/// }'
/// http://localhost:8080/application/0x1234/approve
/// ```
///
Expand Down Expand Up @@ -179,8 +179,8 @@ pub async fn approve_application(
///
/// # Example
/// ```plaintext
/// curl --header "Content-Type: application/json"
/// --request POST
/// curl --header "Content-Type: application/json"
/// --request POST
/// http://localhost:8080/application/0x1234/merge
/// ```
///
Expand Down
6 changes: 4 additions & 2 deletions src/router/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub async fn address_allowance(address: web::Path<String>) -> impl Responder {
{
Ok(res) => return HttpResponse::Ok().body(res),
Err(_) => {
return HttpResponse::InternalServerError().body("SOMETHING IS WRONG WITH DEMOB SETUP!");
return HttpResponse::InternalServerError()
.body("SOMETHING IS WRONG WITH DEMOB SETUP!");
}
}
}
Expand Down Expand Up @@ -57,7 +58,8 @@ pub async fn verified_clients() -> impl Responder {
match blockchain.get_verified_clients().await {
Ok(res) => return HttpResponse::Ok().body(res),
Err(_) => {
return HttpResponse::InternalServerError().body("SOMETHING IS WRONG WITH DEMOB SETUP!");
return HttpResponse::InternalServerError()
.body("SOMETHING IS WRONG WITH DEMOB SETUP!");
}
}
}