Skip to content
Merged
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
2 changes: 1 addition & 1 deletion backend/alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from logging.config import fileConfig

from alembic import context
from sqlalchemy import engine_from_config, pool

from alembic import context
from app.config import settings
from app.db.session import Base
from app.models import Note # noqa: F401 — ensures model is registered on metadata
Expand Down
11 changes: 9 additions & 2 deletions backend/alembic/versions/0001_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
Create Date: 2026-07-22

"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

from alembic import op

revision: str = "0001"
down_revision: str | None = None
branch_labels: str | Sequence[str] | None = None
Expand All @@ -22,7 +24,12 @@ def upgrade() -> None:
"notes",
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
sa.Column("text", sa.String(500), nullable=False),
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.func.now(),
nullable=False,
),
)
op.create_index("notes_created_at_idx", "notes", ["created_at"])

Expand Down
4 changes: 1 addition & 3 deletions backend/app/models/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
class Note(Base):
__tablename__ = "notes"

id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
)
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
text: Mapped[str] = mapped_column(String(500), nullable=False)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
Expand Down
9 changes: 6 additions & 3 deletions backend/app/routers/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import uuid
from datetime import datetime
from typing import Annotated

from fastapi import APIRouter, Depends, HTTPException, status
from pydantic import BaseModel, ConfigDict, Field
Expand All @@ -13,6 +14,8 @@

router = APIRouter(prefix="/api/notes", tags=["notes"])

SessionDep = Annotated[Session, Depends(get_session)]


class NoteOut(BaseModel):
model_config = ConfigDict(from_attributes=True)
Expand All @@ -27,13 +30,13 @@ class NoteIn(BaseModel):


@router.get("", response_model=list[NoteOut])
def list_notes(session: Session = Depends(get_session)) -> list[Note]:
def list_notes(session: SessionDep) -> list[Note]:
stmt = select(Note).order_by(Note.created_at.desc()).limit(100)
return list(session.scalars(stmt).all())


@router.post("", response_model=NoteOut, status_code=status.HTTP_201_CREATED)
def create_note(body: NoteIn, session: Session = Depends(get_session)) -> Note:
def create_note(body: NoteIn, session: SessionDep) -> Note:
note = Note(text=body.text.strip())
session.add(note)
session.commit()
Expand All @@ -42,7 +45,7 @@ def create_note(body: NoteIn, session: Session = Depends(get_session)) -> Note:


@router.delete("/{note_id}", status_code=status.HTTP_204_NO_CONTENT)
def delete_note(note_id: uuid.UUID, session: Session = Depends(get_session)) -> None:
def delete_note(note_id: uuid.UUID, session: SessionDep) -> None:
note = session.get(Note, note_id)
if note is None:
raise HTTPException(status.HTTP_404_NOT_FOUND, "note not found")
Expand Down
1,128 changes: 1,128 additions & 0 deletions backend/uv.lock

Large diffs are not rendered by default.

Loading
Loading