Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 13 additions & 4 deletions app/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .auth import get_password_hash
from sqlalchemy import func


def get_user(db: Session, user_id: int):
return db.query(models.User).filter(models.User.id == user_id).first()

Expand Down Expand Up @@ -283,11 +284,19 @@ def get_user_reports_by_discord_id(db: Session, discord_username: str):
.all()[0]["Report"]
)

def add_reports_by_discord_id(db:Session, report: schemas.ReportDiscord, discord_username: str):
user_id = db.query(models.User).filter(models.User.discord_username == discord_username).first().id

def add_reports_by_discord_id(
db: Session, report: schemas.ReportDiscord, discord_username: str
):
user_id = (
db.query(models.User)
.filter(models.User.discord_username == discord_username)
.first()
.id
)
db_report = models.Report(**report.dict())
db_report.owner_id=user_id
db_report.owner_id = user_id
db.add(db_report)
db.commit()
db.refresh()
return {"message": "report succesfully added"}
return {"message": "report succesfully added"}
9 changes: 7 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ def update_discord_id(
def get_user_report_by_discord_id(discord_username: str, db: Session = Depends(get_db)):
return crud.get_user_reports_by_discord_id(db=db, discord_username=discord_username)


@app.post("/discord")
def add_report_by_discord_username(discord_username: str, report:schemas.ReportDiscord, db: Session = Depends(get_db)):
return crud.add_reports_by_discord_id(db=db, discord_username=discord_username, report=report)
def add_report_by_discord_username(
discord_username: str, report: schemas.ReportDiscord, db: Session = Depends(get_db)
):
return crud.add_reports_by_discord_id(
db=db, discord_username=discord_username, report=report
)
2 changes: 2 additions & 0 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Report(BaseModel):
class Config:
orm_mode = True


class ReportDiscord(BaseModel):
task_type: TaskEnum
title: str
Expand All @@ -103,6 +104,7 @@ class ReportDiscord(BaseModel):
class Config:
orm_mode = True


class ResetPasswordBase(BaseModel):
email: str
password: str
Expand Down