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
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from fastapi_startkit.inertia import Inertia
from app.models.User import User


async def create():
return Inertia.render('Auth/Login', {})
return Inertia.render("Auth/Login", {})


async def store(request: Request):
form = await request.json()
Expand All @@ -16,9 +18,11 @@ async def store(request: Request):
request.session["user_id"] = user.id
return RedirectResponse(url="/", status_code=303)

return Inertia.render('Auth/Login', {
'errors': {'email': 'These credentials do not match our records.'}
})
return Inertia.render(
"Auth/Login",
{"errors": {"email": "These credentials do not match our records."}},
)


async def destroy(request: Request):
request.session.clear()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,58 @@
from fastapi import Depends
from fastapi.responses import RedirectResponse
from fastapi_startkit.inertia import Inertia
from app.http.requests.contact import ContactListRequest, ContactStoreRequest, ContactUpdateRequest
from app.http.requests.contact import (
ContactListRequest,
ContactStoreRequest,
ContactUpdateRequest,
)
from app.models.Contact import Contact
from app.models.Organization import Organization


async def index(filters: ContactListRequest = Depends()):
paginator = await (
Contact.query()
.when(filters.search, lambda q: q.where('first_name', 'like', f'%{filters.search}%').or_where('last_name', 'like', f'%{filters.search}%'))
.when(
filters.search,
lambda q: q.where("first_name", "like", f"%{filters.search}%").or_where(
"last_name", "like", f"%{filters.search}%"
),
)
.paginate(page=filters.page, per_page=filters.limit)
)

return Inertia.render('Contacts/Index', {
'data': [
{
'id': c.id,
'name': f"{c.first_name} {c.last_name}",
'organization_id': c.organization_id,
'organization': None,
'city': c.city,
'phone': c.phone,
'deleted_at': None,
} for c in paginator.result
],
'meta': {
'current_page': paginator.current_page,
'last_page': paginator.last_page,
'per_page': paginator.per_page,
'total': paginator.total,
return Inertia.render(
"Contacts/Index",
{
"data": [
{
"id": c.id,
"name": f"{c.first_name} {c.last_name}",
"organization_id": c.organization_id,
"organization": None,
"city": c.city,
"phone": c.phone,
"deleted_at": None,
}
for c in paginator.result
],
"meta": {
"current_page": paginator.current_page,
"last_page": paginator.last_page,
"per_page": paginator.per_page,
"total": paginator.total,
},
},
})
)


async def create():
organizations = await Organization.query().limit(100).get()
return Inertia.render('Contacts/Create', {
'organizations': [
{'id': o.id, 'name': o.name} for o in organizations
]
})
return Inertia.render(
"Contacts/Create",
{"organizations": [{"id": o.id, "name": o.name} for o in organizations]},
)


async def store(form: ContactStoreRequest):
Expand All @@ -51,25 +63,26 @@ async def store(form: ContactStoreRequest):
async def edit(contact: str):
c = await Contact.find(contact)
organizations = await Organization.query().limit(100).get()
return Inertia.render('Contacts/Edit', {
'contact': {
'id': c.id,
'first_name': c.first_name,
'last_name': c.last_name,
'organization_id': c.organization_id,
'email': c.email,
'phone': c.phone,
'address': c.address,
'city': c.city,
'region': c.region,
'country': c.country,
'postal_code': c.postal_code,
'deleted_at': None,
return Inertia.render(
"Contacts/Edit",
{
"contact": {
"id": c.id,
"first_name": c.first_name,
"last_name": c.last_name,
"organization_id": c.organization_id,
"email": c.email,
"phone": c.phone,
"address": c.address,
"city": c.city,
"region": c.region,
"country": c.country,
"postal_code": c.postal_code,
"deleted_at": None,
},
"organizations": [{"id": o.id, "name": o.name} for o in organizations],
},
'organizations': [
{'id': o.id, 'name': o.name} for o in organizations
]
})
)


async def update(form: ContactUpdateRequest, contact: str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


async def index():
return Inertia.render('Dashboard/Index')
return Inertia.render("Dashboard/Index")
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fastapi_startkit.storage import Storage


async def stream(path: str):
"""Stream a file from S3 back to the client."""
return Storage.disk("s3").stream(path)
Original file line number Diff line number Diff line change
Expand Up @@ -10,60 +10,72 @@
async def index(filters: OrganizationListRequest = Depends()):
paginator = await (
Organization.query()
.when(filters.search, lambda q: q.where('name', 'like', f'%{filters.search}%'))
.when(filters.search, lambda q: q.where("name", "like", f"%{filters.search}%"))
.paginate(page=filters.page, per_page=filters.limit)
)

return Inertia.render('Organizations/Index', {
'data': [
{
'id': org.id,
'name': org.name,
'phone': org.phone,
'city': org.city,
'deleted_at': None,
} for org in paginator.result
],
'meta': {
'current_page': paginator.current_page,
'last_page': paginator.last_page,
'per_page': paginator.per_page,
'total': paginator.total,
return Inertia.render(
"Organizations/Index",
{
"data": [
{
"id": org.id,
"name": org.name,
"phone": org.phone,
"city": org.city,
"deleted_at": None,
}
for org in paginator.result
],
"meta": {
"current_page": paginator.current_page,
"last_page": paginator.last_page,
"per_page": paginator.per_page,
"total": paginator.total,
},
},
})
)


async def create():
return Inertia.render('Organizations/Create')
return Inertia.render("Organizations/Create")


async def store(request: Request):
form = await request.json()
form["account_id"] = 1 # hardcoded for demo
form["account_id"] = 1 # hardcoded for demo
await Organization.create(form)
return RedirectResponse(url="/organizations", status_code=303)


async def edit(organization: str):
org = await Organization.find(organization)
return Inertia.render('Organizations/Edit', {
'organization': {
'id': org.id,
'name': org.name,
'email': org.email,
'phone': org.phone,
'address': org.address,
'city': org.city,
'region': org.region,
'country': org.country,
'postal_code': org.postal_code,
'deleted_at': None,
}
})
return Inertia.render(
"Organizations/Edit",
{
"organization": {
"id": org.id,
"name": org.name,
"email": org.email,
"phone": org.phone,
"address": org.address,
"city": org.city,
"region": org.region,
"country": org.country,
"postal_code": org.postal_code,
"deleted_at": None,
}
},
)


async def update(request: Request, organization: str):
org = await Organization.find(organization)
form = await request.json()
await org.update(form)
return RedirectResponse(url=f"/organizations/{organization}/edit", status_code=303)


async def destroy(organization: str):
org = await Organization.find(organization)
await org.delete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ async def save_photo(photo: Optional[UploadFile]) -> Optional[str]:
async def edit(request: Request):
user = await User.find(request.state.user["id"])
photo_url = f"/images/{user.photo_path}" if user.photo_path else None
return Inertia.render('Profile/Edit', {
'user': {
'id': user.id,
'first_name': user.first_name,
'last_name': user.last_name,
'email': user.email,
'photo': photo_url,
'password': '',
}
})
return Inertia.render(
"Profile/Edit",
{
"user": {
"id": user.id,
"first_name": user.first_name,
"last_name": user.last_name,
"email": user.email,
"photo": photo_url,
"password": "",
}
},
)


async def update(
Expand All @@ -48,7 +51,7 @@ async def update(

update_data = form.validated()
if photo_path:
update_data['photo_path'] = photo_path
update_data["photo_path"] = photo_path

await user.update(update_data)
return RedirectResponse(url="/profile", status_code=303)
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


async def index():
return Inertia.render('Reports/Index', {})
return Inertia.render("Reports/Index", {})
Loading
Loading