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 { val photoFile = photoService.getPhotoFile(photoId, authentication.name, version) return ResponseEntity.ok() .contentType(photoFile.contentType) .body(photoFile.resource) } }