Skip to content

Commit

Permalink
Wire up query and config for transient read
Browse files Browse the repository at this point in the history
  • Loading branch information
ackwell committed Jul 26, 2024
1 parent 37b8448 commit 0ad2213
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
5 changes: 3 additions & 2 deletions boilmaster.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ password = "password"
limit.default = 100
limit.max = 500
limit.depth = 2
# TODO: should this be shared with sheet eventually, or nah?
fields.exdschema = "Name,Singular,Icon"
transient.exdschema = ""

[http.api1.sheet]
limit.default = 100
limit.max = 500
limit.depth = 2
# TODO: should this be shared with search eventually, or nah?
list.fields.exdschema = "Name,Singular,Icon"
list.transient.exdschema = ""
entry.fields.exdschema = "*"
entry.transient.exdschema = "*"

[read.language]
default = "en"
Expand Down
7 changes: 7 additions & 0 deletions src/http/api1/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ enum Entry {
}

impl FilterString {
pub fn is_empty(&self) -> bool {
match &self.0 {
FilterStringInner::All => false,
FilterStringInner::Paths(paths) => paths.is_empty(),
}
}

pub fn to_filter(self, default_language: excel::Language) -> error::Result<read::Filter> {
let paths = match self.0 {
FilterStringInner::All => return Ok(read::Filter::All),
Expand Down
58 changes: 36 additions & 22 deletions src/http/api1/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use super::{
#[derive(Debug, Clone, Deserialize)]
pub struct RowReaderConfig {
fields: HashMap<String, FilterString>,
transient: HashMap<String, FilterString>,
}

// todo: maybe it's readrequest? something? "rowreader" is perhaps overindexing, and i should be referring to it simply as "read"?
Expand All @@ -38,6 +39,9 @@ struct RowReaderQuery {

/// Data fields to read for selected rows.
fields: Option<FilterString>,

/// Data fields to read for selected rows' transient row, if any is present.
transient: Option<FilterString>,
}

// TODO: ideally this structure is equivalent to the relation metadata from read:: - to the point honestly it probably _should_ be that. yet another thing to consider when reworking read::.
Expand All @@ -53,7 +57,8 @@ pub struct RowResult {
/// Field values for this row, according to the current schema and field filter.
pub fields: ValueString,

// fasdhjkfasdhfasdklh
/// Field values for this row's transient row, if any is present, according to
/// the current schema and transient filter.
#[serde(skip_serializing_if = "Option::is_none")]
pub transient: Option<ValueString>,
}
Expand Down Expand Up @@ -88,6 +93,7 @@ pub struct RowReader {
schema: Box<dyn ironworks_schema::Schema + Send>,
pub language: excel::Language,
fields: read::Filter,
transient: Option<read::Filter>,
}

// todo maybe an extra bit of state requirements on this for the filters? that would allow the filters to be wired up per-handler i think. not sure how that aligns with existing state though
Expand Down Expand Up @@ -129,14 +135,19 @@ where
let fields = query
.fields
.or_else(|| config.fields.get(&schema_specifier.source).cloned())
.ok_or_else(|| {
Error::Other(anyhow!(
"missing default fields for {}",
schema_specifier.source
))
})?
.ok_or_else(|| anyhow!("missing default fields for {}", schema_specifier.source))?
.to_filter(language)?;

let transient_string = query
.transient
.or_else(|| config.transient.get(&schema_specifier.source).cloned())
.ok_or_else(|| anyhow!("missing default transient for {}", schema_specifier.source))?;

let transient = match transient_string.is_empty() {
true => None,
false => Some(transient_string.to_filter(language)?),
};

let schema = schema_provider.schema(schema_specifier.clone())?;

Ok(Self {
Expand All @@ -146,6 +157,7 @@ where
schema,
language,
fields,
transient,
})
}
}
Expand Down Expand Up @@ -173,21 +185,23 @@ impl RowReader {
self.language,
);

// Try to read a transient
// TODO: filtering, opt in/out, etc
let transient = match self.read.read(
&self.excel,
self.schema.as_ref(),
&format!("{}Transient", sheet),
row_id,
subrow_id,
self.language,
&read::Filter::All, // TODO
depth,
) {
Ok(value) => Some(ValueString(value, self.language)),
Err(read::Error::NotFound(_)) => None,
Err(error) => Err(error)?,
// Try to read a transient row.
let transient = match self.transient.as_ref() {
None => None,
Some(filter) => match self.read.read(
&self.excel,
self.schema.as_ref(),
&format!("{}Transient", sheet),
row_id,
subrow_id,
self.language,
filter,
depth,
) {
Ok(value) => Some(ValueString(value, self.language)),
Err(read::Error::NotFound(_)) => None,
Err(error) => Err(error)?,
},
};

// Check the kind of the sheet to determine if we should report a subrow id.
Expand Down

0 comments on commit 0ad2213

Please sign in to comment.