Adds image retrieval endpoint

This commit is contained in:
2026-05-14 14:29:52 -05:00
parent 63e015400b
commit aff0872e38
8 changed files with 121 additions and 11 deletions

View File

@@ -0,0 +1,29 @@
package net.halfbinary.scavengerhuntapi.controller
import io.swagger.v3.oas.annotations.Operation
import net.halfbinary.scavengerhuntapi.model.ImageVersion
import net.halfbinary.scavengerhuntapi.model.PhotoId
import net.halfbinary.scavengerhuntapi.service.PhotoService
import org.springframework.core.io.InputStreamSource
import org.springframework.http.ResponseEntity
import org.springframework.security.core.Authentication
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("photo")
class PhotoController(private val photoService: PhotoService) {
@GetMapping("/{photoId}/file")
@Operation(summary = "Get the binary image information for the specified Photo")
fun getPhoto(authentication: Authentication,
@PathVariable photoId: PhotoId,
@RequestParam(defaultValue = "LARGE") version: ImageVersion): ResponseEntity<InputStreamSource> {
val photoFile = photoService.getPhotoFile(photoId, authentication.name, version)
return ResponseEntity.ok()
.contentType(photoFile.contentType)
.body(photoFile.resource)
}
}