Skip to content

Commit 9f4f8bf

Browse files
committed
feat: mark images as inactive
1 parent 4f64ae9 commit 9f4f8bf

24 files changed

+158
-52
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
update imagemetadata
2+
set metadata = jsonb_set(metadata, '{inactive}', 'false')
3+
where metadata->>'inactive' is null
4+
and metadata is not null;

image-api/src/main/scala/no/ndla/imageapi/controller/BaseImageController.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ trait BaseImageController(using
103103
query[Option[Boolean]]("podcast-friendly")
104104
.description("Filter images that are podcast friendly. Width==heigth and between 1400 and 3000.")
105105

106+
val inactive: EndpointInput.Query[Option[Boolean]] =
107+
query[Option[Boolean]]("inactive")
108+
.description("Include inactive images")
109+
106110
val maxImageFileSizeBytes: Int = props.MaxImageFileSizeBytes
107111

108112
def doWithStream[T](filePart: Part[File])(f: UploadedFile => Try[T]): Try[T] = {

image-api/src/main/scala/no/ndla/imageapi/controller/ImageControllerV2.scala

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ class ImageControllerV2(using
9595
podcastFriendly: Option[Boolean],
9696
shouldScroll: Boolean,
9797
modelReleasedStatus: Seq[ModelReleasedStatus.Value],
98-
user: Option[TokenUser]
98+
user: Option[TokenUser],
99+
inactive: Option[Boolean]
99100
) = {
100101
val settings = query match {
101102
case Some(searchString) =>
@@ -111,7 +112,8 @@ class ImageControllerV2(using
111112
podcastFriendly = podcastFriendly,
112113
shouldScroll = shouldScroll,
113114
modelReleased = modelReleasedStatus,
114-
userFilter = List.empty
115+
userFilter = List.empty,
116+
inactive = inactive
115117
)
116118
case None =>
117119
SearchSettings(
@@ -126,7 +128,8 @@ class ImageControllerV2(using
126128
podcastFriendly = podcastFriendly,
127129
shouldScroll = shouldScroll,
128130
modelReleased = modelReleasedStatus,
129-
userFilter = List.empty
131+
userFilter = List.empty,
132+
inactive = inactive
130133
)
131134
}
132135

@@ -153,6 +156,7 @@ class ImageControllerV2(using
153156
.in(podcastFriendly)
154157
.in(scrollId)
155158
.in(modelReleased)
159+
.in(inactive)
156160
.errorOut(errorOutputsFor(400))
157161
.out(jsonBody[SearchResultDTO])
158162
.out(EndpointOutput.derived[DynamicHeaders])
@@ -170,7 +174,8 @@ class ImageControllerV2(using
170174
pageSize,
171175
podcastFriendly,
172176
scrollId,
173-
modelReleased
177+
modelReleased,
178+
inactive
174179
) =>
175180
scrollSearchOr(scrollId, language, user) {
176181
val sort = Sort.valueOf(sortStr)
@@ -189,7 +194,8 @@ class ImageControllerV2(using
189194
podcastFriendly,
190195
shouldScroll,
191196
modelReleasedStatus,
192-
user
197+
user,
198+
inactive
193199
)
194200
}.handleErrorsOrOk
195201
}
@@ -216,6 +222,7 @@ class ImageControllerV2(using
216222
val podcastFriendly = searchParams.podcastFriendly
217223
val sort = searchParams.sort
218224
val shouldScroll = searchParams.scrollId.exists(props.InitialScrollContextKeywords.contains)
225+
val inactive = searchParams.inactive
219226
val modelReleasedStatus =
220227
searchParams.modelReleased.getOrElse(Seq.empty).flatMap(ModelReleasedStatus.valueOf)
221228

@@ -231,7 +238,8 @@ class ImageControllerV2(using
231238
podcastFriendly,
232239
shouldScroll,
233240
modelReleasedStatus,
234-
user
241+
user,
242+
inactive
235243
)
236244
}.handleErrorsOrOk
237245
})

image-api/src/main/scala/no/ndla/imageapi/controller/ImageControllerV3.scala

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class ImageControllerV3(using
8585
shouldScroll: Boolean,
8686
modelReleasedStatus: Seq[ModelReleasedStatus.Value],
8787
user: Option[TokenUser],
88-
userFilter: List[String]
88+
userFilter: List[String],
89+
inactive: Option[Boolean]
8990
) = {
9091
val settings = query match {
9192
case Some(searchString) =>
@@ -101,7 +102,8 @@ class ImageControllerV3(using
101102
podcastFriendly = podcastFriendly,
102103
shouldScroll = shouldScroll,
103104
modelReleased = modelReleasedStatus,
104-
userFilter = userFilter
105+
userFilter = userFilter,
106+
inactive = inactive
105107
)
106108
case None =>
107109
SearchSettings(
@@ -116,7 +118,8 @@ class ImageControllerV3(using
116118
podcastFriendly = podcastFriendly,
117119
shouldScroll = shouldScroll,
118120
modelReleased = modelReleasedStatus,
119-
userFilter = userFilter
121+
userFilter = userFilter,
122+
inactive = inactive
120123
)
121124
}
122125
for {
@@ -146,6 +149,7 @@ class ImageControllerV3(using
146149
.in(scrollId)
147150
.in(modelReleased)
148151
.in(userFilter)
152+
.in(inactive)
149153
.errorOut(errorOutputsFor(400))
150154
.out(jsonBody[SearchResultV3DTO])
151155
.out(EndpointOutput.derived[DynamicHeaders])
@@ -165,7 +169,8 @@ class ImageControllerV3(using
165169
podcastFriendly,
166170
scrollId,
167171
modelReleased,
168-
userFilter
172+
userFilter,
173+
inactive
169174
) =>
170175
scrollSearchOr(scrollId, language.code, user) {
171176
val sort = Sort.valueOf(sortStr)
@@ -186,7 +191,8 @@ class ImageControllerV3(using
186191
shouldScroll,
187192
modelReleasedStatus,
188193
user,
189-
userFilter.values
194+
userFilter.values,
195+
inactive
190196
)
191197
}.handleErrorsOrOk
192198
}
@@ -220,6 +226,7 @@ class ImageControllerV3(using
220226
val modelReleasedStatus =
221227
searchParams.modelReleased.getOrElse(Seq.empty).flatMap(ModelReleasedStatus.valueOf)
222228
val userFilter = searchParams.users.getOrElse(List.empty)
229+
val inactive = searchParams.inactive
223230

224231
searchV3(
225232
minimumSize,
@@ -234,7 +241,8 @@ class ImageControllerV3(using
234241
shouldScroll,
235242
modelReleasedStatus,
236243
user,
237-
userFilter
244+
userFilter,
245+
inactive
238246
)
239247
}.handleErrorsOrOk
240248
}

image-api/src/main/scala/no/ndla/imageapi/model/api/ImageMetaInformationV3DTO.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ case class ImageMetaInformationV3DTO(
4141
@description("Describes the changes made to the image, only visible to editors")
4242
editorNotes: Option[Seq[EditorNoteDTO]],
4343
@description("Describes the image file")
44-
image: ImageFileDTO
44+
image: ImageFileDTO,
45+
@description("Describes if the image is inactive or not")
46+
inactive: Boolean
4547
)
4648

4749
object ImageMetaInformationV3DTO {

image-api/src/main/scala/no/ndla/imageapi/model/api/ImageMetaSummaryDTO.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ case class ImageMetaSummaryDTO(
3030
@description("The time and date of last update") lastUpdated: NDLADate,
3131
@description("The size of the image in bytes") fileSize: Long,
3232
@description("The mimetype of the image") contentType: String,
33-
@description("Dimensions of the image") imageDimensions: Option[ImageDimensionsDTO]
33+
@description("Dimensions of the image") imageDimensions: Option[ImageDimensionsDTO],
34+
@description("Whether the image is inactive or not") inactive: Boolean
3435
)
3536

3637
object ImageMetaSummaryDTO {

image-api/src/main/scala/no/ndla/imageapi/model/api/SearchParamsDTO.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ case class SearchParamsDTO(
4040
podcastFriendly: Option[Boolean],
4141
@description("A search context retrieved from the response header of a previous search.")
4242
scrollId: Option[String],
43+
@description("Include inactive images")
44+
inactive: Option[Boolean],
4345
@description("Return only images with one of the provided values for modelReleased.")
4446
modelReleased: Option[Seq[String]],
4547
@description("Filter editors of the image(s). Multiple values can be specified in a comma separated list.")

image-api/src/main/scala/no/ndla/imageapi/model/api/UpdateImageMetaInformationDTO.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ case class UpdateImageMetaInformationDTO(
2121
@description("Describes the copyright information for the image") copyright: Option[CopyrightDTO],
2222
@description("Searchable tags for the image") tags: Option[Seq[String]],
2323
@description("Caption for the image") caption: Option[String],
24-
@description("Describes if the model has released use of the image") modelReleased: Option[String]
24+
@description("Describes if the model has released use of the image") modelReleased: Option[String],
25+
@description("Whether the image is inactive") inactive: Option[Boolean]
2526
)
2627

2728
object UpdateImageMetaInformationDTO {

image-api/src/main/scala/no/ndla/imageapi/model/domain/ImageMetaInformation.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ case class ImageMetaInformation(
2929
created: NDLADate,
3030
createdBy: String,
3131
modelReleased: ModelReleasedStatus.Value,
32-
editorNotes: Seq[EditorNote]
32+
editorNotes: Seq[EditorNote],
33+
inactive: Boolean
3334
)
3435

3536
object ImageMetaInformation extends SQLSyntaxSupport[ImageMetaInformation] {
@@ -60,7 +61,8 @@ object ImageMetaInformation extends SQLSyntaxSupport[ImageMetaInformation] {
6061
created = meta.created,
6162
createdBy = meta.createdBy,
6263
modelReleased = meta.modelReleased,
63-
editorNotes = meta.editorNotes
64+
editorNotes = meta.editorNotes,
65+
inactive = meta.inactive
6466
)
6567
}
6668
}

image-api/src/main/scala/no/ndla/imageapi/model/domain/SearchSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ case class SearchSettings(
2020
podcastFriendly: Option[Boolean],
2121
shouldScroll: Boolean,
2222
modelReleased: Seq[ModelReleasedStatus.Value],
23-
userFilter: List[String]
23+
userFilter: List[String],
24+
inactive: Option[Boolean]
2425
)

0 commit comments

Comments
 (0)