Skip to content

Commit

Permalink
finished get_model
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderManich committed Nov 27, 2023
1 parent 7ea371c commit eb02e54
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/api/ecdar_api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::sync::Arc;

use crate::api::auth::{RequestExt, Token, TokenType};
use crate::api::{
auth::{RequestExt, Token, TokenType},
server::server::Model,
};
use bcrypt::hash;
use chrono::Local;
use regex::Regex;
Expand Down Expand Up @@ -155,6 +158,13 @@ impl EcdarApi for ConcreteEcdarApi {
.map_err(|err| Status::new(Code::Internal, err.to_string()))?
.ok_or_else(|| Status::new(Code::Internal, "Model not found"))?;

let model = Model {
id: model.id,
name: model.name,
components_info: serde_json::from_value(model.components_info).unwrap(),
owner_id: model.owner_id,
};

let queries = self
.query_context
.get_all_by_model_id(model_id)
Expand All @@ -167,12 +177,18 @@ impl EcdarApi for ConcreteEcdarApi {
id: query.id,
model_id: query.model_id,
query: query.string,
result: "Hej".to_owned(),
result: match query.result {
Some(result) => serde_json::from_value(result).unwrap(),
None => "".to_owned(),
},
outdated: query.outdated,
})
.collect::<Vec<Query>>();

todo!()
Ok(Response::new(GetModelResponse {
model: Some(model),
queries,
}))
}

async fn create_model(
Expand Down
26 changes: 24 additions & 2 deletions src/tests/api/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,22 @@ mock! {
async fn delete(&self, entity_id: i32) -> Result<access::Model, DbErr>;
}
#[async_trait]
impl AccessContextTrait for AccessContext {}
impl AccessContextTrait for AccessContext {
async fn get_access_by_uid_and_model_id(
&self,
uid: i32,
model_id: i32,
) -> Result<Option<access::Model>, DbErr> {
access::Entity::find()
.filter(
Condition::all()
.add(access::Column::UserId.eq(uid))
.add(access::Column::ModelId.eq(model_id)),
)
.one(&self.db_context.get_connection())
.await
}
}
}

mock! {
Expand Down Expand Up @@ -100,7 +115,14 @@ mock! {
async fn delete(&self, entity_id: i32) -> Result<query::Model, DbErr>;
}
#[async_trait]
impl QueryContextTrait for QueryContext {}
impl QueryContextTrait for QueryContext {
async fn get_all_by_model_id(&self, model_id: i32) -> Result<Vec<query::Model>, DbErr> {
query::Entity::find()
.filter(query::Column::ModelId.eq(model_id))
.all(&self.db_context.get_connection())
.await
}
}
}

mock! {
Expand Down

0 comments on commit eb02e54

Please sign in to comment.