Skip to content
This repository was archived by the owner on Feb 20, 2024. It is now read-only.

Commit 85c5c0d

Browse files
authored
Merge pull request #22 from Virtual-Finland-Development/VFD-194-lisataan-testbed-api-iin-endpointit-joiden-kautta-voidaan-kayttaa-users-api-n-productizeria-basic-information-ja-job-applicant-profile
Vfd 194 lisataan testbed api iin endpointit joiden kautta voidaan kayttaa users api n productizeria basic information ja job applicant profile
2 parents 532fcec + f6cf3b8 commit 85c5c0d

8 files changed

Lines changed: 107 additions & 12 deletions

File tree

.env

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ USER_STATUS_INFO_PRODUCTIZER_ENDPOINT = "https://gateway.testbed.fi/test/lsipii/
33
USER_STATUS_INFO_WRITE_PRODUCTIZER_ENDPOINT="https://gateway.testbed.fi/test/lsipii/User/StatusInfo/Write?source=access_to_finland:vfd"
44
POPULATION_FIGURE_PRODUCTIZER_ENDPOINT = "https://gateway.testbed.fi/test/lsipii/Figure/Population?source=virtual_finland"
55
JOB_POSTING_PRODUCTIZER_ENDPOINTS = "https://gateway.testbed.fi/test/lassipatanen/Job/JobPosting?source=tyomarkkinatori, https://gateway.testbed.fi/test/lassipatanen/Job/JobPosting?source=jobs_in_finland"
6-
JMF_SKILL_RECOMMENDATIONS_ENDPOINT = "https://tyomarkkinatori.fi/hakupalvelu/api/1.0/skillrecommendation/skillrecommendation/"
6+
JMF_SKILL_RECOMMENDATIONS_ENDPOINT = "https://tyomarkkinatori.fi/hakupalvelu/api/1.0/skillrecommendation/skillrecommendation/"
7+
TESTBED_BASE_URL = "https://gateway.testbed.fi"
8+
TESTBED_ENVIRONMENT = "development"

.env.staging

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
USER_PROFILE_PRODUCTIZER_ENDPOINT = "https://gateway.testbed.fi/test/lassipatanen/User/Profile?source=access_to_finland__staging"
22
USER_STATUS_INFO_PRODUCTIZER_ENDPOINT="https://gateway.testbed.fi/test/lsipii/User/StatusInfo?source=access_to_finland__staging:vfd"
33
USER_STATUS_INFO_WRITE_PRODUCTIZER_ENDPOINT="https://gateway.testbed.fi/test/lsipii/User/StatusInfo/Write?source=access_to_finland__staging:vfd"
4+
TESTBED_ENVIRONMENT = "staging"

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ Cargo.lock
1212
# Infra build packages
1313
infra/build/*
1414
!infra/build/.gitkeep
15-
.cargo_home
15+
.cargo_home
16+
17+
# idea
18+
.idea

src/lib/api_app/src/api/routes/mod.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{ responses::{ APIRoutingResponse, APIRoutingError }, utils::ParsedRequest };
1+
use super::{responses::{APIRoutingError, APIRoutingResponse}, utils::ParsedRequest};
22

33
pub mod application;
44
pub mod testbed;
@@ -9,12 +9,8 @@ pub mod jmf;
99
*/
1010
pub async fn exec_router_request(parsed_request: ParsedRequest) -> APIRoutingResponse {
1111
match get_router_response(parsed_request).await {
12-
Ok(response) => {
13-
return response;
14-
}
15-
Err(e) => {
16-
return APIRoutingResponse::from_routing_error(e);
17-
}
12+
Ok(response) => { response }
13+
Err(e) => { APIRoutingResponse::from_routing_error(e) }
1814
}
1915
}
2016

@@ -50,6 +46,16 @@ pub async fn get_router_response(
5046
testbed::productizers::user::update_user_status_info(parsed_request).await
5147
}
5248
("POST", "/jmf/recommendations") => { jmf::fetch_jmf_recommendations(parsed_request).await }
49+
50+
("GET", "/testbed/productizer/person/basic-information") =>
51+
{ testbed::productizers::person::basic_information::get_basic_information(parsed_request).await }
52+
("POST", "/testbed/productizer/person/basic-information") =>
53+
{ testbed::productizers::person::basic_information::write_basic_information(parsed_request).await }
54+
("GET", "/testbed/productizer/person/job-applicant-information") =>
55+
{ testbed::productizers::person::job_applicant_profile::get_job_applicant_profile(parsed_request).await }
56+
("POST", "/testbed/productizer/person/job-applicant-information") =>
57+
{ testbed::productizers::person::job_applicant_profile::post_job_applicant_profile(parsed_request).await }
58+
5359
_ => { application::not_found(parsed_request).await }
5460
}
55-
}
61+
}

src/lib/api_app/src/api/routes/testbed/productizers/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use crate::api::{ responses::APIRoutingError, utils::ParsedRequest };
55
pub mod figure;
66
pub mod job;
77
pub mod user;
8+
pub mod person;
89

910
/**
10-
* Parses the authorization headers fromn the input request
11+
* Parses the authorization headers from the input request
1112
*/
1213
fn parse_testbed_request_headers(request: ParsedRequest) -> Result<HeaderMap, APIRoutingError> {
1314
// Prep auth header forwarding
@@ -33,4 +34,4 @@ fn parse_testbed_request_headers(request: ParsedRequest) -> Result<HeaderMap, AP
3334
);
3435
}
3536
Ok(request_headers)
36-
}
37+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use crate::api::{
2+
responses::{APIRoutingError, APIRoutingResponse},
3+
utils::ParsedRequest,
4+
};
5+
6+
pub async fn get_basic_information(request: ParsedRequest) -> Result<APIRoutingResponse, APIRoutingError> {
7+
let data_product = "draft/Person/BasicInformation";
8+
let data_source = "virtualfinland";
9+
let result = super::get_data_product(data_product, data_source, request).await?;
10+
Ok(result)
11+
}
12+
13+
pub async fn write_basic_information(request: ParsedRequest) -> Result<APIRoutingResponse, APIRoutingError> {
14+
let data_product = "draft/Person/BasicInformation/Write";
15+
let data_source = "virtualfinland";
16+
let result = super::write_data_product(data_product, data_source, request).await?;
17+
Ok(result)
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::api::{
2+
responses::{APIRoutingError, APIRoutingResponse},
3+
utils::ParsedRequest,
4+
};
5+
6+
pub async fn get_job_applicant_profile(request: ParsedRequest) -> Result<APIRoutingResponse, APIRoutingError> {
7+
let data_product = "draft/Person/JobApplicantProfile";
8+
let data_source = "virtualfinland";
9+
let result = super::get_data_product(data_product, data_source, request).await?;
10+
Ok(result)
11+
}
12+
13+
pub async fn post_job_applicant_profile(request: ParsedRequest) -> Result<APIRoutingResponse, APIRoutingError> {
14+
let data_product = "draft/Person/JobApplicantProfile/Write";
15+
let data_source = "virtualfinland";
16+
let result = super::write_data_product(data_product, data_source, request).await?;
17+
Ok(result)
18+
}
19+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use std::env;
2+
3+
use serde_json::{json, Value as JSONValue};
4+
5+
use crate::{
6+
api::{
7+
requests::post_json_request,
8+
responses::{APIRoutingError, APIRoutingResponse},
9+
utils::ParsedRequest,
10+
}
11+
};
12+
13+
use super::parse_testbed_request_headers;
14+
15+
pub mod basic_information;
16+
pub mod job_applicant_profile;
17+
18+
fn build_data_product_uri(data_product: &str, data_source: &str) -> String {
19+
let testbed_base_url = env::var("TESTBED_BASE_URL").expect("TESTBED_BASE_URL must be set");
20+
let testbed_environment = env::var("TESTBED_ENVIRONMENT").expect("TESTBED_ENVIRONMENT must be set");
21+
let formatted_path = format!("{testbed_base_url}/{data_product}?source={data_source}:{testbed_environment}");
22+
formatted_path
23+
}
24+
25+
pub async fn get_data_product(data_product: &str, data_source: &str, request: ParsedRequest) -> Result<APIRoutingResponse, APIRoutingError> {
26+
let request_input = json!({});
27+
let request_headers = parse_testbed_request_headers(request)?;
28+
let response = post_json_request::<JSONValue, JSONValue>(
29+
build_data_product_uri(data_product, data_source),
30+
&request_input,
31+
request_headers,
32+
).await?;
33+
Ok(response)
34+
}
35+
36+
pub async fn write_data_product(data_product: &str, data_source: &str, request: ParsedRequest) -> Result<APIRoutingResponse, APIRoutingError> {
37+
let request_input: JSONValue = serde_json::from_str(request.body.as_str()).unwrap_or(json!({}));
38+
let request_headers = parse_testbed_request_headers(request)?;
39+
let response = post_json_request::<JSONValue, JSONValue>(
40+
build_data_product_uri(data_product, data_source),
41+
&request_input,
42+
request_headers,
43+
).await?;
44+
Ok(response)
45+
}

0 commit comments

Comments
 (0)