Adds update and delete item endpoints
This commit is contained in:
@@ -8,11 +8,14 @@ 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.request.ItemUpdateRequest
|
||||
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.DeleteMapping
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PatchMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
@@ -41,4 +44,21 @@ class ItemController(private val huntService: HuntService) {
|
||||
return ResponseEntity.ok(huntService.addItemToHunt(huntId, body.toDomain()).toResponse())
|
||||
}
|
||||
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
@Tag(name = "Admin")
|
||||
@PatchMapping("/{itemId}")
|
||||
@Operation(summary = "Updates name and/or points for the specified Item in the specified Hunt")
|
||||
fun updateItem(@PathVariable huntId: HuntId, @PathVariable itemId: ItemId, @RequestBody body: ItemUpdateRequest): ResponseEntity<ItemResponse> {
|
||||
return ResponseEntity.ok(huntService.updateItem(huntId, itemId, body).toResponse())
|
||||
}
|
||||
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
@Tag(name = "Admin")
|
||||
@DeleteMapping("/{itemId}")
|
||||
@Operation(summary = "Deletes the specified Item from the specified Hunt")
|
||||
fun deleteItem(@PathVariable huntId: HuntId, @PathVariable itemId: ItemId): ResponseEntity<Unit> {
|
||||
huntService.deleteItem(huntId, itemId)
|
||||
return ResponseEntity.noContent().build()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user