Skip to content

Commit

Permalink
feat: added models
Browse files Browse the repository at this point in the history
  • Loading branch information
whiteyebrw committed Dec 7, 2024
1 parent 88f1df1 commit dc6114b
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
Empty file.
4 changes: 4 additions & 0 deletions packages/backend/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import uvicorn

if __name__ == "__main__":
uvicorn.run("server.app:app", host="0.0.0.0", port=8000, reload=True)
25 changes: 25 additions & 0 deletions packages/backend/app/server/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from server.routes.routes import router

app = FastAPI()

origins = [
"*",
]

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

app.include_router(router)


@app.get("/", tags=["Root"])
async def read_root():
return {"message": "Welcome to this fantastic app!"}
100 changes: 100 additions & 0 deletions packages/backend/app/server/models/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from typing import List, Optional
from pydantic import BaseModel, EmailStr, Field
from datetime import datetime
from bson import ObjectId


class PyObjectId(ObjectId):
@classmethod
def __get_validators__(cls):
yield cls.validate

@classmethod
def validate(cls, v):
if not ObjectId.is_valid(v):
raise ValueError("Invalid ObjectId")
return ObjectId(v)

@classmethod
def __modify_schema__(cls, field_schema):
field_schema.update(type="string")


class MongoModel(BaseModel):
id: Optional[PyObjectId] = Field(default_factory=PyObjectId, alias="_id")

class Config:
allow_population_by_field_name = True
arbitrary_types_allowed = True
json_encoders = {ObjectId: str}


class MeetingDetail(BaseModel):
id: PyObjectId
time: datetime
psychologist_id: PyObjectId
status: str


class User(MongoModel):
mail: EmailStr
password: str
sex: str
birth_date: datetime
name: str
surname: str
phone_number: str
meetings: List[MeetingDetail] = []
reviews: List[PyObjectId] = []
transactions: List[PyObjectId] = []


class Education(BaseModel):
institution: str
degree: str
year_graduated: datetime


class WorkExperience(BaseModel):
position: str
place: str
years: List[datetime]


class Psychologist(MongoModel):
user: User
price: float
address: str
meeting_format: str
education: List[Education]
work_experience: List[WorkExperience]
language: str
articles: List[PyObjectId] = []


class Meeting(MongoModel):
time: datetime
user_id: PyObjectId
psychologist_id: PyObjectId
status: str # scheduled | completed | canceled


class Review(MongoModel):
content: str
user_id: PyObjectId
psychologist_id: PyObjectId
created_at: datetime
rating: float


class Article(MongoModel):
content: str
psychologist_id: PyObjectId
created_at: datetime
updated_at: datetime


class Transaction(MongoModel):
user_id: PyObjectId
amount: float
created_at: datetime
3 changes: 3 additions & 0 deletions packages/backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fastapi==0.115.6
uvicorn==0.32.1
motor==3.6.0

0 comments on commit dc6114b

Please sign in to comment.