vesys-bank-server/socket-server/src/commands/get_account_nrs.rs
Sebastian Hugentobler dac95b7dae
Implement the http variant of the bank server.
During that process, many shortcomings with the socket server and the
bank lib were fixed.

I am aware a massive commit like this is not ideal.
2022-03-18 19:35:34 +01:00

25 lines
593 B
Rust

use std::io::Write;
use std::net::TcpStream;
use std::sync::{Arc, RwLock};
use anyhow::Result;
use bank::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)
}
}