mirror of
https://github.com/alvierahman90/rabbit.git
synced 2024-12-15 11:01:59 +00:00
rustfmt
This commit is contained in:
parent
bd8266b795
commit
53208b73f9
@ -1,8 +1,8 @@
|
||||
pub mod json;
|
||||
|
||||
use crate::models::*;
|
||||
use std::io;
|
||||
use serde_json;
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
@ -26,7 +26,12 @@ impl From<serde_json::Error> for Error {
|
||||
pub trait Storage {
|
||||
fn add_category(&mut self, category: NewCategory) -> Result<i32, Error>;
|
||||
fn add_series(&mut self, category_id: i32, series: NewSeries) -> Result<i32, Error>;
|
||||
fn add_series_point(&mut self, category_id: i32, series_id: i32, series_point: NewSeriesPoint) -> Result<i32, Error>;
|
||||
fn add_series_point(
|
||||
&mut self,
|
||||
category_id: i32,
|
||||
series_id: i32,
|
||||
series_point: NewSeriesPoint,
|
||||
) -> Result<i32, Error>;
|
||||
//fn add_user(&mut self, id: i32, user: NewUser) -> Result<User, Error>;
|
||||
fn get_category(&self, id: i32) -> Option<Category>;
|
||||
fn get_series(&self, category_id: i32, series_id: i32) -> Option<Series>;
|
||||
|
@ -9,7 +9,9 @@ impl JsonDb {
|
||||
pub fn new(value: Option<String>) -> Self {
|
||||
match value {
|
||||
Some(value) => JsonDb { value },
|
||||
None => JsonDb { value: String::from("[]") },
|
||||
None => JsonDb {
|
||||
value: String::from("[]"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +28,7 @@ impl JsonDb {
|
||||
Ok(d) => {
|
||||
self.value = d;
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
Err(e) => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
@ -65,7 +67,6 @@ impl Storage for JsonDb {
|
||||
}
|
||||
let cat = cat.unwrap();
|
||||
|
||||
|
||||
for series in cat.series.iter().clone() {
|
||||
if series.id > max_id {
|
||||
max_id = series.id;
|
||||
@ -79,7 +80,12 @@ impl Storage for JsonDb {
|
||||
Ok(max_id + 1)
|
||||
}
|
||||
|
||||
fn add_series_point(&mut self, category_id: i32, series_id: i32, series_point: NewSeriesPoint) -> Result<i32, Error> {
|
||||
fn add_series_point(
|
||||
&mut self,
|
||||
category_id: i32,
|
||||
series_id: i32,
|
||||
series_point: NewSeriesPoint,
|
||||
) -> Result<i32, Error> {
|
||||
let mut max_id = 1;
|
||||
let mut cat: Option<&mut Category> = None;
|
||||
let mut series: Option<&mut Series> = None;
|
||||
@ -148,7 +154,7 @@ impl Storage for JsonDb {
|
||||
|
||||
for series_opt in cat.series {
|
||||
if series_opt.id == series_id {
|
||||
return Some(series_opt)
|
||||
return Some(series_opt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
mod utils;
|
||||
pub mod models;
|
||||
pub mod db;
|
||||
pub mod models;
|
||||
mod utils;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::models::Series;
|
||||
use serde::{ Serialize, Deserialize };
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Category {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use chrono;
|
||||
use super::series_point::SeriesPoint;
|
||||
use serde::{ Serialize, Deserialize };
|
||||
use chrono;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with;
|
||||
|
||||
#[serde_with::serde_as]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use chrono;
|
||||
use super::series_type::SeriesType;
|
||||
use serde::{ Serialize, Deserialize };
|
||||
use chrono;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct SeriesPoint {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use serde::{ Serialize, Deserialize };
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum SeriesType {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use serde::{ Serialize, Deserialize };
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct User {
|
||||
|
Loading…
Reference in New Issue
Block a user