diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/controller/TeamController.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/controller/TeamController.kt index 16f9950..c8a8182 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/controller/TeamController.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/controller/TeamController.kt @@ -70,7 +70,7 @@ class TeamController(private val teamService: TeamService, private val photoServ @PathVariable teamId: TeamId, @PathVariable itemId: ItemId, @PathVariable photoId: PhotoId): ResponseEntity { - TODO("Get photo information for the specified Team, Hunt, Item, and Photo") + TODO("Get photo information for the specified Team, Hunt, Item, and Photo. Join on the Hunter table to get the Hunter name. Also verify that the requesting user is either an admin or is on the same Hunt and Team as the Hunter who submitted the Photo") } @GetMapping("/{teamId}/item/{itemId}/photo/{photoId}/file") @@ -88,8 +88,8 @@ class TeamController(private val teamService: TeamService, private val photoServ @PathVariable teamId: TeamId, @PathVariable itemId: ItemId, authentication: Authentication, - @RequestParam file: MultipartFile): ResponseEntity { - return ResponseEntity.ok(photoService.submitPhoto(huntId, itemId, authentication.name, file).toResponse()) + @RequestParam file: MultipartFile) { + photoService.submitPhoto(huntId, itemId, authentication.name, file) } } \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/converter/PhotoConverter.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/converter/PhotoConverter.kt index da95fea..7d922a3 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/converter/PhotoConverter.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/converter/PhotoConverter.kt @@ -1,5 +1,6 @@ package net.halfbinary.scavengerhuntapi.model.converter +import net.halfbinary.scavengerhuntapi.model.domain.Hunter import net.halfbinary.scavengerhuntapi.model.domain.Photo import net.halfbinary.scavengerhuntapi.model.record.PhotoRecord import net.halfbinary.scavengerhuntapi.model.response.PhotoResponse @@ -14,9 +15,9 @@ fun Photo.toRecord() = PhotoRecord( statusChangeDateTime = statusChangeDateTime ) -fun Photo.toResponse() = PhotoResponse( +fun Photo.toResponse(hunter: Hunter) = PhotoResponse( id = id, - hunterId = hunterId, + hunterName = hunter.name, photoUploadDateTime = foundDateTime, photoStatus = status, photoStatusChangeDateTime = statusChangeDateTime diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/response/PhotoResponse.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/response/PhotoResponse.kt index 16404cf..6301f2d 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/response/PhotoResponse.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/model/response/PhotoResponse.kt @@ -1,13 +1,12 @@ package net.halfbinary.scavengerhuntapi.model.response -import net.halfbinary.scavengerhuntapi.model.HunterId import net.halfbinary.scavengerhuntapi.model.PhotoId import net.halfbinary.scavengerhuntapi.model.PhotoStatus import java.time.LocalDateTime data class PhotoResponse( val id: PhotoId, - val hunterId: HunterId, + val hunterName: String, val photoUploadDateTime: LocalDateTime, val photoStatus: PhotoStatus, val photoStatusChangeDateTime: LocalDateTime, diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/PhotoService.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/PhotoService.kt index e7a2d09..d33232f 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/PhotoService.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/service/PhotoService.kt @@ -23,7 +23,7 @@ class PhotoService( private val s3StorageService: S3StorageService, private val fileProbeService: FileProbeService ) { - fun submitPhoto(huntId: HuntId, itemId: ItemId, email: String, file: MultipartFile): Photo { + fun submitPhoto(huntId: HuntId, itemId: ItemId, email: String, file: MultipartFile) { val originalBytes = file.bytes val fileType = fileProbeService.getFileType(originalBytes) @@ -48,14 +48,10 @@ class PhotoService( val savedRecord = photoRepository.save(photo.toRecord()) val baseName = savedRecord.id.toString() - - - s3StorageService.upload("$baseName${fileProbeService.getFileExtension(fileType)}", originalBytes, fileType) - s3StorageService.upload("${baseName}_large.jpg", originalAsJpeg, MediaType.IMAGE_JPEG_VALUE) - s3StorageService.upload("${baseName}_medium.jpg", resize(originalBytes, 800), MediaType.IMAGE_JPEG_VALUE) - s3StorageService.upload("${baseName}_small.jpg", resize(originalBytes, 200), MediaType.IMAGE_JPEG_VALUE) - - return photo + s3StorageService.upload("$baseName${fileProbeService.getFileExtension(fileType)}", originalBytes, fileType) + s3StorageService.upload("${baseName}_large.jpg", originalAsJpeg, MediaType.IMAGE_JPEG_VALUE) + s3StorageService.upload("${baseName}_medium.jpg", resize(originalBytes, 800), MediaType.IMAGE_JPEG_VALUE) + s3StorageService.upload("${baseName}_small.jpg", resize(originalBytes, 200), MediaType.IMAGE_JPEG_VALUE) } private fun toJpeg(bytes: ByteArray): ByteArray {