forked from project-openubl/xhandler-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add create project skeleton (project-openubl#288)
- Loading branch information
1 parent
a390677
commit 90fd7a7
Showing
15 changed files
with
174 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use std::fmt::{Debug, Formatter}; | ||
|
||
use sea_orm::ActiveValue::Set; | ||
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter}; | ||
|
||
use ublhub_entity::project; | ||
|
||
use crate::db::Transactional; | ||
use crate::system::error::Error; | ||
use crate::system::InnerSystem; | ||
|
||
impl InnerSystem { | ||
pub async fn create_project( | ||
&self, | ||
model: &project::Model, | ||
tx: Transactional<'_>, | ||
) -> Result<ProjectContext, Error> { | ||
if let Some(found) = self.get_project(&model.name, tx).await? { | ||
Ok(found) | ||
} else { | ||
let entity = project::ActiveModel { | ||
name: Set(model.name.clone()), | ||
description: Set(model.description.clone()), | ||
sunat_username: Set(model.sunat_username.clone()), | ||
sunat_password: Set(model.sunat_password.clone()), | ||
sunat_factura_url: Set(model.sunat_factura_url.clone()), | ||
sunat_guia_url: Set(model.sunat_guia_url.clone()), | ||
sunat_percepcion_retencion_url: Set(model.sunat_percepcion_retencion_url.clone()), | ||
}; | ||
|
||
Ok((self, entity.insert(&self.connection(tx)).await?).into()) | ||
} | ||
} | ||
|
||
pub async fn get_project( | ||
&self, | ||
name: &str, | ||
tx: Transactional<'_>, | ||
) -> Result<Option<ProjectContext>, Error> { | ||
Ok(project::Entity::find() | ||
.filter(project::Column::Name.eq(name)) | ||
.one(&self.connection(tx)) | ||
.await? | ||
.map(|project| (self, project).into())) | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct ProjectContext { | ||
pub system: InnerSystem, | ||
pub project: project::Model, | ||
} | ||
|
||
impl Debug for ProjectContext { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
self.project.fmt(f) | ||
} | ||
} | ||
|
||
impl From<(&InnerSystem, project::Model)> for ProjectContext { | ||
fn from((system, project): (&InnerSystem, project::Model)) -> Self { | ||
Self { | ||
system: system.clone(), | ||
project, | ||
} | ||
} | ||
} | ||
|
||
// impl ProjectContext { | ||
// pub async fn advisories(&self, tx: Transactional<'_>) -> Result<Vec<ProjectContext>, Error> { | ||
// Ok(advisory::Entity::find() | ||
// .join( | ||
// JoinType::Join, | ||
// advisory_vulnerability::Relation::Advisory.def().rev(), | ||
// ) | ||
// .filter(advisory_vulnerability::Column::VulnerabilityId.eq(self.cve.id)) | ||
// .all(&self.system.connection(tx)) | ||
// .await? | ||
// .drain(0..) | ||
// .map(|advisory| (&self.system, advisory).into()) | ||
// .collect()) | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use actix_web::{get, web, Responder}; | ||
|
||
use crate::server::Error; | ||
use crate::AppState; | ||
|
||
#[utoipa::path( | ||
responses( | ||
(status = 200, description = "Liveness"), | ||
), | ||
)] | ||
#[get("/health/live")] | ||
pub async fn liveness(_: web::Data<AppState>) -> Result<impl Responder, Error> { | ||
Ok("Live") | ||
} | ||
|
||
#[utoipa::path( | ||
responses( | ||
(status = 200, description = "Readiness"), | ||
), | ||
)] | ||
#[get("/health/read")] | ||
pub async fn readiness(_: web::Data<AppState>) -> Result<impl Responder, Error> { | ||
Ok("Read") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters