Skip to content

Commit

Permalink
refactor(domain): extract for debug domain list API
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 29, 2023
1 parent 0c37a54 commit 7bc6374
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion counit-server/src/domain/domain_record.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Debug, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct DomainRecord {
pub(crate) native: String,
pub(crate) english: String,
Expand Down
2 changes: 2 additions & 0 deletions counit-server/src/domain/domain_transpiler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::path::Path;

use crate::domain::domain_record::DomainRecord;

pub struct DomainTranspiler {
Expand Down Expand Up @@ -93,6 +94,7 @@ impl DomainTranspiler {
#[cfg(test)]
mod tests {
use std::path::{Path, PathBuf};

use super::*;

#[test]
Expand Down
3 changes: 1 addition & 2 deletions counit-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ async fn main() -> anyhow::Result<()> {
// the agent api
.nest("/agent", agent_api::router())

// knowledge init
.nest("/translate/domain", domain_api::router())
.nest("/domain", domain_api::router())

//align to archguard api
.nest("/scanner", archguard_api::router())
Expand Down
27 changes: 10 additions & 17 deletions counit-server/src/server/domain_api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use axum::{Json, Router};
use serde::Serialize;
use axum::{Extension, Json, Router};
use axum::http::StatusCode;

use crate::application::Application;
use crate::domain::domain_record::DomainRecord;

pub(crate) fn router() -> Router {
use axum::routing::*;
Expand All @@ -9,19 +12,9 @@ pub(crate) fn router() -> Router {
}


pub async fn list() -> Json<Vec<LanguageResponse>> {
Json(vec![
LanguageResponse {
id: 1
},
LanguageResponse {
id: 2
},
])
}

#[derive(Serialize)]
pub struct LanguageResponse {
id: u64
pub async fn list(
Extension(app): Extension<Application>,
) -> (StatusCode, Json<Vec<DomainRecord>>) {
let records = app.transpiler.domain_records.clone();
return (StatusCode::OK, Json(records));
}

0 comments on commit 7bc6374

Please sign in to comment.