initial commit
This commit is contained in:
commit
3d9c98eeca
22 changed files with 1075 additions and 0 deletions
26
src/commands/get_account_nrs.rs
Normal file
26
src/commands/get_account_nrs.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use std::io::Write;
|
||||
use std::net::TcpStream;
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::bank::Bank;
|
||||
use crate::commands::Command;
|
||||
use crate::protocol;
|
||||
|
||||
pub struct GetAccountNrs;
|
||||
|
||||
impl Command for GetAccountNrs {
|
||||
fn execute(&self, bank: Arc<RwLock<Bank>>, _: &[u8], mut stream: &TcpStream) -> Result<usize> {
|
||||
info!("getting account numbers...");
|
||||
|
||||
let bank = bank.read().unwrap();
|
||||
let nrs: Vec<String> = bank.account_numbers()
|
||||
.into_iter()
|
||||
.collect();
|
||||
|
||||
let written = stream.write(&protocol::account_nrs(&nrs))?;
|
||||
|
||||
Ok(written)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue