File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Design Project Assignment : Small Component:
2+
3+ The data layer now includes a small ` data.coordinates ` component for validating city coordinates before writes reach MongoDB.
4+
5+ ## What was added
6+
7+ ### ` feat: create small component for data.coordinates `
8+
9+ ` data/coordinates.py ` provides:
10+
11+ - ` Coordinate ` — abstract base class for validated numeric coordinate values
12+ - ` Latitude ` — validates values in the range ` -90..90 `
13+ - ` Longitude ` — validates values in the range ` -180..180 `
14+ - ` Coordinates ` — wrapper for paired latitude/longitude values with:
15+ - ` from_dict() `
16+ - ` to_dict() `
17+
18+ Example:
19+
20+ ``` python
21+ from data.coordinates import Coordinates
22+
23+ coords = Coordinates.from_dict({
24+ " latitude" : 39.78 ,
25+ " longitude" : - 89.64 ,
26+ })
27+
28+ payload = coords.to_dict()
29+ ```
30+
31+ ## Where it is used
32+
33+ ` data/cities.py ` now validates coordinate payloads in:
34+
35+ - ` add_city() `
36+ - ` update_city() `
37+ - ` update_city_by_name_and_country() `
38+
39+ The stored data shape is unchanged:
40+
41+ ``` python
42+ {
43+ " coordinates" : {
44+ " latitude" : 39.78 ,
45+ " longitude" : - 89.64 ,
46+ }
47+ }
48+ ```
49+
50+ ## Validation behavior
51+
52+ The component rejects:
53+
54+ - non-dict coordinate payloads
55+ - missing ` latitude `
56+ - missing ` longitude `
57+ - non-numeric values
58+ - boolean values
59+ - latitude outside ` -90..90 `
60+ - longitude outside ` -180..180 `
61+
62+ ## Tests
63+
64+ ### ` test: add testing to coordinates component `
65+
66+ Coverage was added in:
67+
68+ - ` data/tests/test_coordinates.py `
69+ - ` data/tests/test_cities.py `
70+
71+ Run the relevant tests with:
72+
73+ ``` bash
74+ python -m pytest data/tests/test_coordinates.py data/tests/test_cities.py -q
75+ ```
You can’t perform that action at this time.
0 commit comments