Add inline block editing to schedule templates
- Backend: PATCH /api/schedules/{template_id}/blocks/{block_id} endpoint
- Frontend: Edit button on each block row expands an inline form
pre-filled with current subject, times, and label; saves via PATCH
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ from app.schemas.schedule import (
|
||||
ScheduleTemplateOut,
|
||||
ScheduleTemplateUpdate,
|
||||
ScheduleBlockCreate,
|
||||
ScheduleBlockUpdate,
|
||||
ScheduleBlockOut,
|
||||
)
|
||||
|
||||
@@ -144,6 +145,34 @@ async def add_block(
|
||||
return block
|
||||
|
||||
|
||||
@router.patch("/{template_id}/blocks/{block_id}", response_model=ScheduleBlockOut)
|
||||
async def update_block(
|
||||
template_id: int,
|
||||
block_id: int,
|
||||
body: ScheduleBlockUpdate,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
result = await db.execute(
|
||||
select(ScheduleBlock)
|
||||
.join(ScheduleTemplate)
|
||||
.where(
|
||||
ScheduleBlock.id == block_id,
|
||||
ScheduleBlock.template_id == template_id,
|
||||
ScheduleTemplate.user_id == current_user.id,
|
||||
)
|
||||
)
|
||||
block = result.scalar_one_or_none()
|
||||
if not block:
|
||||
raise HTTPException(status_code=404, detail="Block not found")
|
||||
|
||||
for field, value in body.model_dump(exclude_unset=True).items():
|
||||
setattr(block, field, value)
|
||||
await db.commit()
|
||||
await db.refresh(block)
|
||||
return block
|
||||
|
||||
|
||||
@router.delete("/{template_id}/blocks/{block_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def delete_block(
|
||||
template_id: int,
|
||||
|
||||
@@ -11,6 +11,15 @@ class ScheduleBlockCreate(BaseModel):
|
||||
order_index: int = 0
|
||||
|
||||
|
||||
class ScheduleBlockUpdate(BaseModel):
|
||||
subject_id: int | None = None
|
||||
time_start: time | None = None
|
||||
time_end: time | None = None
|
||||
label: str | None = None
|
||||
notes: str | None = None
|
||||
order_index: int | None = None
|
||||
|
||||
|
||||
class ScheduleBlockOut(BaseModel):
|
||||
id: int
|
||||
subject_id: int | None
|
||||
|
||||
Reference in New Issue
Block a user