Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
wip(backend): improve config parser to use enum type instead of strin…
Browse files Browse the repository at this point in the history
…g for field type
  • Loading branch information
evoxmusic committed Dec 17, 2023
1 parent d33b8ac commit cf82ceb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
2 changes: 1 addition & 1 deletion backend/examples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ catalogs:
title: field 8
description: field 8
placeholder: field 8
type: string
type: text
default: field 8
required: true
- slug: field-9
Expand Down
34 changes: 7 additions & 27 deletions backend/src/yaml_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,41 +87,21 @@ pub struct CatalogFieldYamlConfig {
pub description: Option<String>,
pub placeholder: Option<String>,
#[serde(rename = "type")]
pub type_: String,
pub type_: CatalogFieldType,
pub default: Option<String>,
pub required: Option<bool>,
pub autocomplete_fetcher: Option<String>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub enum CatalogFieldType {
String,
Text,
Textarea,
Number,
Boolean,
Date,
DateTime,
Datetime,
Time,
Enum,
Array,
Object,
}

impl CatalogFieldYamlConfig {
pub fn get_type(&self) -> CatalogFieldType {
match self.type_.as_str() {
"string" => CatalogFieldType::String,
"number" => CatalogFieldType::Number,
"boolean" => CatalogFieldType::Boolean,
"date" => CatalogFieldType::Date,
"datetime" => CatalogFieldType::DateTime,
"time" => CatalogFieldType::Time,
"enum" => CatalogFieldType::Enum,
"array" => CatalogFieldType::Array,
"object" => CatalogFieldType::Object,
_ => panic!("Unknown field type: {}", self.type_),
}
}

pub fn is_required(&self) -> bool {
self.required.unwrap_or(false)
}
List,
}

0 comments on commit cf82ceb

Please sign in to comment.