Skip to content

Commit

Permalink
Use platform as string
Browse files Browse the repository at this point in the history
  • Loading branch information
gemcoder21 committed Sep 3, 2023
1 parent 5253048 commit c2430b5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
5 changes: 3 additions & 2 deletions api/src/device/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extern crate rocket;
use std::error::Error;

use primitives::platform::Platform;
use storage::database::DatabaseClient;

pub struct DevicesClient {
Expand Down Expand Up @@ -29,7 +30,7 @@ impl DevicesClient {
Ok(
primitives::device::Device {
id: device.device_id,
platform: device.platform,
platform: Platform::from_str(device.platform.as_str()).unwrap(),
token: device.token,
is_push_enabled: device.is_push_enabled,
}
Expand All @@ -45,7 +46,7 @@ impl DevicesClient {
pub fn map_device(&self, device: primitives::device::Device) -> storage::models::Device {
return storage::models::Device {
device_id: device.id,
platform: device.platform,
platform: device.platform.as_str().to_string(),
token: device.token,
is_push_enabled: device.is_push_enabled,
};
Expand Down
4 changes: 3 additions & 1 deletion primitives/src/device.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use typeshare::typeshare;
use serde::{Serialize, Deserialize};

use crate::platform::Platform;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[typeshare(swift="Codable")]
#[serde(rename_all = "camelCase")]
pub struct Device {
pub id: String,
pub platform: i32,
pub platform: Platform,
pub token: String,
pub is_push_enabled: bool,
}
10 changes: 10 additions & 0 deletions primitives/src/platform.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use typeshare::typeshare;
use serde::{Serialize, Deserialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[typeshare(swift="Codable")]
#[serde(rename_all = "lowercase")]
pub enum Platform {
IOS,
Expand All @@ -14,4 +16,12 @@ impl Platform {
Platform::Android => "android",
}
}

pub fn from_str(s: &str) -> Option<Platform> {
match s {
"ios" => Some(Platform::IOS),
"android" => Some(Platform::Android),
_ => None,
}
}
}
2 changes: 1 addition & 1 deletion storage/src/migrations/2023-09-03-192926_devices/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CREATE TABLE devices (
id SERIAL PRIMARY KEY,
device_id VARCHAR NOT NULL,
is_push_enabled boolean NOT NULL,
platform INTEGER NOT NULL,
platform VARCHAR NOT NULL,
token VARCHAR NOT NULL,
updated_at timestamp NOT NULL default current_timestamp,
created_at timestamp NOT NULL default current_timestamp,
Expand Down
2 changes: 1 addition & 1 deletion storage/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl Price {
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Device {
pub device_id: String,
pub platform: i32,
pub platform: String,
pub token: String,
pub is_push_enabled: bool,
}
2 changes: 1 addition & 1 deletion storage/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ diesel::table! {
id -> Int4,
device_id -> Varchar,
is_push_enabled -> Bool,
platform -> Int4,
platform -> Varchar,
token -> Varchar,
updated_at -> Timestamp,
created_at -> Timestamp,
Expand Down

0 comments on commit c2430b5

Please sign in to comment.