Remove comments
This commit is contained in:
Binary file not shown.
@@ -4,10 +4,10 @@ from pydantic import BaseModel
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
# Enable CORS for NestJS (or directly for React if you prefer)
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
|
# This setup is only for the purpose of the exam, this should be restricted in production
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["*"], # In production, restrict this to your NestJS server domain
|
allow_origins=["*"],
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
)
|
)
|
||||||
@@ -16,18 +16,60 @@ app.add_middleware(
|
|||||||
LEADS = [
|
LEADS = [
|
||||||
{"id": 1, "name": "Alex Rivera", "email": "alex@company.com"},
|
{"id": 1, "name": "Alex Rivera", "email": "alex@company.com"},
|
||||||
{"id": 2, "name": "Jordan Smith", "email": "jsmith@leads.io"},
|
{"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")
|
@app.get("/leads")
|
||||||
def get_leads():
|
def get_leads():
|
||||||
return {"leads": 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):
|
class FeedbackData(BaseModel):
|
||||||
status: str
|
status: str
|
||||||
reason: str
|
reason: str
|
||||||
|
|
||||||
@app.post("/leads/{lead_id}/feedback")
|
@app.post("/leads/{lead_id}/feedback")
|
||||||
def receive_feedback(lead_id: str, feedback: FeedbackData):
|
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}")
|
print(f"Received feedback for {lead_id}: {feedback.status}, {feedback.reason}")
|
||||||
return {"status": "success"}
|
return {"status": "success"}
|
||||||
@@ -13,7 +13,7 @@ export class LeadsService {
|
|||||||
private readonly PYTHON_API = 'http://localhost:8000';
|
private readonly PYTHON_API = 'http://localhost:8000';
|
||||||
|
|
||||||
async getAllLeads() {
|
async getAllLeads() {
|
||||||
const response = await axios.get(`${this.PYTHON_API}/leads`);
|
const response = await axios.get(`${this.PYTHON_API}/leads/ibm`);
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
import { LeadCard } from './components/LeadCard';
|
import { LeadCard } from './components/LeadCard';
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
|
|
||||||
// Define the shape of your lead for better type safety
|
|
||||||
interface Lead {
|
interface Lead {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -17,11 +16,9 @@ export default function Home() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchLeads = async () => {
|
const fetchLeads = async () => {
|
||||||
try {
|
try {
|
||||||
// Use the environment variable or hardcoded backend URL
|
|
||||||
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000'}/leads`);
|
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000'}/leads`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
// Assuming your NestJS/Python returns { leads: [...] }
|
|
||||||
setLeads(data.leads);
|
setLeads(data.leads);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch leads:", error);
|
console.error("Failed to fetch leads:", error);
|
||||||
|
|||||||
Reference in New Issue
Block a user