Add sorting preset dto and function to retrieve all presets
Signed-off-by: trivernis <trivernis@protonmail.com>pull/12/head
parent
ed68b76a42
commit
3e768d7c7c
@ -1,20 +1,6 @@
|
||||
use crate::dao_provider;
|
||||
|
||||
pub mod migrate_content_descriptors;
|
||||
pub mod sqlite_operations;
|
||||
|
||||
use crate::dao::{DaoContext, DaoProvider};
|
||||
|
||||
pub struct JobDao {
|
||||
ctx: DaoContext,
|
||||
}
|
||||
|
||||
impl DaoProvider for JobDao {
|
||||
fn dao_ctx(&self) -> DaoContext {
|
||||
self.ctx.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl JobDao {
|
||||
pub fn new(ctx: DaoContext) -> JobDao {
|
||||
Self { ctx }
|
||||
}
|
||||
}
|
||||
dao_provider!(JobDao);
|
||||
|
@ -0,0 +1,34 @@
|
||||
use crate::dao_provider;
|
||||
use crate::dto::{SortKeyDto, SortingPresetDto};
|
||||
use mediarepo_core::error::RepoResult;
|
||||
use mediarepo_database::entities::{sort_key, sorting_preset, sorting_preset_key};
|
||||
use sea_orm::prelude::*;
|
||||
use sea_orm::{JoinType, QueryOrder, QuerySelect};
|
||||
|
||||
dao_provider!(SortingPresetDao);
|
||||
|
||||
impl SortingPresetDao {
|
||||
#[tracing::instrument(level = "debug", skip(self))]
|
||||
pub async fn all(&self) -> RepoResult<Vec<SortingPresetDto>> {
|
||||
let presets = sorting_preset::Entity::find()
|
||||
.find_with_related(sort_key::Entity)
|
||||
.join(
|
||||
JoinType::InnerJoin,
|
||||
sorting_preset_key::Relation::SortingKey.def(),
|
||||
)
|
||||
.order_by_asc(sorting_preset_key::Column::KeyIndex)
|
||||
.all(&self.ctx.db)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(map_sorting_preset_dto)
|
||||
.collect();
|
||||
|
||||
Ok(presets)
|
||||
}
|
||||
}
|
||||
|
||||
fn map_sorting_preset_dto(
|
||||
entry: (sorting_preset::Model, Vec<sort_key::Model>),
|
||||
) -> SortingPresetDto {
|
||||
SortingPresetDto::new(entry.0, entry.1.into_iter().map(SortKeyDto::new).collect())
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
use mediarepo_database::entities::sort_key;
|
||||
use mediarepo_database::entities::sorting_preset;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SortingPresetDto {
|
||||
model: sorting_preset::Model,
|
||||
keys: Vec<SortKeyDto>,
|
||||
}
|
||||
|
||||
impl SortingPresetDto {
|
||||
pub fn new(model: sorting_preset::Model, keys: Vec<SortKeyDto>) -> Self {
|
||||
Self { model, keys }
|
||||
}
|
||||
|
||||
pub fn id(&self) -> i32 {
|
||||
self.model.id
|
||||
}
|
||||
|
||||
pub fn keys(&self) -> &Vec<SortKeyDto> {
|
||||
&self.keys
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SortKeyDto {
|
||||
model: sort_key::Model,
|
||||
}
|
||||
|
||||
impl SortKeyDto {
|
||||
pub fn new(model: sort_key::Model) -> Self {
|
||||
Self { model }
|
||||
}
|
||||
|
||||
pub fn id(&self) -> i32 {
|
||||
self.model.id
|
||||
}
|
||||
|
||||
pub fn key_type(&self) -> i32 {
|
||||
self.model.key_type
|
||||
}
|
||||
|
||||
pub fn ascending(&self) -> bool {
|
||||
self.model.ascending
|
||||
}
|
||||
|
||||
pub fn value(&self) -> Option<&String> {
|
||||
self.model.value.as_ref()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue