Skip to content

Feat/add image users table#968

Open
gunnarvelle wants to merge 5 commits into
masterfrom
feat/add-image-users-table
Open

Feat/add image users table#968
gunnarvelle wants to merge 5 commits into
masterfrom
feat/add-image-users-table

Conversation

@gunnarvelle
Copy link
Copy Markdown
Member

Basert på tilsvarende funksjonalitet fra draft-api

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds persistence and backfill for tracking which users have created/updated images (including editor note authors) via a new image_editors table, based on similar functionality in draft-api.

Changes:

  • Add DB migration creating image_editors and backfilling it from existing imagemetadata JSON.
  • Update ImageRepository to write editor user IDs into image_editors on insert/update, and clean up on delete.
  • Add an integration test asserting editors are tracked across insert/update/delete.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
image-api/src/main/scala/no/ndla/imageapi/repository/ImageRepository.scala Tracks editor user IDs on insert/update; adds getAllEditors; cleans image_editors on delete.
image-api/src/main/resources/no/ndla/imageapi/db/migration/V29__AddImageEditorsTable.sql Creates image_editors and backfills from createdBy, updatedBy, and editorNotes.updatedBy.
image-api/src/test/scala/no/ndla/imageapi/repository/ImageRepositoryTest.scala Extends DB cleanup and adds test coverage for editor tracking behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 43 to +54
def insert(imageMeta: ImageMetaInformation)(implicit
session: DBSession = dbUtility.autoSession
): Try[ImageMetaInformation] =
val dataObject = new PGobject()
dataObject.setType("jsonb")
dataObject.setValue(CirceUtil.toJsonString(imageMeta))

tsql"insert into imagemetadata(metadata) values ($dataObject)"
.updateAndReturnGeneratedKey()
.map(id => imageMeta.copy(id = Some(id)))
for {
id <- tsql"insert into imagemetadata(metadata) values ($dataObject)".updateAndReturnGeneratedKey()
inserted = imageMeta.copy(id = Some(id))
tracked <- trackEditors(inserted)
} yield tracked
Comment on lines 96 to +103
def delete(imageId: Long)(implicit session: DBSession = dbUtility.autoSession): Try[Int] = Try {
tsql"delete from imagemetadata where id = $imageId".update().get
}.flatMap {
case n if n < 1 =>
Failure(new ImageNotFoundException(s"Image with id $imageId was not found, and could not be deleted."))
case n => Success(n)
case n =>
val _ = tsql"delete from image_editors where image_id = $imageId".update().get
Success(n)
Comment thread image-api/src/test/scala/no/ndla/imageapi/repository/ImageRepositoryTest.scala Outdated
gunnarvelle and others added 3 commits May 21, 2026 14:46
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants