Skip to content
Open
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
25 changes: 24 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,38 @@
app = FastAPI()


IMPORTANT_PEOPLE = ["Boss", "Ned Stark", "Robert Baratheon", "Jaime Lannister"]


def add_to_destination_list(values: list[str], default=["Boss"]):
to = default
for value in values:
if value not in default:
to.append(value)
return to


@app.post("/generate_message", status_code=status.HTTP_202_ACCEPTED)
async def generate_message(
destination: list[str] = Body(),
message: str = Body("Hello World"),
include_important_people: bool = False,
) -> str:
"""
Generate a message that will be sent to all the people in the destination list.
- **destination**: A list of people that should receive the message.
- **message**: The content of the message that will be sent.
- **include_important_people**: Whether to include important people in the destination list, default `False`.
"""
return {"message": message, "destination": ["Boss"] + destination}
if len(message) <= 10:
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail="Message should be at least 10 characters long.",
)

if include_important_people:
destination = add_to_destination_list(destination, default=IMPORTANT_PEOPLE)
else:
destination = add_to_destination_list(destination)

return {"message": message, "destination": destination}