invesa / src /models.rs
gowtham851's picture
feat: Add self-contained Rust backend with local PostgreSQL database
6c93417
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use chrono::{DateTime, Utc};
// ----------------------------------------
// Database entity models
// ----------------------------------------
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct User {
pub id: Uuid,
pub name: String,
pub email: String,
pub password_hash: String,
pub role: String, // 'founder', 'builder', 'investor'
pub bio: Option<String>,
pub skills: Option<Vec<String>>,
pub linkedin: Option<String>,
pub created_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PublicUser {
pub id: Uuid,
pub name: String,
pub email: String,
pub role: String,
pub bio: Option<String>,
pub skills: Option<Vec<String>>,
pub linkedin: Option<String>,
pub created_at: DateTime<Utc>,
}
impl From<User> for PublicUser {
fn from(user: User) -> Self {
Self {
id: user.id,
name: user.name,
email: user.email,
role: user.role,
bio: user.bio,
skills: user.skills,
linkedin: user.linkedin,
created_at: user.created_at,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct TeamMember {
pub id: Uuid,
pub idea_id: Uuid,
pub user_id: Uuid,
pub role_title: String,
pub joined_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TeamMemberDetail {
pub id: Uuid,
pub user_id: Uuid,
pub name: String,
pub role_title: String,
pub joined_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct JoinRequest {
pub id: Uuid,
pub idea_id: Uuid,
pub builder_id: Uuid,
pub message: String,
pub status: String, // 'pending', 'accepted', 'rejected'
pub created_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JoinRequestDetail {
pub id: Uuid,
pub idea_id: Uuid,
pub builder_id: Uuid,
pub builder_name: String,
pub builder_skills: Vec<String>,
pub message: String,
pub status: String,
pub created_at: DateTime<Utc>,
pub idea_title: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct InvestorInterest {
pub id: Uuid,
pub idea_id: Uuid,
pub investor_id: Uuid,
pub note: String,
pub created_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InvestorInterestDetail {
pub id: Uuid,
pub idea_id: Uuid,
pub investor_id: Uuid,
pub investor_name: String,
pub note: String,
pub created_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct Idea {
pub id: Uuid,
pub founder_id: Uuid,
pub title: String,
pub summary: String,
pub description: String,
pub category: String,
pub stage: String,
pub team_slots: Vec<String>,
pub ip_hash: String,
pub created_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IdeaDetail {
pub id: Uuid,
pub founder_id: Uuid,
pub founder_name: String,
pub title: String,
pub summary: String,
pub description: String,
pub category: String,
pub stage: String,
pub team_slots: Vec<String>,
pub ip_hash: String,
pub created_at: DateTime<Utc>,
pub team_members: Vec<TeamMemberDetail>,
pub join_requests: Vec<JoinRequestDetail>,
pub investor_interests: Vec<InvestorInterestDetail>,
}
// ----------------------------------------
// Request / Response payloads
// ----------------------------------------
#[derive(Debug, Deserialize)]
pub struct RegisterReq {
pub name: String,
pub email: String,
pub password_hash: String, // For simplicity matches client payload
pub role: String,
pub bio: Option<String>,
pub skills: Option<Vec<String>>,
pub linkedin: Option<Option<String>>,
}
#[derive(Debug, Deserialize)]
pub struct LoginReq {
pub email: String,
pub password_hash: String,
}
#[derive(Debug, Serialize)]
pub struct AuthRes {
pub token: String,
pub user: PublicUser,
}
#[derive(Debug, Deserialize)]
pub struct CreateIdeaReq {
pub title: String,
pub summary: String,
pub description: String,
pub category: String,
pub stage: String,
pub team_slots: Vec<String>,
pub ip_hash: String,
}
#[derive(Debug, Deserialize)]
pub struct JoinRequestReq {
pub message: String,
}
#[derive(Debug, Deserialize)]
pub struct InvestorInterestReq {
pub note: String,
}
#[derive(Debug, Deserialize)]
pub struct JoinRequestStatusReq {
pub status: String, // 'accepted', 'rejected'
}