Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Backend/app/db/seed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import datetime, timezone
from db.db import AsyncSessionLocal
from models.models import User
import sys
import os
from app.db.db import AsyncSessionLocal
from app.models.models import User
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

Refactor or relocate the sys.path hack.

The runtime path append appears after the imports, so it won't help resolve them and is fragile across environments. Consider moving this line above the imports or, better, removing it entirely by structuring the project as a proper Python package (e.g., using setup.py or pyproject.toml) and running with python -m.

Apply this diff to reorder and harden path setup:

- import sys
- import os
- sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+ import sys
+ import os
+ # Ensure `app` package root is discoverable before imports
+ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import sys
import os
# Ensure `app` package root is discoverable before imports
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
πŸ€– Prompt for AI Agents
In Backend/app/db/seed.py at line 5, the sys.path modification occurs after
imports, making it ineffective for resolving module paths. Move the
sys.path.append line to the very top of the file before any imports to ensure it
takes effect. Alternatively, refactor the project into a proper Python package
with setup.py or pyproject.toml and run scripts using python -m to avoid needing
this path hack altogether.



async def seed_db():
Expand Down
10 changes: 5 additions & 5 deletions Backend/app/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from db.db import engine
from db.seed import seed_db
from models import models, chat
from routes.post import router as post_router
from routes.chat import router as chat_router
from app.db.db import engine
from app.db.seed import seed_db
from app.models import models, chat
from app.routes.post import router as post_router
from app.routes.chat import router as chat_router
from sqlalchemy.exc import SQLAlchemyError
import logging
import os
Expand Down
2 changes: 1 addition & 1 deletion Backend/app/models/chat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sqlalchemy import Column, String, ForeignKey, DateTime, Enum, UniqueConstraint
from sqlalchemy.orm import relationship
from datetime import datetime, timezone
from db.db import Base
from app.db.db import Base
import uuid
import enum

Expand Down
26 changes: 19 additions & 7 deletions Backend/app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from sqlalchemy.orm import relationship
from datetime import datetime, timezone
from db.db import Base
from app.db.db import Base
import uuid


Expand Down Expand Up @@ -40,10 +40,18 @@ class User(Base):
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
)

audience = relationship("AudienceInsights", back_populates="user", uselist=False)
sponsorships = relationship("Sponsorship", back_populates="brand")
posts = relationship("UserPost", back_populates="user")
applications = relationship("SponsorshipApplication", back_populates="creator")
audience = relationship(
"AudienceInsights", back_populates="user", uselist=False
)
sponsorships = relationship(
"Sponsorship", back_populates="brand"
)
posts = relationship(
"UserPost", back_populates="user"
)
applications = relationship(
"SponsorshipApplication", back_populates="creator"
)
payments = relationship(
"SponsorshipPayment",
foreign_keys="[SponsorshipPayment.creator_id]",
Expand Down Expand Up @@ -83,7 +91,9 @@ class Sponsorship(Base):
brand_id = Column(String, ForeignKey("users.id"), nullable=False)
title = Column(String, nullable=False)
description = Column(Text, nullable=False)
required_audience = Column(JSON) # {"age": ["18-24"], "location": ["USA", "UK"]}
required_audience = Column(
JSON
) # {"age": ["18-24"], "location": ["USA", "UK"]}
budget = Column(DECIMAL(10, 2))
engagement_minimum = Column(Float)
status = Column(String, default="open")
Expand All @@ -105,7 +115,9 @@ class UserPost(Base):
content = Column(Text, nullable=False)
post_url = Column(Text, nullable=True)
category = Column(String, nullable=True)
engagement_metrics = Column(JSON) # {"likes": 500, "comments": 100, "shares": 50}
engagement_metrics = Column(
JSON
) # {"likes": 500, "comments": 100, "shares": 50}
created_at = Column(
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
)
Expand Down
36 changes: 32 additions & 4 deletions Backend/app/routes/post.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.future import select
from db.db import AsyncSessionLocal
from models.models import (
from app.db.db import AsyncSessionLocal
from app.models.models import (
User, AudienceInsights, Sponsorship, UserPost,
SponsorshipApplication, SponsorshipPayment, Collaboration
)
Comment on lines +4 to 8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove unused SQLAlchemy imports.

The static analysis tools correctly identify that all the imported SQLAlchemy-related classes and AsyncSessionLocal are unused in this file. This file uses Supabase for database operations instead of SQLAlchemy ORM.

-from app.db.db import AsyncSessionLocal
-from app.models.models import (
-    User, AudienceInsights, Sponsorship, UserPost,
-    SponsorshipApplication, SponsorshipPayment, Collaboration
-)

Also remove the unused schema imports from lines 9-12:

-from schemas.schema import (
-    UserCreate, AudienceInsightsCreate, SponsorshipCreate, UserPostCreate,
-    SponsorshipApplicationCreate, SponsorshipPaymentCreate, CollaborationCreate
-)
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from app.db.db import AsyncSessionLocal
from app.models.models import (
User, AudienceInsights, Sponsorship, UserPost,
SponsorshipApplication, SponsorshipPayment, Collaboration
)
🧰 Tools
πŸͺ› Ruff (0.11.9)

4-4: app.db.db.AsyncSessionLocal imported but unused

Remove unused import: app.db.db.AsyncSessionLocal

(F401)


6-6: app.models.models.User imported but unused

Remove unused import

(F401)


6-6: app.models.models.AudienceInsights imported but unused

Remove unused import

(F401)


6-6: app.models.models.Sponsorship imported but unused

Remove unused import

(F401)


6-6: app.models.models.UserPost imported but unused

Remove unused import

(F401)


7-7: app.models.models.SponsorshipApplication imported but unused

Remove unused import

(F401)


7-7: app.models.models.SponsorshipPayment imported but unused

Remove unused import

(F401)


7-7: app.models.models.Collaboration imported but unused

Remove unused import

(F401)

πŸͺ› Flake8 (7.2.0)

[error] 4-4: 'app.db.db.AsyncSessionLocal' imported but unused

(F401)


[error] 5-5: 'app.models.models.User' imported but unused

(F401)


[error] 5-5: 'app.models.models.AudienceInsights' imported but unused

(F401)


[error] 5-5: 'app.models.models.Sponsorship' imported but unused

(F401)


[error] 5-5: 'app.models.models.UserPost' imported but unused

(F401)


[error] 5-5: 'app.models.models.SponsorshipApplication' imported but unused

(F401)


[error] 5-5: 'app.models.models.SponsorshipPayment' imported but unused

(F401)


[error] 5-5: 'app.models.models.Collaboration' imported but unused

(F401)

πŸ€– Prompt for AI Agents
In Backend/app/routes/post.py from lines 4 to 12, remove all unused imports
related to SQLAlchemy including AsyncSessionLocal and the imported models User,
AudienceInsights, Sponsorship, UserPost, SponsorshipApplication,
SponsorshipPayment, Collaboration, as well as any unused schema imports on lines
9 to 12. This cleanup is necessary because the file uses Supabase for database
operations and does not require these SQLAlchemy ORM imports.

Expand All @@ -20,21 +20,30 @@

# Load environment variables
load_dotenv()
url: str = os.getenv("SUPABASE_URL")
key: str = os.getenv("SUPABASE_KEY")
url = os.getenv("SUPABASE_URL")
key = os.getenv("SUPABASE_KEY")
if url is None:
raise RuntimeError("SUPABASE_URL environment variable is not set")
if key is None:
raise RuntimeError("SUPABASE_KEY environment variable is not set")
supabase: Client = create_client(url, key)

# Define Router
router = APIRouter()

# Helper Functions


def generate_uuid():
return str(uuid.uuid4())


def current_timestamp():
return datetime.now(timezone.utc).isoformat()

# ========== USER ROUTES ==========


@router.post("/users/")
async def create_user(user: UserCreate):
user_id = generate_uuid()
Expand All @@ -53,12 +62,15 @@ async def create_user(user: UserCreate):

return response


@router.get("/users/")
async def get_users():
result = supabase.table("users").select("*").execute()
return result

# ========== AUDIENCE INSIGHTS ROUTES ==========


@router.post("/audience-insights/")
async def create_audience_insights(insights: AudienceInsightsCreate):
insight_id = generate_uuid()
Expand All @@ -78,12 +90,15 @@ async def create_audience_insights(insights: AudienceInsightsCreate):

return response


@router.get("/audience-insights/")
async def get_audience_insights():
result = supabase.table("audience_insights").select("*").execute()
return result

# ========== SPONSORSHIP ROUTES ==========


@router.post("/sponsorships/")
async def create_sponsorship(sponsorship: SponsorshipCreate):
sponsorship_id = generate_uuid()
Expand All @@ -103,12 +118,15 @@ async def create_sponsorship(sponsorship: SponsorshipCreate):

return response


@router.get("/sponsorships/")
async def get_sponsorships():
result = supabase.table("sponsorships").select("*").execute()
return result

# ========== USER POST ROUTES ==========


@router.post("/posts/")
async def create_post(post: UserPostCreate):
post_id = generate_uuid()
Expand All @@ -127,12 +145,15 @@ async def create_post(post: UserPostCreate):

return response


@router.get("/posts/")
async def get_posts():
result = supabase.table("user_posts").select("*").execute()
return result

# ========== SPONSORSHIP APPLICATION ROUTES ==========


@router.post("/sponsorship-applications/")
async def create_sponsorship_application(application: SponsorshipApplicationCreate):
application_id = generate_uuid()
Expand All @@ -150,12 +171,15 @@ async def create_sponsorship_application(application: SponsorshipApplicationCrea

return response


@router.get("/sponsorship-applications/")
async def get_sponsorship_applications():
result = supabase.table("sponsorship_applications").select("*").execute()
return result

# ========== SPONSORSHIP PAYMENT ROUTES ==========


@router.post("/sponsorship-payments/")
async def create_sponsorship_payment(payment: SponsorshipPaymentCreate):
payment_id = generate_uuid()
Expand All @@ -172,12 +196,15 @@ async def create_sponsorship_payment(payment: SponsorshipPaymentCreate):

return response


@router.get("/sponsorship-payments/")
async def get_sponsorship_payments():
result = supabase.table("sponsorship_payments").select("*").execute()
return result

# ========== COLLABORATION ROUTES ==========


@router.post("/collaborations/")
async def create_collaboration(collab: CollaborationCreate):
collaboration_id = generate_uuid()
Expand All @@ -194,6 +221,7 @@ async def create_collaboration(collab: CollaborationCreate):

return response


@router.get("/collaborations/")
async def get_collaborations():
result = supabase.table("collaborations").select("*").execute()
Expand Down
4 changes: 2 additions & 2 deletions Backend/app/services/chat_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.sql import select
from datetime import datetime, timezone
from models.models import User
from models.chat import ChatList, ChatMessage, MessageStatus
from app.models.models import User
from app.models.chat import ChatList, ChatMessage, MessageStatus
from typing import Dict
from redis.asyncio import Redis
import logging
Expand Down
Loading