Skip to content

Commit d1dd903

Browse files
committed
Add last_updated field to PhotoGallery and bump on mutations
1 parent 5f1c8ac commit d1dd903

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

app/backend/src/couchers/models/uploads.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class PhotoGallery(Base, kw_only=True):
8080
owner_user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), index=True)
8181

8282
created: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), init=False)
83+
last_updated: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), init=False)
8384

8485
owner_user: Mapped[User] = relationship(init=False, foreign_keys=[owner_user_id], back_populates="galleries")
8586
photos: Mapped[list[PhotoGalleryItem]] = relationship(

app/backend/src/couchers/servicers/galleries.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def AddPhotoToGallery(
9696
caption=request.caption or None,
9797
)
9898
session.add(item)
99+
gallery.last_updated = func.now()
99100
session.flush()
100101
session.refresh(gallery)
101102

@@ -124,6 +125,7 @@ def RemovePhotoFromGallery(
124125
context.abort_with_error_code(grpc.StatusCode.NOT_FOUND, "gallery_item_not_found")
125126

126127
session.delete(item)
128+
gallery.last_updated = func.now()
127129
session.flush()
128130
session.refresh(gallery)
129131

@@ -184,6 +186,7 @@ def MovePhoto(
184186
session.execute(
185187
update(PhotoGalleryItem).where(PhotoGalleryItem.id == request.item_id).values(position=new_position)
186188
)
189+
gallery.last_updated = func.now()
187190

188191
session.flush()
189192
session.refresh(gallery)
@@ -213,6 +216,7 @@ def UpdatePhotoCaption(
213216
context.abort_with_error_code(grpc.StatusCode.NOT_FOUND, "gallery_item_not_found")
214217

215218
item.caption = request.caption or None
219+
gallery.last_updated = func.now()
216220
session.flush()
217221
session.refresh(gallery)
218222

0 commit comments

Comments
 (0)