Skip to content

Commit

Permalink
update new indexer endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyBuisset committed Nov 28, 2023
1 parent 76c376b commit 16d9eb0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
15 changes: 8 additions & 7 deletions api/src/infrastructure/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use crate::domain::services::indexer;
#[async_trait]
impl indexer::Service for http::Client {
async fn index_repo(&self, repo_id: GithubRepoId) -> Result<()> {
self.post::<serde_json::Value>(format!("repo/{repo_id}")).await?;
self.post::<serde_json::Value>(format!("repo/{repo_id}"), None).await?;

Check warning on line 11 in api/src/infrastructure/indexer.rs

View check run for this annotation

Codecov / codecov/patch

api/src/infrastructure/indexer.rs#L11

Added line #L11 was not covered by tests
Ok(())
}

async fn index_user(&self, user_id: GithubUserId) -> Result<()> {
self.post::<serde_json::Value>(format!("user/{user_id}")).await?;
self.post::<serde_json::Value>(format!("user/{user_id}"), None).await?;

Check warning on line 16 in api/src/infrastructure/indexer.rs

View check run for this annotation

Codecov / codecov/patch

api/src/infrastructure/indexer.rs#L16

Added line #L16 was not covered by tests
Ok(())
}

Expand All @@ -22,7 +22,7 @@ impl indexer::Service for http::Client {
repo_id: GithubRepoId,
issue_number: GithubIssueNumber,
) -> Result<()> {
self.post::<serde_json::Value>(format!("repo/{repo_id}/issue/{issue_number}"))
self.post::<serde_json::Value>(format!("repo/{repo_id}/issue/{issue_number}"), None)

Check warning on line 25 in api/src/infrastructure/indexer.rs

View check run for this annotation

Codecov / codecov/patch

api/src/infrastructure/indexer.rs#L25

Added line #L25 was not covered by tests
.await?;
Ok(())
}
Expand All @@ -32,7 +32,7 @@ impl indexer::Service for http::Client {
repo_id: GithubRepoId,
pr_number: GithubPullRequestNumber,
) -> Result<()> {
self.post::<serde_json::Value>(format!("repo/{repo_id}/pull_request/{pr_number}"))
self.post::<serde_json::Value>(format!("repo/{repo_id}/pull_request/{pr_number}"), None)

Check warning on line 35 in api/src/infrastructure/indexer.rs

View check run for this annotation

Codecov / codecov/patch

api/src/infrastructure/indexer.rs#L35

Added line #L35 was not covered by tests
.await?;
Ok(())
}
Expand All @@ -49,9 +49,10 @@ impl indexer::Service for http::Client {
}

let response: Response = self
.post(format!(
"repo/{repo_owner}/{repo_name}/pull_request/{pr_number}"
))
.post(
format!("repo/{repo_owner}/{repo_name}/pull_request/{pr_number}"),
None,
)

Check warning on line 55 in api/src/infrastructure/indexer.rs

View check run for this annotation

Codecov / codecov/patch

api/src/infrastructure/indexer.rs#L52-L55

Added lines #L52 - L55 were not covered by tests
.await?;

Ok(response.id)
Expand Down
9 changes: 8 additions & 1 deletion api/src/infrastructure/new_indexer.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
use anyhow::Result;
use domain::*;
use infrastructure::http;
use serde_json::json;

use crate::domain::services::new_indexer;

#[async_trait]
impl new_indexer::Service for http::Client {
async fn index_repo(&self, repo_id: GithubRepoId) -> Result<()> {
self.put(format!("api/v1/indexes/repos/{repo_id}")).await?;
self.post(
"api/v1/events/on-repo-link-changed".to_string(),
Some(json!({
"linkedRepoIds": [repo_id]
})),
)
.await?;

Check warning on line 17 in api/src/infrastructure/new_indexer.rs

View check run for this annotation

Codecov / codecov/patch

api/src/infrastructure/new_indexer.rs#L11-L17

Added lines #L11 - L17 were not covered by tests
Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"request": {
"urlPattern": "/new_indexer/api/v1/indexes/repos/[0-9]*",
"method": "PUT",
"urlPattern": "/new_indexer/api/v1/events/on-repo-link-changed",
"method": "POST",
"headers": {
"Authorization": {
"contains": "Bearer "
Expand Down
13 changes: 11 additions & 2 deletions common/infrastructure/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@ impl Client {
Ok(url)
}

pub async fn post<R: DeserializeOwned>(&self, path: String) -> Result<R> {
let response = self.client.post(self.url(path)?).send().await?.error_for_status()?;
pub async fn post<R: DeserializeOwned>(
&self,
path: String,
body: Option<serde_json::Value>,
) -> Result<R> {
let mut request = self.client.post(self.url(path)?);
if let Some(body) = body {
request = request.body(body.to_string());
}

Check warning on line 39 in common/infrastructure/src/http/mod.rs

View check run for this annotation

Codecov / codecov/patch

common/infrastructure/src/http/mod.rs#L31-L39

Added lines #L31 - L39 were not covered by tests

let response = request.send().await?.error_for_status()?;

Check warning on line 41 in common/infrastructure/src/http/mod.rs

View check run for this annotation

Codecov / codecov/patch

common/infrastructure/src/http/mod.rs#L41

Added line #L41 was not covered by tests
let json = response.json().await?;
Ok(json)
}
Expand Down

0 comments on commit 16d9eb0

Please sign in to comment.