Spaces:
Sleeping
Sleeping
File size: 5,937 Bytes
3c4a809 76089f2 3a19693 3c4a809 76089f2 3c4a809 76089f2 3c4a809 76089f2 3c4a809 76089f2 3c4a809 76089f2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | from sqlalchemy import Column, Integer, String, Text, DateTime, JSON, Boolean, ForeignKey
from sqlalchemy.sql import func
from pydantic import BaseModel
from typing import Optional, Any
from datetime import datetime
from database import Base
# ββ User model ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
username = Column(String, unique=True, index=True, nullable=False)
full_name = Column(String, nullable=True)
email = Column(String, unique=True, nullable=True)
hashed_password = Column(String, nullable=False)
is_admin = Column(Boolean, default=False)
is_active = Column(Boolean, default=True)
created_at = Column(DateTime, server_default=func.now())
class UserResponse(BaseModel):
id: int
username: str
full_name: Optional[str] = None
email: Optional[str] = None
is_admin: bool
is_active: bool
created_at: Optional[datetime] = None
class Config:
from_attributes = True
class UserCreate(BaseModel):
username: str
full_name: Optional[str] = None
email: Optional[str] = None
password: str
is_admin: bool = False
class UserUpdate(BaseModel):
full_name: Optional[str] = None
email: Optional[str] = None
is_admin: Optional[bool] = None
is_active: Optional[bool] = None
class PasswordReset(BaseModel):
new_password: str
# ββ Project model ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
class Project(Base):
__tablename__ = "projects"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False, index=True)
description = Column(Text, nullable=True)
color = Column(String, default="#0073ea")
created_at = Column(DateTime, server_default=func.now())
class ProjectCreate(BaseModel):
name: str
description: Optional[str] = None
color: Optional[str] = "#0073ea"
class ProjectUpdate(BaseModel):
name: Optional[str] = None
description: Optional[str] = None
color: Optional[str] = None
class ProjectResponse(BaseModel):
id: int
name: str
description: Optional[str] = None
color: str
created_at: Optional[datetime] = None
class Config:
from_attributes = True
# SQLAlchemy ORM Model
class Lead(Base):
__tablename__ = "leads"
id = Column(Integer, primary_key=True, index=True)
project_id = Column(Integer, ForeignKey("projects.id", ondelete="SET NULL"), nullable=True, index=True)
company_name = Column(String, index=True, nullable=True)
contact_name = Column(String, nullable=True)
email = Column(String, index=True, nullable=True)
phone = Column(String, nullable=True)
website = Column(String, nullable=True)
industry = Column(String, nullable=True)
company_size = Column(String, nullable=True)
location = Column(String, nullable=True)
linkedin_url = Column(String, nullable=True)
source = Column(String, nullable=True) # csv, excel, linkedin, web_scrape, manual
status = Column(String, default="new") # new, contacted, qualified, converted, archived
notes = Column(Text, nullable=True)
custom_fields = Column(JSON, nullable=True)
created_at = Column(DateTime, server_default=func.now())
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
class ScrapingJob(Base):
__tablename__ = "scraping_jobs"
id = Column(Integer, primary_key=True, index=True)
project_id = Column(Integer, ForeignKey("projects.id", ondelete="SET NULL"), nullable=True, index=True)
url = Column(String)
status = Column(String, default="pending") # pending, running, completed, failed
leads_found = Column(Integer, default=0)
error = Column(Text, nullable=True)
config = Column(JSON, nullable=True)
created_at = Column(DateTime, server_default=func.now())
completed_at = Column(DateTime, nullable=True)
# Pydantic Schemas
class LeadBase(BaseModel):
project_id: Optional[int] = None
company_name: Optional[str] = None
contact_name: Optional[str] = None
email: Optional[str] = None
phone: Optional[str] = None
website: Optional[str] = None
industry: Optional[str] = None
company_size: Optional[str] = None
location: Optional[str] = None
linkedin_url: Optional[str] = None
source: Optional[str] = None
status: Optional[str] = "new"
notes: Optional[str] = None
custom_fields: Optional[dict] = None
class LeadCreate(LeadBase):
pass
class LeadUpdate(LeadBase):
pass
class LeadResponse(LeadBase):
id: int
project_id: Optional[int] = None
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
class Config:
from_attributes = True
class LeadListResponse(BaseModel):
total: int
page: int
page_size: int
leads: list[LeadResponse]
class ScrapingConfig(BaseModel):
url: str
extract_emails: bool = True
extract_phones: bool = True
extract_company_name: bool = True
custom_selectors: Optional[dict] = None
follow_links: bool = False
max_pages: int = 1
class ScrapingJobResponse(BaseModel):
id: int
url: str
status: str
leads_found: int
error: Optional[str] = None
created_at: Optional[datetime] = None
completed_at: Optional[datetime] = None
class Config:
from_attributes = True
class AnalyticsResponse(BaseModel):
total_leads: int
leads_by_status: dict[str, int]
leads_by_source: dict[str, int]
leads_by_industry: dict[str, int]
recent_leads: list[LeadResponse]
conversion_rate: float
|