-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add: derive macros * feat: read packages from root folder * feat: add settings in model layer * fix: warning
- Loading branch information
Showing
17 changed files
with
406 additions
and
42 deletions.
There are no files selected for viewing
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
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,62 @@ | ||
//! Contains the model internally used by nebula | ||
//! | ||
//! | ||
pub mod pb_mapper; | ||
|
||
pub type PackageType = super::server::PackageType; | ||
|
||
/// Optional MetaData Fields | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub enum MetaDataField { | ||
PreviewImages, | ||
|
||
DataPackage, | ||
|
||
// todo more? | ||
} | ||
|
||
|
||
/// Settings to select additional (heavy) fields | ||
#[derive(Debug, Clone, Default, PartialEq, Eq)] | ||
pub struct FieldSettings { | ||
optional_fields: Vec<MetaDataField>, // todo: on stack? set semantic... | ||
} | ||
|
||
/// Pagation Settings | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct PagationSettings { | ||
pub limit: u32, | ||
|
||
pub offset: u32, | ||
} | ||
|
||
impl Default for PagationSettings { | ||
fn default() -> Self { | ||
Self { limit: 30, offset: Default::default() } | ||
} | ||
} | ||
|
||
/// multi level sort settinggs, not implemented | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct SortSettings { | ||
|
||
} | ||
|
||
impl Default for SortSettings { | ||
fn default() -> Self { | ||
Self { } | ||
} | ||
} | ||
|
||
/// Filter Settings, not implemnted | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct FilterSettings { | ||
package_type: PackageType, | ||
} | ||
|
||
impl Default for FilterSettings { | ||
fn default() -> Self { | ||
Self { package_type: crate::server::PackageType::Both } | ||
} | ||
} |
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,98 @@ | ||
//! Contains functionality to map protobuf related types to nebulas internal model | ||
use crate::{datapackage::DataPackage, server::PackageInfo}; | ||
|
||
use super::{FilterSettings, PackageType, PagationSettings, SortSettings}; | ||
|
||
/// Maps self to Pagation Settings | ||
pub trait PagationMapper { | ||
fn as_pagation(&self) -> Result<PagationSettings, Box<dyn std::error::Error>>; | ||
} | ||
|
||
/// Maps self to Filter Settings | ||
pub trait FilterMapper { | ||
fn as_filter(&self) -> Result<FilterSettings, Box<dyn std::error::Error>>; | ||
fn into_filter(self) -> Result<FilterSettings, Box<dyn std::error::Error>>; | ||
} | ||
|
||
pub trait SortMapper { | ||
fn as_sort(&self) -> Result<SortSettings, Box<dyn std::error::Error>>; | ||
} | ||
|
||
impl PagationMapper for super::super::server::ListPackagesRequest { | ||
fn as_pagation(&self) -> Result<PagationSettings, Box<dyn std::error::Error>> { | ||
let mut reval = PagationSettings::default(); | ||
if let Some(limit) = self.limit {reval.limit = limit as u32;} | ||
if let Some(offset) = self.offset {reval.offset = offset as u32;} | ||
Ok(reval) | ||
} | ||
} | ||
|
||
impl PagationMapper for super::super::server::SearchPackagesRequest { | ||
fn as_pagation(&self) -> Result<PagationSettings, Box<dyn std::error::Error>> { | ||
let mut reval = PagationSettings::default(); | ||
if let Some(limit) = self.limit {reval.limit = limit as u32;} | ||
if let Some(offset) = self.offset {reval.offset = offset as u32;} | ||
Ok(reval) | ||
} | ||
} | ||
|
||
impl FilterMapper for super::super::server::PackageRequest { | ||
fn as_filter(&self) -> Result<FilterSettings, Box<dyn std::error::Error>> { | ||
let mut reval = FilterSettings::default(); | ||
if let Some(pt) = self.package_type {reval.package_type = PackageType::try_from(pt).unwrap();} | ||
Ok(reval) | ||
} | ||
|
||
fn into_filter(self) -> Result<FilterSettings, Box<dyn std::error::Error>> { | ||
self.as_filter() | ||
} | ||
} | ||
|
||
impl FilterMapper for super::super::server::SearchPackagesRequest { | ||
fn as_filter(&self) -> Result<FilterSettings, Box<dyn std::error::Error>> { | ||
Ok(FilterSettings::default()) | ||
} | ||
|
||
fn into_filter(self) -> Result<FilterSettings, Box<dyn std::error::Error>> { | ||
Ok(FilterSettings::default()) | ||
} | ||
|
||
} | ||
|
||
impl SortMapper for super::super::server::SearchPackagesRequest { | ||
fn as_sort(&self) -> Result<SortSettings, Box<dyn std::error::Error>> { | ||
Ok(SortSettings::default()) | ||
} | ||
} | ||
|
||
impl Into<PackageInfo> for DataPackage { | ||
fn into(self) -> PackageInfo { | ||
let mut inner = self.into_inner(); | ||
PackageInfo { | ||
name: match inner.name.take() { | ||
Some(v) => v, | ||
None => "No name".to_string(), | ||
}, | ||
version: match inner.version.take() { | ||
Some(v) => v, | ||
None => "0.1.0".to_string(), | ||
}, | ||
description: match inner.description.take() { | ||
Some(v) => v, | ||
None => "No Information".to_string(), | ||
}, | ||
license: { | ||
let mut reval = String::new(); | ||
for lic in &inner.licenses { | ||
reval += lic.name.as_str(); | ||
} | ||
if reval.is_empty() { | ||
reval = "UKNOWN".to_string() | ||
} | ||
reval | ||
}, | ||
..Default::default() | ||
} | ||
} | ||
} |
Oops, something went wrong.