we compiled

This commit is contained in:
filipriec
2025-03-24 22:03:04 +01:00
parent 70d83c284a
commit 3ed6fd4ee8
3 changed files with 17 additions and 19 deletions

View File

@@ -1,7 +1,10 @@
// src/auth/handlers/register.rs
use bcrypt::{hash, DEFAULT_COST}; use bcrypt::{hash, DEFAULT_COST};
use tonic::{Request, Response, Status}; use tonic::{Request, Response, Status};
use uuid::Uuid; use common::proto::multieko2::auth::{auth_service_server, RegisterRequest, AuthResponse};
use crate::{auth::{models::{RegisterRequest, AuthResponse, AuthError}, db::PgPool}}; use crate::db::PgPool;
use crate::auth::models::AuthError;
pub struct AuthService { pub struct AuthService {
pool: PgPool, pool: PgPool,
@@ -14,11 +17,11 @@ impl AuthService {
} }
#[tonic::async_trait] #[tonic::async_trait]
impl multieko2::auth::auth_service_server::AuthService for AuthService { impl auth_service_server::AuthService for AuthService {
async fn register( async fn register(
&self, &self,
request: Request<multieko2::auth::RegisterRequest>, request: Request<RegisterRequest>,
) -> Result<Response<multieko2::auth::AuthResponse>, Status> { ) -> Result<Response<AuthResponse>, Status> {
let payload = request.into_inner(); let payload = request.into_inner();
// Validate passwords match // Validate passwords match
@@ -51,10 +54,10 @@ impl multieko2::auth::auth_service_server::AuthService for AuthService {
} }
})?; })?;
Ok(Response::new(multieko2::auth::AuthResponse { Ok(Response::new(AuthResponse {
id: user.id.to_string(), id: user.id.to_string(),
username: user.username, username: user.username,
email: user.email, email: user.email.unwrap_or_default(),
role: user.role, role: user.role,
})) }))
} }

View File

@@ -1,26 +1,19 @@
// src/auth/models.rs
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use uuid::Uuid;
use validator::Validate; use validator::Validate;
#[derive(Debug, Validate, Deserialize)] #[derive(Debug, Validate, Deserialize)]
pub struct RegisterRequest { pub struct RegisterRequest {
#[validate(length(min = 3, max = 30))] #[validate(length(min = 1, max = 30))]
pub username: String, pub username: String,
#[validate(email)] #[validate(email)]
pub email: String, pub email: String,
#[validate(length(min = 8))] #[validate(length(min = 1))]
pub password: String, pub password: String,
pub password_confirmation: String, pub password_confirmation: String,
} }
#[derive(Debug, Serialize)]
pub struct AuthResponse {
pub id: Uuid,
pub username: String,
pub email: String,
pub role: String,
}
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum AuthError { pub enum AuthError {
#[error("Passwords do not match")] #[error("Passwords do not match")]

View File

@@ -1,5 +1,7 @@
// src/db.rs // src/db.rs
use sqlx::postgres::{PgPool, PgPoolOptions};
use sqlx::postgres::PgPoolOptions;
pub use sqlx::postgres::PgPool;
use std::time::Duration; use std::time::Duration;
use tracing::info; use tracing::info;