Feat/add image users table#968
Open
gunnarvelle wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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_editorsand backfilling it from existingimagemetadataJSON. - Update
ImageRepositoryto write editor user IDs intoimage_editorson 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) |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Basert på tilsvarende funksjonalitet fra draft-api