🔨 Refactors into packages models and dtos
This commit is contained in:
25
src/dtos/hit.rs
Normal file
25
src/dtos/hit.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use crate::models::hit::Hit;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct HitDTO {
|
||||
pub id: String,
|
||||
pub tracker_id: String,
|
||||
pub ip: String,
|
||||
pub agent: Option<String>,
|
||||
pub language: Option<String>,
|
||||
pub created_at: String,
|
||||
}
|
||||
|
||||
impl HitDTO {
|
||||
pub fn from(hit: &Hit) -> HitDTO {
|
||||
HitDTO {
|
||||
id: hit.id.to_string(),
|
||||
tracker_id: hit.tracker_id.to_string(),
|
||||
ip: hit.ip.clone(),
|
||||
agent: hit.agent.clone(),
|
||||
language: hit.language.clone(),
|
||||
created_at: hit.created_at.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
2
src/dtos/mod.rs
Normal file
2
src/dtos/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod hit;
|
||||
pub mod tracker;
|
||||
17
src/dtos/tracker.rs
Normal file
17
src/dtos/tracker.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::models::tracker::Tracker;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct TrackerDTO {
|
||||
pub id: String,
|
||||
pub created_at: String,
|
||||
}
|
||||
|
||||
impl TrackerDTO {
|
||||
pub fn from(tracker: &Tracker) -> TrackerDTO {
|
||||
TrackerDTO {
|
||||
id: tracker.id.to_string(),
|
||||
created_at: tracker.created_at.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user