1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
use std::str::FromStr;
use time::Date;
use crate::{activity::*, contact::*, id::*, links::*, location::*, review::*, revision::*};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PlaceRoot {
pub id: Id,
pub license: String,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct OpeningHours(String);
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct OpeningHoursParseError;
impl OpeningHours {
pub const fn min_len() -> usize {
4
}
}
impl FromStr for OpeningHours {
type Err = OpeningHoursParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let trimmed = s.trim();
if trimmed.len() < Self::min_len() {
return Err(OpeningHoursParseError);
}
Ok(Self(trimmed.to_string()))
}
}
impl From<String> for OpeningHours {
fn from(from: String) -> Self {
let res = Self(from);
debug_assert_eq!(Ok(&res), res.0.as_str().parse().as_ref());
res
}
}
impl From<OpeningHours> for String {
fn from(from: OpeningHours) -> Self {
from.0
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PlaceRevision {
pub revision: Revision,
pub created: Activity,
pub title: String,
pub description: String,
pub location: Location,
pub contact: Option<Contact>,
pub opening_hours: Option<OpeningHours>,
pub founded_on: Option<Date>,
pub links: Option<Links>,
pub tags: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Place {
pub id: Id,
pub license: String,
pub revision: Revision,
pub created: Activity,
pub title: String,
pub description: String,
pub location: Location,
pub contact: Option<Contact>,
pub opening_hours: Option<OpeningHours>,
pub founded_on: Option<Date>,
pub links: Option<Links>,
pub tags: Vec<String>,
}
impl Place {
pub fn strip_activity_details(self) -> Self {
Self {
created: self.created.anonymize(),
..self
}
}
pub fn strip_contact_details(self) -> Self {
Self {
contact: None,
..self
}
}
pub fn is_owned<'a>(&self, moderated_tags: impl IntoIterator<Item = &'a str>) -> bool {
moderated_tags
.into_iter()
.any(|moderated_tag| self.tags.iter().any(|tag| tag == moderated_tag))
}
}
impl From<(PlaceRoot, PlaceRevision)> for Place {
fn from(from: (PlaceRoot, PlaceRevision)) -> Self {
let (
PlaceRoot { id, license },
PlaceRevision {
revision,
created,
title,
description,
location,
contact,
opening_hours,
founded_on,
links,
tags,
},
) = from;
Self {
id,
license,
revision,
created,
title,
description,
location,
contact,
opening_hours,
founded_on,
links,
tags,
}
}
}
impl From<Place> for (PlaceRoot, PlaceRevision) {
fn from(from: Place) -> Self {
let Place {
id,
license,
revision,
created,
title,
description,
location,
contact,
opening_hours,
founded_on,
links,
tags,
} = from;
(
PlaceRoot { id, license },
PlaceRevision {
revision,
created,
title,
description,
location,
contact,
opening_hours,
founded_on,
links,
tags,
},
)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PlaceHistory {
pub place: PlaceRoot,
pub revisions: Vec<(PlaceRevision, Vec<ReviewStatusLog>)>,
}