1use crate::build_request;
4use crate::{impl_into_iter, impl_iter_and_mut};
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Deserialize, Serialize)]
10pub struct AllSeries {
11 cases: Vec<AllSlice>,
12}
13
14#[derive(Debug, Deserialize, Serialize)]
15pub struct AllSlice {
16 confirmed: u32,
17 deaths: u32,
18 date: String,
19}
20
21#[derive(Debug, Deserialize, Serialize)]
25pub struct ConfirmedSeries {
26 pub cases: Vec<Confirmed>,
27}
28#[derive(Debug, Deserialize, Serialize)]
29pub struct Confirmed {
30 pub confirmed: u32,
31 pub date: String,
32}
33
34#[derive(Debug, Deserialize, Serialize)]
38pub struct RecoveredSeries {
39 pub cases: Vec<Recovered>,
40}
41
42#[derive(Debug, Deserialize, Serialize)]
43pub struct Recovered {
44 pub recovered: u32,
45 pub date: String,
46}
47
48#[derive(Debug, Deserialize, Serialize)]
52pub struct DeathSeries {
53 pub cases: Vec<Deaths>,
54}
55
56#[derive(Debug, Deserialize, Serialize)]
57pub struct Deaths {
58 pub deaths: u32,
59 pub date: String,
60}
61
62#[derive(Debug, Deserialize, Serialize)]
66pub struct ActiveSeries {
67 pub cases: Vec<Active>,
68}
69
70#[derive(Debug, Deserialize, Serialize)]
71pub struct Active {
72 pub active: u32,
73 pub date: String,
74}
75
76#[derive(Debug, Deserialize, Serialize)]
80pub struct IntensiveSeries {
81 pub cases: Vec<Intensive>,
82}
83
84#[derive(Debug, Deserialize, Serialize)]
85pub struct Intensive {
86 pub intensive_care: Option<u32>,
87 pub date: String,
88}
89
90#[derive(Debug, Deserialize, Serialize)]
94pub struct TestSeries {
95 pub total_tests: Vec<Tests>,
96}
97
98#[derive(Debug, Deserialize, Serialize)]
99pub struct Tests {
100 pub tests: Option<u32>,
101 #[serde(rename = "rapid-tests")]
102 pub rapid_tests: u32,
103 pub date: String,
104}
105
106#[derive(Debug, Deserialize, Serialize)]
109pub struct AgeDistributionSeries {
110 #[serde(rename = "age-distribution")]
111 pub age_distribution: Vec<AgeDistributionSlice>,
112}
113
114#[derive(Debug, Deserialize, Serialize)]
115pub struct AgeDistributionSlice {
116 pub date: String,
117 pub cases: AgeSlice,
118 pub critical: AgeSlice,
119 pub deaths: AgeSlice,
120}
121
122#[derive(Debug, Deserialize, Serialize)]
123pub struct AgeSlice {
124 #[serde(rename = "0-17")]
125 pub age_group_0_17: u32,
126 #[serde(rename = "18-39")]
127 pub age_group_18_39: u32,
128 #[serde(rename = "40-64")]
129 pub age_group_40_64: u32,
130 #[serde(rename = "65+")]
131 pub age_group4_65: u32,
132}
133
134#[derive(Debug, Deserialize, Serialize)]
136pub struct RegionsHistorySeries {
137 #[serde(rename = "regions-history")]
138 pub regions_history: Vec<Regions>,
139}
140
141#[derive(Debug, Deserialize, Serialize)]
142pub struct Regions {
143 pub date: String,
144 pub regions: Vec<RegionSlice>,
145}
146
147#[derive(Debug, Deserialize, Serialize)]
148pub struct RegionSlice {
149 pub area_en: String,
150 pub area_gr: String,
151 pub cases: Option<u32>,
152 pub geo_department_en: String,
153 pub geo_department_gr: String,
154 pub last_updated_at: String,
155 pub latitude: f64,
156 pub longtitude: f64,
157 pub region_en: String,
158 pub region_gr: String,
159}
160
161#[derive(Debug, Deserialize, Serialize)]
164pub struct MaleCasesHistory {
165 #[serde(rename = "male-cases")]
166 pub male_cases: Vec<AgeDistributionSlice>,
167}
168
169#[derive(Debug, Deserialize, Serialize)]
172pub struct FemaleCasesHistory {
173 #[serde(rename = "female-cases")]
174 pub female_cases: Vec<AgeDistributionSlice>,
175}
176
177#[derive(Debug, Deserialize, Serialize)]
180pub struct VaccineSeries {
181 #[serde(rename = "vaccinations-history")]
182 pub vaccinations_history: Vec<VaccineSlice>,
183}
184
185#[derive(Debug, Deserialize, Serialize)]
186pub struct VaccineSlice {
187 pub area_gr: String,
188 pub area_en: String,
189 pub dailydose1: u32,
190 pub dailydose2: u32,
191 pub daydiff: i32,
192 pub daytotal: u32,
193 pub referencedate: String,
194 pub totaldistinctpersons: u32,
195 pub totaldose1: u32,
196 pub totaldose2: u32,
197 pub totalvaccinations: u32,
198}
199
200#[derive(Debug, Deserialize, Serialize)]
203pub struct SchoolStatusSeries {
204 #[serde(rename = "schools-status")]
205 pub schools_status: Vec<SchoolSlice>,
206}
207
208#[derive(Debug, Deserialize, Serialize)]
209pub struct SchoolSlice {
210 #[serde(rename = "Address")]
211 pub address: String,
212 #[serde(rename = "Area")]
213 pub area: String,
214 #[serde(rename = "DateFrom")]
215 pub date_from: String,
216 #[serde(rename = "DateTo")]
217 pub date_to: String,
218 #[serde(rename = "Latitude")]
219 pub latitude: Option<f64>,
220 #[serde(rename = "Longitude")]
221 pub longitude: Option<f64>,
222 #[serde(rename = "MunicipalUnit")]
223 pub municipal_unit: String,
224 #[serde(rename = "Municipality")]
225 pub municipality: String,
226 #[serde(rename = "Remarks")]
227 pub remarks: String,
228 #[serde(rename = "SchoolKind")]
229 pub school_kind: String,
230 #[serde(rename = "UnitName")]
231 pub unit_name: String,
232}
233
234pub fn get_all_series_data() -> AllSeries {
236 let json_resp = build_request("all");
237 let all_series = serde_json::from_str(&json_resp).unwrap();
238 all_series
239}
240
241pub fn get_confirmed_series_data() -> ConfirmedSeries {
243 let json_resp = build_request("confirmed");
244 let confirmed_series = serde_json::from_str(&json_resp).unwrap();
245 confirmed_series
246}
247
248pub fn get_recovered_series_data() -> RecoveredSeries {
250 let json_resp = build_request("recovered");
251 let recovered_series = serde_json::from_str(&json_resp).unwrap();
252 recovered_series
253}
254
255pub fn get_deaths_series_data() -> DeathSeries {
257 let json_resp = build_request("deaths");
258 let deaths_series = serde_json::from_str(&json_resp).unwrap();
259 deaths_series
260}
261
262pub fn get_active_series_data() -> ActiveSeries {
264 let json_resp = build_request("active");
265 let active_series = serde_json::from_str(&json_resp).unwrap();
266 active_series
267}
268
269pub fn get_intensive_care_series_data() -> IntensiveSeries {
271 let json_resp = build_request("intensive-care");
272 let intensive_series = serde_json::from_str(&json_resp).unwrap();
273 intensive_series
274}
275
276pub fn get_total_tests_series_data() -> TestSeries {
278 let json_resp = build_request("total-tests");
279 let test_series = serde_json::from_str(&json_resp).unwrap();
280 test_series
281}
282
283pub fn get_age_dist_series_data() -> AgeDistributionSeries {
285 let json_resp = build_request("age-distribution-history");
286 let age_dist_series = serde_json::from_str(&json_resp).unwrap();
287 age_dist_series
288}
289
290pub fn get_regions_history_series_data() -> RegionsHistorySeries {
292 let json_resp = build_request("regions-history");
293 let region_hist_series = serde_json::from_str(&json_resp).unwrap();
294 region_hist_series
295}
296
297pub fn get_male_cases_series_data() -> MaleCasesHistory {
299 let json_resp = build_request("male-cases-history");
300 let male_cases = serde_json::from_str(&json_resp).unwrap();
301 male_cases
302}
303
304pub fn get_female_cases_series_data() -> FemaleCasesHistory {
306 let json_resp = build_request("female-cases-history");
307 let female_cases = serde_json::from_str(&json_resp).unwrap();
308 female_cases
309}
310
311pub fn get_vaccin_per_region_series_data() -> VaccineSeries {
313 let json_resp = build_request("vaccinations-per-region-history");
314 let vaccine_series = serde_json::from_str(&json_resp).unwrap();
315 vaccine_series
316}
317
318pub fn get_school_status_series_data() -> SchoolStatusSeries {
320 let json_resp = build_request("schools-status");
321 let school_series = serde_json::from_str(&json_resp).unwrap();
322 school_series
323}
324
325impl_into_iter!(SchoolStatusSeries, SchoolSlice, schools_status);
327impl_iter_and_mut!(SchoolStatusSeries, SchoolSlice, schools_status);
328impl_into_iter!(VaccineSeries, VaccineSlice, vaccinations_history);
329impl_iter_and_mut!(VaccineSeries, VaccineSlice, vaccinations_history);
330impl_into_iter!(FemaleCasesHistory, AgeDistributionSlice, female_cases);
331impl_iter_and_mut!(FemaleCasesHistory, AgeDistributionSlice, female_cases);
332impl_into_iter!(MaleCasesHistory, AgeDistributionSlice, male_cases);
333impl_iter_and_mut!(MaleCasesHistory, AgeDistributionSlice, male_cases);
334impl_into_iter!(RegionsHistorySeries, Regions, regions_history);
335impl_iter_and_mut!(RegionsHistorySeries, Regions, regions_history);
336impl_into_iter!(
337 AgeDistributionSeries,
338 AgeDistributionSlice,
339 age_distribution
340);
341impl_iter_and_mut!(
342 AgeDistributionSeries,
343 AgeDistributionSlice,
344 age_distribution
345);
346impl_into_iter!(DeathSeries, Deaths, cases);
347impl_iter_and_mut!(DeathSeries, Deaths, cases);
348impl_into_iter!(AllSeries, AllSlice, cases);
349impl_iter_and_mut!(AllSeries, AllSlice, cases);
350impl_into_iter!(ConfirmedSeries, Confirmed, cases);
351impl_iter_and_mut!(ConfirmedSeries, Confirmed, cases);
352impl_into_iter!(RecoveredSeries, Recovered, cases);
353impl_iter_and_mut!(RecoveredSeries, Recovered, cases);
354impl_into_iter!(ActiveSeries, Active, cases);
355impl_iter_and_mut!(ActiveSeries, Active, cases);
356impl_into_iter!(IntensiveSeries, Intensive, cases);
357impl_iter_and_mut!(IntensiveSeries, Intensive, cases);
358impl_into_iter!(TestSeries, Tests, total_tests);
359impl_iter_and_mut!(TestSeries, Tests, total_tests);
360
361#[cfg(test)]
362mod tests {
363 use super::*;
364
365 #[test]
366 fn test_deser_school_status() {
367 let str_json: &str = r#"
368 {
369 "schools-status": [
370 {
371 "UnitName": "string",
372 "SchoolKind": "string",
373 "Municipality": "string",
374 "MunicipalUnit": "string",
375 "Area": "string",
376 "Address": "string",
377 "Longitude": 0,
378 "Latitude": 0,
379 "DateFrom": "2021-04-28",
380 "DateTo": "2021-04-28",
381 "Remarks": "string"
382 }
383 ]
384 }
385 "#;
386 let school_data: Result<SchoolStatusSeries, _> = serde_json::from_str(str_json);
387 println!("{:?}", &school_data);
388 assert!(school_data.is_ok());
389 }
390
391 #[test]
392 fn test_deser_vaccin_per_region_history() {
393 const STR_JSON: &str = r#"
394 {
395 "vaccinations-history": [
396 {
397 "area_gr": "string",
398 "area_en": "string",
399 "dailydose1": 0,
400 "dailydose2": 0,
401 "daydiff": 0,
402 "daytotal": 0,
403 "referencedate": "2021-04-28",
404 "totaldistinctpersons": 0,
405 "totaldose1": 0,
406 "totaldose2": 0,
407 "totalvaccinations": 0
408 }
409 ]
410 }
411 "#;
412 let vaccine_series_hist: Result<VaccineSeries, _> = serde_json::from_str(STR_JSON);
413 println!("{:?}", &vaccine_series_hist);
414 assert!(vaccine_series_hist.is_ok());
415 }
416
417 #[test]
418 fn test_deser_region_history() {
419 const STR_JSON: &str = r#"
420
421 {
422 "regions-history": [
423 {
424 "date": "2021-04-29",
425 "regions": [
426 {
427 "area_gr": "string",
428 "area_en": "string",
429 "region_gr": "string",
430 "region_en": "string",
431 "geo_department_gr": "string",
432 "geo_department_en": "string",
433 "last_updated_at": "2021-04-29",
434 "longtitude": 0,
435 "latitude": 0,
436 "population": 0,
437 "cases": 0
438 }
439 ]
440 }
441 ]
442 }
443 "#;
444 let region_series_hist: Result<RegionsHistorySeries, _> = serde_json::from_str(STR_JSON);
445 println!("{:?}", ®ion_series_hist);
446 assert!(region_series_hist.is_ok());
447 }
448 #[test]
449 fn test_deser_females_cases_history() {
450 const STR_JSON: &str = r#"
451 {
452 "female-cases": [
453 {
454 "date": "2021-04-28",
455 "cases": {
456 "0-17": 0,
457 "18-39": 0,
458 "40-64": 0,
459 "65+": 0
460 },
461 "critical": {
462 "0-17": 0,
463 "18-39": 0,
464 "40-64": 0,
465 "65+": 0
466 },
467 "deaths": {
468 "0-17": 0,
469 "18-39": 0,
470 "40-64": 0,
471 "65+": 0
472 }
473 }
474 ]
475 }
476 "#;
477 let females_series_hist: Result<FemaleCasesHistory, _> = serde_json::from_str(STR_JSON);
478 println!("{:?}", &females_series_hist);
479 assert!(females_series_hist.is_ok());
480 }
481
482 #[test]
483 fn test_deser_males_cases_history() {
484 const STR_JSON: &str = r#"
485 {
486 "male-cases": [
487 {
488 "date": "2021-04-28",
489 "cases": {
490 "0-17": 0,
491 "18-39": 0,
492 "40-64": 0,
493 "65+": 0
494 },
495 "critical": {
496 "0-17": 0,
497 "18-39": 0,
498 "40-64": 0,
499 "65+": 0
500 },
501 "deaths": {
502 "0-17": 0,
503 "18-39": 0,
504 "40-64": 0,
505 "65+": 0
506 }
507 }
508 ]
509 }
510 "#;
511 let males_series_hist: Result<MaleCasesHistory, _> = serde_json::from_str(STR_JSON);
512 println!("{:?}", &males_series_hist);
513 assert!(males_series_hist.is_ok());
514 }
515
516 #[test]
517 fn test_deser_age_dist_history() {
518 const STR_JSON: &str = r#"
519 {
520 "age-distribution": [
521 {
522 "date": "2021-04-28",
523 "cases": {
524 "0-17": 0,
525 "18-39": 0,
526 "40-64": 0,
527 "65+": 0
528 },
529 "critical": {
530 "0-17": 0,
531 "18-39": 0,
532 "40-64": 0,
533 "65+": 0
534 },
535 "deaths": {
536 "0-17": 0,
537 "18-39": 0,
538 "40-64": 0,
539 "65+": 0
540 }
541 }
542 ]
543 }
544 "#;
545 let age_dist_series_hist: Result<AgeDistributionSeries, _> = serde_json::from_str(STR_JSON);
546 println!("{:?}", &age_dist_series_hist);
547 assert!(age_dist_series_hist.is_ok());
548 }
549
550 #[test]
551 fn test_deser_confirmed() {
552 const STR_JSON: &str = r#"
553 {
554 "cases": [
555 {
556 "confirmed": 0,
557 "date": "2021-04-28"
558 }
559 ]
560 }
561 "#;
562 let confirmed: Result<ConfirmedSeries, _> = serde_json::from_str(STR_JSON);
563 println!("{:?}", &confirmed);
564 assert!(confirmed.is_ok());
565 }
566
567 #[test]
568 fn test_deser_recovered() {
569 const STR_JSON: &str = r#"
570 {
571 "cases": [
572 {
573 "recovered": 0,
574 "date": "2021-04-28"
575 }
576 ]
577 }
578 "#;
579 let recovered: Result<RecoveredSeries, _> = serde_json::from_str(STR_JSON);
580 println!("{:?}", &recovered);
581 assert!(recovered.is_ok());
582 }
583
584 #[test]
585 fn test_desser_deaths() {
586 const STR_JSON: &str = r#"
587 {
588 "cases": [
589 {
590 "deaths": 0,
591 "date": "2021-04-28"
592 }
593 ]
594 }
595 "#;
596 let deaths: Result<DeathSeries, _> = serde_json::from_str(STR_JSON);
597 println!("{:?}", &deaths);
598 assert!(deaths.is_ok());
599 }
600
601 #[test]
602 fn test_deser_active() {
603 const STR_JSON: &str = r#"
604 {
605 "cases": [
606 {
607 "active": 0,
608 "date": "2021-04-28"
609 }
610 ]
611 }
612 "#;
613 let active: Result<ActiveSeries, _> = serde_json::from_str(STR_JSON);
614 println!("{:?}", &active);
615 assert!(active.is_ok());
616 }
617
618 #[test]
619 fn test_deser_all() {
620 const STR_JSON: &str = r#"
621 {
622 "cases": [
623 {
624 "confirmed": 0,
625 "deaths": 0,
626 "date": "2021-04-29"
627 }
628 ]
629 }
630 "#;
631 let all: Result<AllSeries, _> = serde_json::from_str(STR_JSON);
632 println!("{:?}", &all);
633 assert!(all.is_ok());
634 }
635
636 #[test]
637 fn test_desser_intensive_care() {
638 const STR_JSON: &str = r#"
639 {
640 "cases": [
641 {
642 "intensive_care": 0,
643 "date": "2021-04-29"
644 }
645 ]
646 }
647 "#;
648 let intensive: Result<IntensiveSeries, _> = serde_json::from_str(STR_JSON);
649 println!("{:?}", &intensive);
650 assert!(intensive.is_ok());
651 }
652
653 #[test]
654 fn test_deser_total_tests() {
655 const STR_JSON: &str = r#"
656 {
657 "total_tests": [
658 {
659 "tests": 0,
660 "rapid-tests" : 0,
661 "date": "2021-04-29"
662 }
663 ]
664 }
665 "#;
666 let tests: Result<TestSeries, _> = serde_json::from_str(STR_JSON);
667 println!("{:?}", &tests);
668 assert!(tests.is_ok());
669 }
670
671 #[test]
672 fn test_get_all_data() {
673 let res = get_all_series_data();
674 }
675
676 #[test]
677 fn test_get_confirmed_data() {
678 let res = get_confirmed_series_data();
679 }
680
681 #[test]
682 fn test_get_recovered_data() {
683 let res = get_recovered_series_data();
684 }
685
686 #[test]
687 fn test_get_deaths_series_data() {
688 let res = get_deaths_series_data();
689 }
690
691 #[test]
692 fn test_get_active_series_data() {
693 let res = get_active_series_data();
694 }
695
696 #[test]
697 fn test_get_intensive_care_data() {
698 let res = get_intensive_care_series_data();
699 }
700
701 #[test]
702 fn test_get_total_tests_data() {
703 let res = get_total_tests_series_data();
704 }
705
706 #[test]
707 fn test_get_age_dist_series_data() {
708 let res = get_age_dist_series_data();
709 }
710
711 #[test]
712 fn test_get_regions_history_data() {
713 let res = get_regions_history_series_data();
714 }
715
716 #[test]
717 fn test_get_males_cases_series_data() {
718 let res = get_male_cases_series_data();
719 }
720
721 #[test]
722 fn test_get_females_cases_series_data() {
723 let res = get_female_cases_series_data();
724 }
725
726 #[test]
727 fn test_vaccin_history_data() {
728 let res = get_vaccin_per_region_series_data();
729 }
730
731 #[test]
732 fn test_get_school_status_data() {
733 let res = get_school_status_series_data();
734 }
735}