melodium_repository/global/
package.rs

1use super::{Author, Tag, Type};
2use chrono::{DateTime, Utc};
3use semver::Version;
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6//use iso639_1::Iso639_1;
7
8#[derive(Clone, Debug, Serialize, Deserialize)]
9pub struct Package {
10    pub name: String,
11    pub authors: Vec<Author>,
12    pub publication: DateTime<Utc>,
13    // TODO when https://github.com/AlbanMinassian/iso639/tree/master/iso639-1 is released as 0.3.1 with serde
14    // pub description: HashMap<Iso639_1, String>,
15    pub description: HashMap<String, String>,
16    pub version: Version,
17    pub license: String,
18    pub homepage: Option<String>,
19    pub repository: Option<String>,
20    pub r#type: Type,
21    pub tags: Vec<Tag>,
22}
23
24impl From<&crate::technical::Package> for Package {
25    fn from(value: &crate::technical::Package) -> Self {
26        Self {
27            name: value.name.clone(),
28            authors: Vec::new(),
29            publication: DateTime::parse_from_rfc3339("2023-05-11T10:03:00+02:00")
30                .unwrap()
31                .into(),
32            description: HashMap::new(),
33            version: value.version.clone(),
34            license: String::new(),
35            homepage: None,
36            repository: None,
37            r#type: match value.r#type {
38                crate::technical::Type::Jeu { .. } => Type::Jeu,
39                crate::technical::Type::Compiled { .. } => Type::Compiled,
40            },
41            tags: Vec::new(),
42        }
43    }
44}
45
46impl PartialEq for Package {
47    fn eq(&self, other: &Self) -> bool {
48        self.name == other.name && self.version == other.version
49    }
50}