-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor cleanup, including fixing openapi validation error
- Loading branch information
Showing
10 changed files
with
6,883 additions
and
6,758 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
52 changes: 52 additions & 0 deletions
52
backend/src/main/kotlin/dev/dres/api/rest/handler/preview/PreviewImageTimelessHandler.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package dev.dres.api.rest.handler.preview | ||
|
||
import dev.dres.api.rest.types.status.ErrorStatusException | ||
import dev.dres.data.model.media.DbMediaItem | ||
import dev.dres.mgmt.cache.CacheManager | ||
import io.javalin.http.Context | ||
import io.javalin.openapi.* | ||
import jetbrains.exodus.database.TransientEntityStore | ||
import kotlinx.dnq.query.eq | ||
import kotlinx.dnq.query.firstOrNull | ||
import kotlinx.dnq.query.query | ||
|
||
/** | ||
* A general purpose, [AbstractPreviewHandler] that handles image previews for different [DbMediaItem]. | ||
* | ||
* [PreviewImageHandler] vs [PreviewImageTimelessHandler]: Optional path parameters are not allowed in OpenApi. | ||
* | ||
* @author Ralph Gasser and Loris Sauter | ||
* @version 1.1.0 | ||
*/ | ||
class PreviewImageTimelessHandler(store: TransientEntityStore, cache: CacheManager) : AbstractPreviewHandler(store, cache) { | ||
|
||
override val route: String = "preview/{mediaItemId}" | ||
@OpenApi( | ||
summary = "Returns a preview image from a media item.", | ||
path = "/api/v2/preview/{mediaItemId}", | ||
operationId = OpenApiOperation.AUTO_GENERATE, | ||
pathParams = [ | ||
OpenApiParam("mediaItemId", String::class, "Unique ID of the media item.", required = true, allowEmptyValue = false), | ||
], | ||
tags = ["Media"], | ||
responses = [ | ||
OpenApiResponse("200", [OpenApiContent(type = "image/jpeg")]), | ||
OpenApiResponse("202"), | ||
OpenApiResponse("400"), | ||
OpenApiResponse("404") | ||
], | ||
methods = [HttpMethod.GET] | ||
) | ||
override fun get(ctx: Context) { | ||
val params = ctx.pathParamMap() | ||
val mediaItemId = params["mediaItemId"] ?: throw ErrorStatusException(400, "Media item ID was not specified or is invalid.", ctx) | ||
this.store.transactional(true) { | ||
val item = DbMediaItem.query(DbMediaItem::id eq mediaItemId).firstOrNull() | ||
handlePreviewImageRequest(item, 0L, ctx) | ||
} | ||
} | ||
|
||
override fun doGet(ctx: Context): Any { | ||
throw UnsupportedOperationException("PreviewImageHandler::doGet() is not supported and should not be executed!") | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.