75 lines
3.6 KiB
Python
75 lines
3.6 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from pydantic import BaseModel
|
|
|
|
app = FastAPI()
|
|
|
|
app.add_middleware(
|
|
# This setup is only for the purpose of the exam, this should be restricted in production
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Hardcoded Leads Data
|
|
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):
|
|
print(f"Received feedback for {lead_id}: {feedback.status}, {feedback.reason}")
|
|
return {"status": "success"} |