-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6aae00f
commit 1c87693
Showing
4 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
from sqlalchemy import Column, Integer, String | ||
from datetime import datetime | ||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime | ||
from sqlalchemy.orm import relationship | ||
from .database import Base | ||
|
||
class Item(Base): | ||
__tablename__ = "items" | ||
|
||
id = Column(Integer, primary_key=True, index=True) | ||
name = Column(String, index=True) | ||
description = Column(String) | ||
description = Column(String) | ||
|
||
class User(Base): | ||
__tablename__ = "users" | ||
|
||
id = Column(Integer, primary_key=True, index=True) | ||
username = Column(String, unique=True, index=True) | ||
|
||
meetings = relationship("Meeting", back_populates="user") | ||
|
||
class Meeting(Base): | ||
__tablename__ = "meetings" | ||
|
||
id = Column(Integer, primary_key=True, index=True) | ||
title = Column(String, index=True) | ||
description = Column(String) | ||
date = Column(DateTime) | ||
user_id = Column(Integer, ForeignKey("users.id")) | ||
|
||
user = relationship("User", back_populates="meetings") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from fastapi import APIRouter, Depends, HTTPException | ||
from sqlalchemy.orm import Session | ||
from typing import List | ||
|
||
from .. import schemas | ||
from ..database import get_db | ||
|
||
router = APIRouter() | ||
|
||
# User CRUD endpoints | ||
@router.post("/users/", response_model=schemas.User) | ||
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)): | ||
db_user = crud.get_user_by_username(db, username=user.username) | ||
if db_user: | ||
raise HTTPException(status_code=400, detail="Username already registered") | ||
return crud.create_user(db=db, user=user) | ||
|
||
@router.get("/users/", response_model=List[schemas.User]) | ||
def read_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): | ||
users = crud.get_users(db, skip=skip, limit=limit) | ||
return users | ||
|
||
@router.get("/users/{user_id}", response_model=schemas.UserWithMeetings) | ||
def read_user(user_id: int, db: Session = Depends(get_db)): | ||
db_user = crud.get_user(db, user_id=user_id) | ||
if db_user is None: | ||
raise HTTPException(status_code=404, detail="User not found") | ||
return db_user | ||
|
||
@router.put("/users/{user_id}", response_model=schemas.User) | ||
def update_user(user_id: int, user: schemas.UserCreate, db: Session = Depends(get_db)): | ||
db_user = crud.update_user(db, user_id=user_id, user=user) | ||
if db_user is None: | ||
raise HTTPException(status_code=404, detail="User not found") | ||
return db_user | ||
|
||
@router.delete("/users/{user_id}", response_model=schemas.User) | ||
def delete_user(user_id: int, db: Session = Depends(get_db)): | ||
db_user = crud.delete_user(db, user_id=user_id) | ||
if db_user is None: | ||
raise HTTPException(status_code=404, detail="User not found") | ||
return db_user | ||
|
||
# Meeting CRUD endpoints | ||
@router.post("/meetings/", response_model=schemas.Meeting) | ||
def create_meeting(meeting: schemas.MeetingCreate, db: Session = Depends(get_db)): | ||
return crud.create_meeting(db=db, meeting=meeting) | ||
|
||
@router.get("/meetings/", response_model=List[schemas.Meeting]) | ||
def read_meetings(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): | ||
meetings = crud.get_meetings(db, skip=skip, limit=limit) | ||
return meetings | ||
|
||
@router.get("/meetings/{meeting_id}", response_model=schemas.MeetingWithUser) | ||
def read_meeting(meeting_id: int, db: Session = Depends(get_db)): | ||
db_meeting = crud.get_meeting(db, meeting_id=meeting_id) | ||
if db_meeting is None: | ||
raise HTTPException(status_code=404, detail="Meeting not found") | ||
return db_meeting | ||
|
||
@router.put("/meetings/{meeting_id}", response_model=schemas.Meeting) | ||
def update_meeting(meeting_id: int, meeting: schemas.MeetingCreate, db: Session = Depends(get_db)): | ||
db_meeting = crud.update_meeting(db, meeting_id=meeting_id, meeting=meeting) | ||
if db_meeting is None: | ||
raise HTTPException(status_code=404, detail="Meeting not found") | ||
return db_meeting | ||
|
||
@router.delete("/meetings/{meeting_id}", response_model=schemas.Meeting) | ||
def delete_meeting(meeting_id: int, db: Session = Depends(get_db)): | ||
db_meeting = crud.delete_meeting(db, meeting_id=meeting_id) | ||
if db_meeting is None: | ||
raise HTTPException(status_code=404, detail="Meeting not found") | ||
return db_meeting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters