package net.halfbinary.scavengerhuntapi.controller import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import jakarta.validation.Valid import net.halfbinary.scavengerhuntapi.model.HuntId import net.halfbinary.scavengerhuntapi.model.ItemId import net.halfbinary.scavengerhuntapi.model.converter.toDomain import net.halfbinary.scavengerhuntapi.model.converter.toResponse import net.halfbinary.scavengerhuntapi.model.request.ItemRequest import net.halfbinary.scavengerhuntapi.model.response.ItemResponse import net.halfbinary.scavengerhuntapi.service.HuntService import org.springframework.http.ResponseEntity import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("hunt/{huntId}/item") class ItemController(private val huntService: HuntService) { @GetMapping fun getItemsForHunt(@PathVariable huntId: HuntId): ResponseEntity> { return ResponseEntity.ok(huntService.getItemsForHunt(huntId).map { it.toResponse() }) } @GetMapping("/{itemId}") fun getItem(@PathVariable huntId: HuntId, @PathVariable itemId: ItemId): ResponseEntity { TODO("Maybe not needed: Get detailed information about the specified Item for the specified Hunt") } @PreAuthorize("hasRole('ADMIN')") @Tag(name = "Admin") @PostMapping @Operation(summary = "Adds new Item to specified Hunt") fun addItemToHunt(@PathVariable huntId: HuntId, @Valid @RequestBody body: ItemRequest): ResponseEntity { return ResponseEntity.ok(huntService.addItemToHunt(huntId, body.toDomain()).toResponse()) } }