Skip to main content

amlich_api/
convert.rs

1use crate::dto::{
2    CanChiDto, CanChiInfoDto, CanInsightDto, ChiInsightDto, DayGuidanceDto, DayInfoDto,
3    ElementInsightDto, FestivalInsightDto, FoodInsightDto, GioHoangDaoDto, HolidayDto,
4    HolidayInsightDto, HourInfoDto, LocalizedListDto, LocalizedTextDto, LunarDto, NguHanhDto,
5    ProverbInsightDto, RegionsInsightDto, SolarDto, TabooInsightDto, TietKhiDto, TietKhiInsightDto,
6};
7
8impl From<&amlich_core::NguHanh> for NguHanhDto {
9    fn from(value: &amlich_core::NguHanh) -> Self {
10        Self {
11            can: value.can.clone(),
12            chi: value.chi.clone(),
13        }
14    }
15}
16
17impl From<&amlich_core::CanChi> for CanChiDto {
18    fn from(value: &amlich_core::CanChi) -> Self {
19        Self {
20            can_index: value.can_index,
21            chi_index: value.chi_index,
22            can: value.can.clone(),
23            chi: value.chi.clone(),
24            full: value.full.clone(),
25            con_giap: value.con_giap.clone(),
26            ngu_hanh: NguHanhDto::from(&value.ngu_hanh),
27        }
28    }
29}
30
31impl From<&amlich_core::CanChiInfo> for CanChiInfoDto {
32    fn from(value: &amlich_core::CanChiInfo) -> Self {
33        Self {
34            day: CanChiDto::from(&value.day),
35            month: CanChiDto::from(&value.month),
36            year: CanChiDto::from(&value.year),
37            full: value.full.clone(),
38        }
39    }
40}
41
42impl From<&amlich_core::SolarInfo> for SolarDto {
43    fn from(value: &amlich_core::SolarInfo) -> Self {
44        Self {
45            day: value.day,
46            month: value.month,
47            year: value.year,
48            day_of_week: value.day_of_week,
49            day_of_week_name: value.day_of_week_name.clone(),
50            date_string: value.date_string.clone(),
51        }
52    }
53}
54
55impl From<&amlich_core::LunarInfo> for LunarDto {
56    fn from(value: &amlich_core::LunarInfo) -> Self {
57        Self {
58            day: value.day,
59            month: value.month,
60            year: value.year,
61            is_leap_month: value.is_leap_month,
62            date_string: value.date_string.clone(),
63        }
64    }
65}
66
67impl From<&amlich_core::tietkhi::SolarTerm> for TietKhiDto {
68    fn from(value: &amlich_core::tietkhi::SolarTerm) -> Self {
69        Self {
70            index: value.index,
71            name: value.name.clone(),
72            description: value.description.clone(),
73            longitude: value.longitude,
74            current_longitude: value.current_longitude,
75            season: value.season.clone(),
76        }
77    }
78}
79
80impl From<&amlich_core::gio_hoang_dao::HourInfo> for HourInfoDto {
81    fn from(value: &amlich_core::gio_hoang_dao::HourInfo) -> Self {
82        Self {
83            hour_index: value.hour_index,
84            hour_chi: value.hour_chi.clone(),
85            time_range: value.time_range.clone(),
86            star: value.star.clone(),
87            is_good: value.is_good,
88        }
89    }
90}
91
92impl From<&amlich_core::gio_hoang_dao::GioHoangDao> for GioHoangDaoDto {
93    fn from(value: &amlich_core::gio_hoang_dao::GioHoangDao) -> Self {
94        Self {
95            day_chi: value.day_chi.clone(),
96            good_hour_count: value.good_hour_count,
97            good_hours: value.good_hours.iter().map(HourInfoDto::from).collect(),
98            all_hours: value.all_hours.iter().map(HourInfoDto::from).collect(),
99            summary: value.summary.clone(),
100        }
101    }
102}
103
104impl From<&amlich_core::DayInfo> for DayInfoDto {
105    fn from(value: &amlich_core::DayInfo) -> Self {
106        Self {
107            solar: SolarDto::from(&value.solar),
108            lunar: LunarDto::from(&value.lunar),
109            jd: value.jd,
110            canchi: CanChiInfoDto::from(&value.canchi),
111            tiet_khi: TietKhiDto::from(&value.tiet_khi),
112            gio_hoang_dao: GioHoangDaoDto::from(&value.gio_hoang_dao),
113        }
114    }
115}
116
117impl From<&amlich_core::holidays::Holiday> for HolidayDto {
118    fn from(value: &amlich_core::holidays::Holiday) -> Self {
119        Self {
120            name: value.name.clone(),
121            description: value.description.clone(),
122            solar_day: value.solar_day,
123            solar_month: value.solar_month,
124            solar_year: value.solar_year,
125            lunar_day: value.lunar_date.as_ref().map(|d| d.day),
126            lunar_month: value.lunar_date.as_ref().map(|d| d.month),
127            lunar_year: value.lunar_date.as_ref().map(|d| d.year),
128            is_solar: value.is_solar,
129            category: value.category.clone(),
130            is_major: value.is_major,
131        }
132    }
133}
134
135impl From<&amlich_core::holiday_data::BilingualText> for LocalizedTextDto {
136    fn from(value: &amlich_core::holiday_data::BilingualText) -> Self {
137        Self {
138            vi: value.vi.clone(),
139            en: value.en.clone(),
140        }
141    }
142}
143
144impl From<&amlich_core::insight_data::BilingualText> for LocalizedTextDto {
145    fn from(value: &amlich_core::insight_data::BilingualText) -> Self {
146        Self {
147            vi: value.vi.clone(),
148            en: value.en.clone(),
149        }
150    }
151}
152
153impl From<&amlich_core::insight_data::BilingualList> for LocalizedListDto {
154    fn from(value: &amlich_core::insight_data::BilingualList) -> Self {
155        Self {
156            vi: value.vi.clone(),
157            en: value.en.clone(),
158        }
159    }
160}
161
162impl From<&amlich_core::holiday_data::BilingualList> for LocalizedListDto {
163    fn from(value: &amlich_core::holiday_data::BilingualList) -> Self {
164        Self {
165            vi: value.vi.clone(),
166            en: value.en.clone(),
167        }
168    }
169}
170
171impl From<&amlich_core::holiday_data::FoodItem> for FoodInsightDto {
172    fn from(value: &amlich_core::holiday_data::FoodItem) -> Self {
173        Self {
174            name: LocalizedTextDto::from(&value.name),
175            description: LocalizedTextDto::from(&value.description),
176        }
177    }
178}
179
180impl From<&amlich_core::holiday_data::TabooItem> for TabooInsightDto {
181    fn from(value: &amlich_core::holiday_data::TabooItem) -> Self {
182        Self {
183            action: LocalizedTextDto::from(&value.action),
184            reason: LocalizedTextDto::from(&value.reason),
185        }
186    }
187}
188
189impl From<&amlich_core::holiday_data::ProverbItem> for ProverbInsightDto {
190    fn from(value: &amlich_core::holiday_data::ProverbItem) -> Self {
191        Self {
192            text: value.text.clone(),
193            meaning: LocalizedTextDto::from(&value.meaning),
194        }
195    }
196}
197
198impl From<&amlich_core::holiday_data::Regions> for RegionsInsightDto {
199    fn from(value: &amlich_core::holiday_data::Regions) -> Self {
200        Self {
201            north: LocalizedTextDto::from(&value.north),
202            central: LocalizedTextDto::from(&value.central),
203            south: LocalizedTextDto::from(&value.south),
204        }
205    }
206}
207
208impl From<&amlich_core::holiday_data::LunarFestivalData> for FestivalInsightDto {
209    fn from(value: &amlich_core::holiday_data::LunarFestivalData) -> Self {
210        Self {
211            names: LocalizedListDto {
212                vi: value.names.vi.clone(),
213                en: value.names.en.clone(),
214            },
215            origin: value.origin.as_ref().map(LocalizedTextDto::from),
216            activities: value.activities.as_ref().map(LocalizedListDto::from),
217            food: value.food.iter().map(FoodInsightDto::from).collect(),
218            taboos: value.taboos.iter().map(TabooInsightDto::from).collect(),
219            proverbs: value.proverbs.iter().map(ProverbInsightDto::from).collect(),
220            regions: value.regions.as_ref().map(RegionsInsightDto::from),
221            category: value.category.clone(),
222            is_major: value.is_major,
223        }
224    }
225}
226
227impl From<&amlich_core::holiday_data::SolarHolidayData> for HolidayInsightDto {
228    fn from(value: &amlich_core::holiday_data::SolarHolidayData) -> Self {
229        Self {
230            names: LocalizedListDto {
231                vi: value.names.vi.clone(),
232                en: value.names.en.clone(),
233            },
234            origin: value.origin.as_ref().map(LocalizedTextDto::from),
235            significance: value.significance.as_ref().map(LocalizedTextDto::from),
236            activities: value.activities.as_ref().map(LocalizedListDto::from),
237            traditions: value.traditions.as_ref().map(LocalizedListDto::from),
238            food: value.food.iter().map(FoodInsightDto::from).collect(),
239            taboos: value.taboos.iter().map(TabooInsightDto::from).collect(),
240            proverbs: value.proverbs.iter().map(ProverbInsightDto::from).collect(),
241            regions: value.regions.as_ref().map(RegionsInsightDto::from),
242            category: value.category.clone(),
243            is_major: value.is_major,
244        }
245    }
246}
247
248impl From<(&String, &amlich_core::insight_data::ElementInfo)> for ElementInsightDto {
249    fn from((key, value): (&String, &amlich_core::insight_data::ElementInfo)) -> Self {
250        Self {
251            key: key.clone(),
252            name: LocalizedTextDto::from(&value.name),
253            nature: LocalizedTextDto::from(&value.nature),
254        }
255    }
256}
257
258impl From<&amlich_core::insight_data::CanInfo> for CanInsightDto {
259    fn from(value: &amlich_core::insight_data::CanInfo) -> Self {
260        Self {
261            name: value.name.clone(),
262            element: value.element.clone(),
263            meaning: LocalizedTextDto::from(&value.meaning),
264            nature: LocalizedTextDto::from(&value.nature),
265        }
266    }
267}
268
269impl From<&amlich_core::insight_data::ChiInfo> for ChiInsightDto {
270    fn from(value: &amlich_core::insight_data::ChiInfo) -> Self {
271        Self {
272            name: value.name.clone(),
273            animal: LocalizedTextDto::from(&value.animal),
274            element: value.element.clone(),
275            meaning: LocalizedTextDto::from(&value.meaning),
276            hours: value.hours.clone(),
277        }
278    }
279}
280
281impl From<&amlich_core::insight_data::DayGuidance> for DayGuidanceDto {
282    fn from(value: &amlich_core::insight_data::DayGuidance) -> Self {
283        Self {
284            good_for: LocalizedListDto::from(&value.good_for),
285            avoid_for: LocalizedListDto::from(&value.avoid_for),
286        }
287    }
288}
289
290impl From<&amlich_core::insight_data::TietKhiInsight> for TietKhiInsightDto {
291    fn from(value: &amlich_core::insight_data::TietKhiInsight) -> Self {
292        Self {
293            id: value.id.clone(),
294            name: LocalizedTextDto::from(&value.name),
295            longitude: value.longitude,
296            meaning: LocalizedTextDto::from(&value.meaning),
297            astronomy: LocalizedTextDto::from(&value.astronomy),
298            agriculture: LocalizedListDto::from(&value.agriculture),
299            health: LocalizedListDto::from(&value.health),
300            weather: LocalizedTextDto::from(&value.weather),
301        }
302    }
303}