-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
113 lines (86 loc) · 3.3 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from dotenv import dotenv_values
from models.News import News
from models.Stock import StockInstance
from models.User import User
from models.UserOrder import UserOrder
from models.UserStock import UserStock
from models.Notification import Notification, NotificationDto, NotificationReply
from newsGenerator import generate_random_article, reset_news
from userOrders import add_order, get_open_orders
from users import login, profile, reset_users
from stocks import burst_the_bubble, get_stock, get_stocks, get_user_stocks, reset_stocks, tick_stocks
from notifications import get_notifications, read_notification, reply_to_notification, create_notification
from scheduler import scheduler
# Load environment variables (including MongoDB Atlas connection string)
config = dotenv_values(".env")
ATLAS_URI = config["ATLAS_URI"]
GEMINI_API_KEY = config["GEMINI_API_KEY"]
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.on_event("startup")
def startup_event():
scheduler.start()
@app.on_event("shutdown")
def shutdown_event():
scheduler.shutdown()
#User endpoints
@app.get("/login/{email}", response_model=User)
def add_login_endpoint(email: str):
return login(email)
@app.get("/profile/{email}", response_model=User)
def get_profile_endpoint(email: str):
return profile(email)
@app.post("/users/reset")
def reset_all_users_endpoint():
return reset_users()
@app.post("/users/{email}/stocks", response_model=list[UserStock])
def get_user_stocks_endpoint(email: str):
return get_user_stocks(email)
@app.post("/notification/", response_model=Notification)
def create_notifications_endpoint(notif: NotificationDto):
return create_notification(notif)
@app.get("/notifications/{email}", response_model=list[Notification])
def get_notifications_endpoint(email: str):
return get_notifications(email)
@app.get("/notification/{id}/read", response_model=Notification)
def get_notification_read_endpoint(id: str):
return read_notification(id)
@app.post("/notification/{id}/reply", response_model=Notification)
def create_notification_reply_endpoint(id: str, reply: NotificationReply):
return reply_to_notification(id, reply)
#Stock endpoints
@app.get("/stocks/", response_model=list[StockInstance])
def get_stocks_endpoint():
return get_stocks()
@app.get("/stock/{symbol}", response_model=StockInstance)
def get_stock_endpoint(symbol: str):
return get_stock(symbol)
@app.post("/stocks/reset")
def reset_all_stocks_endpoint(stock: StockInstance):
return reset_stocks()
@app.post("/stocks/tick")
def tick_all_stocks_endpoint(stock: StockInstance):
return tick_stocks()
@app.get("/orders/{email}/open", response_model=list[UserOrder])
def get_open_orders_endpoint(email: str):
return get_open_orders(email)
@app.post("/orders/", response_model=UserOrder)
def create_user_order_endpoint(order: UserOrder):
return add_order(order)
@app.get("/pop/")
def pop_endpoint():
return burst_the_bubble()
@app.post("/news/reset")
def reset_all_news_endpoint():
return reset_news()
@app.get("/news/random", response_model=News)
def generate_random_news_endpoint():
return generate_random_article()