fix: generate i64 session ids instead of u64

This commit is contained in:
Jef Roosens 2025-01-12 08:48:24 +01:00
parent 48b3191117
commit 7cf0e44b65
Signed by: Jef Roosens
GPG key ID: 21FD3D77D56BAF49
9 changed files with 18 additions and 15 deletions

View file

@ -5,14 +5,14 @@ use super::{DbError, DbPool};
#[derive(Serialize, Deserialize)]
pub struct Comment {
id: i32,
plant_id: i32,
id: i64,
plant_id: i64,
comment: String,
}
#[derive(Deserialize)]
pub struct NewComment {
plant_id: i32,
plant_id: i64,
comment: String,
}

View file

@ -64,8 +64,8 @@ impl FromSql for EventType {
#[derive(Serialize)]
pub struct Event {
id: i32,
plant_id: i32,
id: i64,
plant_id: i64,
event_type: EventType,
date: NaiveDate,
description: String,
@ -85,7 +85,7 @@ impl Event {
#[derive(Deserialize)]
pub struct NewEvent {
plant_id: i32,
plant_id: i64,
event_type: EventType,
date: NaiveDate,
description: String,

View file

@ -5,7 +5,7 @@ use super::{Comment, DbError, DbPool, Event};
#[derive(Serialize)]
pub struct Plant {
id: i32,
id: i64,
name: String,
species: String,
description: String,
@ -37,7 +37,7 @@ impl Plant {
Ok(plants?)
}
pub fn by_id(pool: &DbPool, id: i32) -> Result<Option<Self>, DbError> {
pub fn by_id(pool: &DbPool, id: i64) -> Result<Option<Self>, DbError> {
let conn = pool.get()?;
let mut stmt = conn.prepare("select * from plants where id = $1")?;

View file

@ -1,10 +1,11 @@
use argon2::password_hash::rand_core::{OsRng, RngCore};
use rand::Rng;
use rusqlite::Row;
use super::{DbError, DbPool, User};
pub struct Session {
pub id: u64,
pub id: i64,
pub user_id: i32,
}
@ -16,7 +17,7 @@ impl Session {
})
}
pub fn user_from_id(pool: &DbPool, id: u64) -> Result<Option<super::User>, DbError> {
pub fn user_from_id(pool: &DbPool, id: i64) -> Result<Option<super::User>, DbError> {
let conn = pool.get()?;
let mut stmt = conn.prepare("select users.* from sessions inner join users on sessions.user_id = users.id where sessions.id = $1")?;
@ -27,8 +28,8 @@ impl Session {
}
}
pub fn new_for_user(pool: &DbPool, user_id: i32) -> Result<Self, DbError> {
let id: u64 = OsRng.next_u64();
pub fn new_for_user(pool: &DbPool, user_id: i64) -> Result<Self, DbError> {
let id: i64 = rand::thread_rng().gen();
let conn = pool.get()?;
let mut stmt =

View file

@ -9,7 +9,7 @@ use super::{DbError, DbPool};
#[derive(Serialize, Deserialize, Clone)]
pub struct User {
pub id: i32,
pub id: i64,
pub username: String,
pub password_hash: String,
pub admin: bool,