Skip to content

Commit

Permalink
Refactor folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
tbsklg committed Aug 23, 2024
1 parent e516081 commit 76e34da
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 30 deletions.
9 changes: 9 additions & 0 deletions cli-client/src/clients/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::collections::HashMap;

use crate::tarnished::Tarnished;

pub trait StrikeClient {
fn add_strike(&self, name: &str) -> HashMap<String, i8>;
fn get_tarnished(&self) -> Vec<Tarnished>;
fn clear_strikes(&self);
}
30 changes: 2 additions & 28 deletions cli-client/src/clients/local_client.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
use serde_json::json;
use std::collections::HashMap;

#[derive(Debug, PartialEq, Clone)]
pub struct Tarnished {
pub name: String,
pub strikes: u8,
}

impl Tarnished {
fn sort_desc_by_strike(tarnished: Vec<Tarnished>) -> Vec<Tarnished> {
let mut tarnished = tarnished.clone();
tarnished.sort_by(|a, b| b.strikes.partial_cmp(&a.strikes).unwrap());
tarnished
}

fn as_tarnished(db: HashMap<String, u8>) -> Vec<Tarnished> {
db.iter()
.map(|(name, strikes)| Tarnished {
name: name.to_string(),
strikes: *strikes,
})
.collect()
}
}

pub trait StrikeClient {
fn add_strike(&self, name: &str) -> HashMap<String, i8>;
fn get_tarnished(&self) -> Vec<Tarnished>;
fn clear_strikes(&self);
}
use crate::tarnished::Tarnished;
use super::client::StrikeClient;

pub struct LocalClient {
pub db_path: std::path::PathBuf,
Expand Down
1 change: 1 addition & 0 deletions cli-client/src/clients/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod local_client;
pub mod remote_client;
pub mod client;
1 change: 1 addition & 0 deletions cli-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod configuration;
pub mod clients;
pub mod output;
pub mod tarnished;
3 changes: 2 additions & 1 deletion cli-client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::{Parser, Subcommand};
use strikes::clients::client::StrikeClient;
use std::path::PathBuf;
use strikes::clients::local_client::{LocalClient, StrikeClient};
use strikes::clients::local_client::LocalClient;
use strikes::configuration::get_configuration;
use strikes::output::print_as_table;

Expand Down
2 changes: 1 addition & 1 deletion cli-client/src/output.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::clients::local_client::Tarnished;
use crate::tarnished::Tarnished;

pub fn print_as_table(tarnished: Vec<Tarnished>) {
println!("{0: <10} | {1: <10} |", "Tarnished", "Strikes");
Expand Down
25 changes: 25 additions & 0 deletions cli-client/src/tarnished.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::collections::HashMap;

#[derive(Debug, PartialEq, Clone)]
pub struct Tarnished {
pub name: String,
pub strikes: u8,
}

impl Tarnished {
pub fn sort_desc_by_strike(tarnished: Vec<Tarnished>) -> Vec<Tarnished> {
let mut tarnished = tarnished.clone();
tarnished.sort_by(|a, b| b.strikes.partial_cmp(&a.strikes).unwrap());
tarnished
}

pub fn as_tarnished(db: HashMap<String, u8>) -> Vec<Tarnished> {
db.iter()
.map(|(name, strikes)| Tarnished {
name: name.to_string(),
strikes: *strikes,
})
.collect()
}
}

0 comments on commit 76e34da

Please sign in to comment.