Remove comments
This commit is contained in:
Binary file not shown.
@@ -4,10 +4,10 @@ from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# Enable CORS for NestJS (or directly for React if you prefer)
|
||||
app.add_middleware(
|
||||
# This setup is only for the purpose of the exam, this should be restricted in production
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"], # In production, restrict this to your NestJS server domain
|
||||
allow_origins=["*"],
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
@@ -16,18 +16,60 @@ app.add_middleware(
|
||||
LEADS = [
|
||||
{"id": 1, "name": "Alex Rivera", "email": "alex@company.com"},
|
||||
{"id": 2, "name": "Jordan Smith", "email": "jsmith@leads.io"},
|
||||
{"id": 3, "name": "John Smith", "email": "johnsmith@ibm.com"},
|
||||
{"id": 4, "name": "Sarah Connor", "email": "sarah@techcorp.com"},
|
||||
{"id": 5, "name": "Marcus Wright", "email": "mwright@ibm.com"},
|
||||
{"id": 6, "name": "Elena Fisher", "email": "elena@naughty.com"},
|
||||
{"id": 7, "name": "Nathan Drake", "email": "drake@treasure.com"},
|
||||
{"id": 8, "name": "Alice Johnson", "email": "ajohnson@ibm.com"},
|
||||
{"id": 9, "name": "Bob Vance", "email": "bob@vancerefrig.com"},
|
||||
{"id": 10, "name": "Charlie Day", "email": "charlie@paddys.com"},
|
||||
{"id": 11, "name": "Diana Prince", "email": "diana@themyscira.gov"},
|
||||
{"id": 12, "name": "Edward Norton", "email": "edward@fightclub.com"},
|
||||
{"id": 13, "name": "Fiona Gallagher", "email": "fiona@southside.com"},
|
||||
{"id": 14, "name": "George Bluth", "email": "george@bananastand.com"},
|
||||
{"id": 15, "name": "Hannah Abbott", "email": "hannah@ibm.com"},
|
||||
{"id": 16, "name": "Ian Malcolm", "email": "chaos@jurassic.com"},
|
||||
{"id": 17, "name": "Jack Shephard", "email": "jack@oceanic.com"},
|
||||
{"id": 18, "name": "Karen Page", "email": "karen@nelsonmurdock.com"},
|
||||
{"id": 19, "name": "Luke Skywalker", "email": "luke@tatooine.com"},
|
||||
{"id": 20, "name": "Michael Scott", "email": "michael@dundermifflin.com"},
|
||||
{"id": 21, "name": "Nina Simone", "email": "nina@ibm.com"},
|
||||
{"id": 22, "name": "Oscar Martinez", "email": "oscar@accounting.com"},
|
||||
{"id": 23, "name": "Peter Parker", "email": "peter@dailybugle.com"},
|
||||
{"id": 24, "name": "Quinn Fabray", "email": "quinn@mckinley.edu"},
|
||||
{"id": 25, "name": "Riley Reid", "email": "riley@ibm.com"},
|
||||
{"id": 26, "name": "Sam Winchester", "email": "sam@hunters.com"},
|
||||
{"id": 27, "name": "Tina Fey", "email": "tina@30rock.com"},
|
||||
{"id": 28, "name": "Uma Thurman", "email": "uma@ibm.com"},
|
||||
{"id": 29, "name": "Victor Creed", "email": "victor@sabertooth.com"},
|
||||
{"id": 30, "name": "Walter White", "email": "walter@heisenberg.com"},
|
||||
{"id": 31, "name": "Alice Watson", "email": "alice.watson@ibm.com"},
|
||||
{"id": 32, "name": "Brian K. Vaughan", "email": "bvaughan@ibm.com"},
|
||||
{"id": 33, "name": "Catherine Zeta", "email": "czeta@ibm.com"},
|
||||
{"id": 34, "name": "David Chen", "email": "dchen@ibm.com"},
|
||||
{"id": 35, "name": "Eva Green", "email": "egreen@ibm.com"},
|
||||
{"id": 36, "name": "Franklin Roosevelt", "email": "froosevelt@ibm.com"},
|
||||
{"id": 37, "name": "Grace Hopper", "email": "ghopper@ibm.com"},
|
||||
{"id": 38, "name": "Henry Cavill", "email": "hcavill@ibm.com"},
|
||||
{"id": 39, "name": "Isabel Allende", "email": "iallend@ibm.com"},
|
||||
{"id": 40, "name": "Julian Assange", "email": "jassange@ibm.com"},
|
||||
]
|
||||
|
||||
@app.get("/leads")
|
||||
def get_leads():
|
||||
return {"leads": LEADS}
|
||||
|
||||
@app.get("/leads/ibm")
|
||||
def get_ibm_leads():
|
||||
ibm_leads = [lead for lead in LEADS if lead["email"].endswith("@ibm.com")]
|
||||
return {"leads": ibm_leads}
|
||||
|
||||
class FeedbackData(BaseModel):
|
||||
status: str
|
||||
reason: str
|
||||
|
||||
@app.post("/leads/{lead_id}/feedback")
|
||||
def receive_feedback(lead_id: str, feedback: FeedbackData):
|
||||
# Now FastAPI knows exactly what structure to look for
|
||||
print(f"Received feedback for {lead_id}: {feedback.status}, {feedback.reason}")
|
||||
return {"status": "success"}
|
||||
@@ -13,7 +13,7 @@ export class LeadsService {
|
||||
private readonly PYTHON_API = 'http://localhost:8000';
|
||||
|
||||
async getAllLeads() {
|
||||
const response = await axios.get(`${this.PYTHON_API}/leads`);
|
||||
const response = await axios.get(`${this.PYTHON_API}/leads/ibm`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { LeadCard } from './components/LeadCard';
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
// Define the shape of your lead for better type safety
|
||||
interface Lead {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -17,11 +16,9 @@ export default function Home() {
|
||||
useEffect(() => {
|
||||
const fetchLeads = async () => {
|
||||
try {
|
||||
// Use the environment variable or hardcoded backend URL
|
||||
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000'}/leads`);
|
||||
const data = await res.json();
|
||||
|
||||
// Assuming your NestJS/Python returns { leads: [...] }
|
||||
setLeads(data.leads);
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch leads:", error);
|
||||
|
||||
Reference in New Issue
Block a user