Skip to content

Commit

Permalink
Introduce map to session
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Jul 30, 2024
1 parent 16c8e99 commit dd0ccdd
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 76 deletions.
1 change: 1 addition & 0 deletions engine/src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::state::AppState;

pub mod me;
pub mod oauth;
pub mod properties;
pub mod root;
pub mod sessions;

Expand Down
29 changes: 29 additions & 0 deletions engine/src/routes/properties/mod.rs
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![]),
}
}
}
3 changes: 3 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
"clsx": "^2.1.1",
"eslint-plugin-unused-imports": "^4.0.1",
"globals": "^15.8.0",
"leaflet": "^1.9.4",
"postcss": "^8.4.38",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-leaflet": "^4.2.1",
"swr": "^2.2.5",
"tailwindcss": "^3.4.3",
"ua-parser-js": "^1.0.38",
Expand All @@ -33,6 +35,7 @@
"devDependencies": {
"@tanstack/router-devtools": "^1.45.14",
"@tanstack/router-plugin": "^1.45.13",
"@types/leaflet": "^1.9.12",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/ua-parser-js": "^0.7.39",
Expand Down
48 changes: 48 additions & 0 deletions web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions web/src/api/geoip.ts
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 }
);
10 changes: 10 additions & 0 deletions web/src/api/media.ts
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);
14 changes: 14 additions & 0 deletions web/src/api/property.ts
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);
2 changes: 1 addition & 1 deletion web/src/api/sessions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useHttp } from './core';

type SessionResponse = {
export type SessionResponse = {
id: string;
user_id: number;
user_agent: string;
Expand Down
Loading

0 comments on commit dd0ccdd

Please sign in to comment.