Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Item(
@Enumerated(EnumType.STRING)
val itemType: ItemType,
var count: Int = 0,
var lastGrantedAt: LocalDateTime = LocalDateTime.now(),
var lastGrantedAt: LocalDateTime? = null,
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import com.snackgame.server.game.snackgame.core.service.dto.ItemsResponse
import com.snackgame.server.game.snackgame.exception.ItemNotReadyException
import com.snackgame.server.game.snackgame.exception.NoItemException
import org.springframework.stereotype.Service
import java.time.LocalDateTime

import javax.transaction.Transactional

@Service
Expand All @@ -34,7 +32,6 @@ class ItemService(
}



@Transactional
fun useItem(ownerId: Long, itemType: ItemType) {
val found = itemRepository.findItemByOwnerIdAndItemType(ownerId, itemType)
Expand All @@ -43,17 +40,6 @@ class ItemService(
found.useOne()
itemRepository.save(found)
}

@Transactional
fun issueItem(ownerId: Long, itemType: ItemType) : ItemResponse {
val found = itemRepository.findItemByOwnerIdAndItemType(ownerId, itemType)
.orElse(Item(ownerId = ownerId, itemType = itemType, count = 0, LocalDateTime.now()))

found.count += 1
itemRepository.save(found)
return ItemResponse.of(found)
}


@Transactional
fun issueItem(ownerId: Long, itemType: ItemType, grantType: GrantType): ItemResponse {
Expand All @@ -64,7 +50,7 @@ class ItemService(
}

val found = itemRepository.findItemByOwnerIdAndItemType(ownerId, itemType)
.orElse(Item(ownerId = ownerId, itemType = itemType, count = 0, LocalDateTime.now()))
.orElse(Item(ownerId = ownerId, itemType = itemType, count = 0))

itemGrantHistories.save(ItemGrantHistory(ownerId, itemType, grantType))
found.addOne()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class ItemResponse(
val ownerId: Long,
val type: ItemType,
val count: Int,
val lastGrantedAt: LocalDateTime,
val lastGrantedAt: LocalDateTime? = null,
) {
companion object {
fun of(item: Item): ItemResponse {
Expand Down
Loading