mane i done goofed up the initial commit
This commit is contained in:
parent
0400b224c2
commit
4a4cc244e0
198
main.py
198
main.py
|
@ -1,132 +1,66 @@
|
||||||
from fastapi import FastAPI, HTTPException
|
from fastapi import FastAPI, HTTPException
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from calls import register_user, authenticate_user, add_friend, send_match_invite, accept_match_invite
|
from calls import register_user, authenticate_user, add_friend, send_match_invite, accept_match_invite
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
class RegisterRequest(BaseModel):
|
class RegisterRequest(BaseModel):
|
||||||
email: str
|
email: str
|
||||||
display_name: str
|
display_name: str
|
||||||
password: str
|
password: str
|
||||||
|
|
||||||
class LoginRequest(BaseModel):
|
class LoginRequest(BaseModel):
|
||||||
email: str
|
email: str
|
||||||
password: str
|
password: str
|
||||||
|
|
||||||
class FriendRequest(BaseModel):
|
class FriendRequest(BaseModel):
|
||||||
user_uid: int
|
user_uid: int
|
||||||
friend_uid: int
|
friend_uid: int
|
||||||
|
|
||||||
class MatchInviteRequest(BaseModel):
|
class MatchInviteRequest(BaseModel):
|
||||||
sender_uid: int
|
sender_uid: int
|
||||||
receiver_uid: int
|
receiver_uid: int
|
||||||
|
|
||||||
class AcceptInviteRequest(BaseModel):
|
class AcceptInviteRequest(BaseModel):
|
||||||
match_id: int
|
match_id: int
|
||||||
player2_uid: int
|
player2_uid: int
|
||||||
|
|
||||||
@app.post("/register")
|
@app.post("/register")
|
||||||
def register(request: RegisterRequest):
|
def register(request: RegisterRequest):
|
||||||
try:
|
try:
|
||||||
uid = register_user(request.email, request.display_name, request.password)
|
uid = register_user(request.email, request.display_name, request.password)
|
||||||
return {"message": "User registered successfully", "uid": uid}
|
return {"message": "User registered successfully", "uid": uid}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=400, detail=str(e))
|
raise HTTPException(status_code=400, detail=str(e))
|
||||||
|
|
||||||
@app.post("/login")
|
@app.post("/login")
|
||||||
def login(request: LoginRequest):
|
def login(request: LoginRequest):
|
||||||
uid = authenticate_user(request.email, request.password)
|
uid = authenticate_user(request.email, request.password)
|
||||||
if uid:
|
if uid:
|
||||||
return {"message": "Login successful", "uid": uid}
|
return {"message": "Login successful", "uid": uid}
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=401, detail="Invalid credentials")
|
raise HTTPException(status_code=401, detail="Invalid credentials")
|
||||||
|
|
||||||
@app.post("/add_friend")
|
@app.post("/add_friend")
|
||||||
def add_friend_endpoint(request: FriendRequest):
|
def add_friend_endpoint(request: FriendRequest):
|
||||||
try:
|
try:
|
||||||
success = add_friend(request.user_uid, request.friend_uid)
|
success = add_friend(request.user_uid, request.friend_uid)
|
||||||
return {"message": "Friend added successfully"} if success else HTTPException(400, "Failed to add friend")
|
return {"message": "Friend added successfully"} if success else HTTPException(400, "Failed to add friend")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=400, detail=str(e))
|
raise HTTPException(status_code=400, detail=str(e))
|
||||||
|
|
||||||
@app.post("/send_match_invite")
|
@app.post("/send_match_invite")
|
||||||
def send_invite(request: MatchInviteRequest):
|
def send_invite(request: MatchInviteRequest):
|
||||||
try:
|
try:
|
||||||
match_id = send_match_invite(request.sender_uid, request.receiver_uid)
|
match_id = send_match_invite(request.sender_uid, request.receiver_uid)
|
||||||
return {"message": "Match invite sent successfully", "match_id": match_id}
|
return {"message": "Match invite sent successfully", "match_id": match_id}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=400, detail=str(e))
|
raise HTTPException(status_code=400, detail=str(e))
|
||||||
|
|
||||||
@app.post("/accept_match_invite")
|
@app.post("/accept_match_invite")
|
||||||
def accept_invite(request: AcceptInviteRequest):
|
def accept_invite(request: AcceptInviteRequest):
|
||||||
try:
|
try:
|
||||||
success = accept_match_invite(request.match_id, request.player2_uid)
|
success = accept_match_invite(request.match_id, request.player2_uid)
|
||||||
return {"message": "Match invite accepted"} if success else HTTPException(400, "Failed to accept invite")
|
return {"message": "Match invite accepted"} if success else HTTPException(400, "Failed to accept invite")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=400, detail=str(e))
|
raise HTTPException(status_code=400, detail=str(e))
|
||||||
from fastapi import FastAPI, HTTPException
|
|
||||||
from pydantic import BaseModel
|
|
||||||
from calls import register_user, authenticate_user, add_friend, send_match_invite, accept_match_invite
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
class RegisterRequest(BaseModel):
|
|
||||||
email: str
|
|
||||||
display_name: str
|
|
||||||
password: str
|
|
||||||
|
|
||||||
class LoginRequest(BaseModel):
|
|
||||||
email: str
|
|
||||||
password: str
|
|
||||||
|
|
||||||
class FriendRequest(BaseModel):
|
|
||||||
user_uid: int
|
|
||||||
friend_uid: int
|
|
||||||
|
|
||||||
class MatchInviteRequest(BaseModel):
|
|
||||||
sender_uid: int
|
|
||||||
receiver_uid: int
|
|
||||||
|
|
||||||
class AcceptInviteRequest(BaseModel):
|
|
||||||
match_id: int
|
|
||||||
player2_uid: int
|
|
||||||
|
|
||||||
@app.post("/register")
|
|
||||||
def register(request: RegisterRequest):
|
|
||||||
try:
|
|
||||||
uid = register_user(request.email, request.display_name, request.password)
|
|
||||||
return {"message": "User registered successfully", "uid": uid}
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(status_code=400, detail=str(e))
|
|
||||||
|
|
||||||
@app.post("/login")
|
|
||||||
def login(request: LoginRequest):
|
|
||||||
uid = authenticate_user(request.email, request.password)
|
|
||||||
if uid:
|
|
||||||
return {"message": "Login successful", "uid": uid}
|
|
||||||
else:
|
|
||||||
raise HTTPException(status_code=401, detail="Invalid credentials")
|
|
||||||
|
|
||||||
@app.post("/add_friend")
|
|
||||||
def add_friend_endpoint(request: FriendRequest):
|
|
||||||
try:
|
|
||||||
success = add_friend(request.user_uid, request.friend_uid)
|
|
||||||
return {"message": "Friend added successfully"} if success else HTTPException(400, "Failed to add friend")
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(status_code=400, detail=str(e))
|
|
||||||
|
|
||||||
@app.post("/send_match_invite")
|
|
||||||
def send_invite(request: MatchInviteRequest):
|
|
||||||
try:
|
|
||||||
match_id = send_match_invite(request.sender_uid, request.receiver_uid)
|
|
||||||
return {"message": "Match invite sent successfully", "match_id": match_id}
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(status_code=400, detail=str(e))
|
|
||||||
|
|
||||||
@app.post("/accept_match_invite")
|
|
||||||
def accept_invite(request: AcceptInviteRequest):
|
|
||||||
try:
|
|
||||||
success = accept_match_invite(request.match_id, request.player2_uid)
|
|
||||||
return {"message": "Match invite accepted"} if success else HTTPException(400, "Failed to accept invite")
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(status_code=400, detail=str(e))
|
|
Loading…
Reference in a new issue