-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backend, frontend: add geographic restrictions to access tokens
- Loading branch information
Showing
15 changed files
with
323 additions
and
12 deletions.
There are no files selected for viewing
5 changes: 3 additions & 2 deletions
5
...cc13ebb08158644bff59dc14451c40cd7904.json → ...23e76275727202fe37ef64b32778b25d824a.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 3 additions & 2 deletions
5
...b53013a580d1b8a09d31ecb5309700706d0f.json → ...26af12513af8da0a9d21b5eb56e9cf86c724.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod deserializers; | ||
pub mod hcaptcha; | ||
pub mod postgis_polygons; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use utoipa::ToSchema; | ||
|
||
pub type Coordinates = (f64, f64); | ||
pub type Polygon = Vec<Coordinates>; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, ToSchema)] | ||
pub struct MultiPolygon(Vec<Polygon>); | ||
|
||
impl MultiPolygon { | ||
pub fn to_polygon_string(&self, srid: Option<u32>) -> String { | ||
let polygons_str = self | ||
.0 | ||
.iter() | ||
.map(|polygon| { | ||
let coords_str = polygon | ||
.iter() | ||
.map(|&(x, y)| format!("{} {}", x, y)) | ||
.collect::<Vec<_>>() | ||
.join(", "); | ||
format!("({})", coords_str) | ||
}) | ||
.collect::<Vec<_>>() | ||
.join("),("); | ||
|
||
match srid { | ||
Some(srid) => format!("SRID={};MULTIPOLYGON(({}))", srid, polygons_str), | ||
None => format!("MULTIPOLYGON(({}))", polygons_str), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_to_polygon_string() { | ||
let multi_polygon = MultiPolygon(vec![ | ||
vec![(30.0, 20.0), (45.0, 40.0), (10.0, 40.0), (30.0, 20.0)], | ||
vec![ | ||
(15.0, 5.0), | ||
(40.0, 10.0), | ||
(10.0, 20.0), | ||
(5.0, 10.0), | ||
(15.0, 5.0), | ||
], | ||
]); | ||
|
||
let expected_string = | ||
"MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))"; | ||
assert_eq!(multi_polygon.to_polygon_string(None), expected_string); | ||
} | ||
|
||
#[test] | ||
fn test_to_polygon_string_with_srid() { | ||
let multi_polygon = MultiPolygon(vec![ | ||
vec![(30.0, 20.0), (45.0, 40.0), (10.0, 40.0), (30.0, 20.0)], | ||
vec![ | ||
(15.0, 5.0), | ||
(40.0, 10.0), | ||
(10.0, 20.0), | ||
(5.0, 10.0), | ||
(15.0, 5.0), | ||
], | ||
]); | ||
|
||
let expected_string = | ||
"SRID=3857;MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))"; | ||
assert_eq!(multi_polygon.to_polygon_string(Some(3857)), expected_string); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.