-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
277 additions
and
76 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::sync::Arc; | ||
|
||
use poem::web::Data; | ||
use poem_openapi::{payload::Json, OpenApi}; | ||
|
||
use crate::{ | ||
auth::middleware::AuthToken, models::property::Property, state::AppState | ||
}; | ||
|
||
pub struct ApiProperties; | ||
|
||
#[OpenApi] | ||
impl ApiProperties { | ||
#[oai(path = "/property/:property_id", method = "get")] | ||
async fn get_property( | ||
&self, | ||
auth: AuthToken, | ||
state: Data<&Arc<AppState>>, | ||
) -> poem_openapi::payload::Json<Vec<Property>> { | ||
match auth { | ||
AuthToken::Active(active_user) => poem_openapi::payload::Json( | ||
Property::get_by_owner_id(active_user.session.user_id, &state.database) | ||
.await | ||
.unwrap(), | ||
), | ||
AuthToken::None => poem_openapi::payload::Json(vec![]), | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import useSWR from 'swr'; | ||
|
||
type GeoIpResponse = { | ||
ip_address: string; | ||
latitude: number; | ||
longitude: number; | ||
postal_code: string; | ||
continent_code: string; | ||
continent_name: string; | ||
country_code: string; | ||
country_name: string; | ||
region_code: string; | ||
region_name: string; | ||
province_code: string; | ||
province_name: string; | ||
city_name: string; | ||
timezone: string; | ||
}; | ||
|
||
export const useGeoIp = (ip: string) => | ||
useSWR( | ||
'geo:' + ip, | ||
async () => { | ||
const response = await fetch('https://api.geoip.rs/?ip=' + ip); | ||
const data = await response.json(); | ||
|
||
return data as GeoIpResponse; | ||
}, | ||
{ errorRetryInterval: 10_000 } | ||
); |
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,10 @@ | ||
import { useHttp } from './core'; | ||
|
||
type MediaResponse = { | ||
id: number; | ||
description: string; | ||
url: string; | ||
}; | ||
|
||
export const useMedia = (id: string) => | ||
useHttp<MediaResponse>('/api/media/' + id); |
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,14 @@ | ||
import { useHttp } from './core'; | ||
|
||
export type PropertyResponse = { | ||
id: number; | ||
owner_id: number; | ||
product_id: number; | ||
name?: string; | ||
media?: number[]; | ||
created?: string; | ||
modified?: string; | ||
}; | ||
|
||
export const useProperty = (id: string) => | ||
useHttp<PropertyResponse>('/api/property/' + id); |
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.