Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
kokal33 committed Oct 24, 2023
1 parent 1f3d1de commit 2ab3449
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/test_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test Pull Request Workflow

on:
pull_request:
types:
- opened
- synchronize
pull_request_review:
types:
- submitted
issue_comment:
types:
- created
push:

jobs:
extract-pr-number:
runs-on: ubuntu-latest
steps:
- name: Set PR Number as Environment Variable
run: echo "PR_NUMBER=${{ github.event.number }}" >> $GITHUB_ENV
- name: Set User Handle as Environment Variable
run: echo "USER_HANDLE=${{ github.actor }}" >> $GITHUB_ENV

call-backend:
needs: extract-pr-number
runs-on: ubuntu-latest
steps:
- name: Call Backend with PR Number and User Handle
run: |
PR_NUMBER="13"
USER_HANDLE=${{ env.USER_HANDLE }}
BACKEND_URL="https://f01c-89-212-199-23.ngrok-free.app/pr"
curl -X POST -d "pr_number=$PR_NUMBER&user_handle=$USER_HANDLE" $BACKEND_URL
1 change: 1 addition & 0 deletions fplus-http-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async fn main() -> std::io::Result<()> {
.service(router::application::get_all_applications)
.service(router::blockchain::address_allowance)
.service(router::blockchain::verified_clients)
.service(router::rkh::receive_pr)
})
.bind(("0.0.0.0", 8080))?
.run()
Expand Down
1 change: 1 addition & 0 deletions fplus-http-server/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use actix_web::{get, HttpResponse, Responder};

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

/// Return server health status
#[get("/health")]
Expand Down
35 changes: 29 additions & 6 deletions fplus-http-server/src/router/rkh.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
use actix_web::{get, http::header::ContentType, post, web, HttpResponse};
use mongodb::Client;
use std::sync::Mutex;
use actix_web::{get, post, web, HttpResponse, Responder};
use serde::Deserialize;
use fplus_lib::core::LDNApplication;


#[derive(Deserialize)]
pub struct PullRequestData {
pr_number: String,
user_handle: String,
}

#[get("/rkh")]
pub async fn get() -> HttpResponse {
HttpResponse::InternalServerError().finish()
}

#[post("/rkh")]
pub async fn post() -> HttpResponse {
HttpResponse::InternalServerError().finish()
#[post("/pr")]
pub async fn receive_pr(info: web::Json<PullRequestData>) -> impl Responder {
let pr_number = info.pr_number.trim_matches('"').parse::<u64>();

match pr_number {
Ok(pr_number) => {
match LDNApplication::get_by_pr_number(pr_number).await {
Ok(application_file) => {
println!("Received PR data - PR Number: {}, User Handle: {}", pr_number, info.user_handle);
HttpResponse::Ok().json(application_file)
},
Err(error) => HttpResponse::InternalServerError().json(error.to_string()),
}
}
Err(_) => HttpResponse::BadRequest().json("Invalid PR Number"),
}
}



0 comments on commit 2ab3449

Please sign in to comment.