add fetch_one note

This commit is contained in:
Edward Shen 2021-02-08 20:59:35 -05:00
parent f560236f8f
commit e6ff1576f1
Signed by: edward
GPG key ID: 19182661E818369F

View file

@ -4,15 +4,9 @@ use sodiumoxide::crypto::pwhash::argon2id13::{pwhash_verify, HashedPassword};
use sqlx::{query, PgPool};
use std::convert::TryFrom;
use thiserror::Error;
use vtse_common::{
net::{ServerResponse, UserError},
user::User,
};
use vtse_common::{stock::Stock, user::UserBalance};
use vtse_common::{
stock::StockSymbol,
user::{ApiKey, Password, UserDebt, Username},
};
use vtse_common::net::{ServerResponse, UserError};
use vtse_common::stock::{Stock, StockSymbol};
use vtse_common::user::{ApiKey, Password, User, UserBalance, UserDebt, Username};
#[derive(Error, Debug)]
pub(crate) enum StateError {
@ -234,6 +228,9 @@ impl AppState {
todo!()
}
// todo: fetch_one needs to turn into fetch_optional, else we can't discriminate user versus
// server error.
async fn get_user_balance(user_id: i32, pool: &PgPool) -> Result<Decimal, StateError> {
query!("SELECT balance FROM users where user_id = $1", user_id)
.fetch_one(pool)