Skip to content

Commit

Permalink
FEAT: admin에서 지급할 아이템 조회 기능
Browse files Browse the repository at this point in the history
  • Loading branch information
saewoo1 committed Oct 25, 2024
1 parent 059d11b commit 307f533
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package org.ftclub.cabinet.admin.item.controller;

import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.mapping;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.ftclub.cabinet.admin.dto.AdminCoinAssignRequestDto;
import org.ftclub.cabinet.admin.dto.AdminItemHistoryPaginationDto;
Expand All @@ -8,7 +14,14 @@
import org.ftclub.cabinet.auth.domain.AuthLevel;
import org.ftclub.cabinet.dto.ItemAssignRequestDto;
import org.ftclub.cabinet.dto.ItemCreateDto;
import org.ftclub.cabinet.dto.ItemDetailsDto;
import org.ftclub.cabinet.dto.ItemStoreDto;
import org.ftclub.cabinet.dto.ItemStoreResponseDto;
import org.ftclub.cabinet.item.domain.Item;
import org.ftclub.cabinet.item.domain.ItemType;
import org.ftclub.cabinet.item.service.ItemQueryService;
import org.ftclub.cabinet.log.Logging;
import org.ftclub.cabinet.mapper.ItemMapper;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -24,6 +37,8 @@
public class AdminItemController {

private final AdminItemFacadeService adminItemFacadeService;
private final ItemQueryService itemQueryService;
private final ItemMapper itemMapper;

@PostMapping("")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
Expand All @@ -32,6 +47,24 @@ public void createItem(@RequestBody ItemCreateDto itemCreateDto) {
itemCreateDto.getSku(), itemCreateDto.getType());
}

@GetMapping("")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public ItemStoreResponseDto getAllItems() {
List<Item> allItems = itemQueryService.getAllItems();
Map<ItemType, List<ItemDetailsDto>> itemMap = allItems.stream()
.collect(groupingBy(Item::getType,
mapping(itemMapper::toItemDetailsDto, Collectors.toList())));
List<ItemStoreDto> result = itemMap.entrySet().stream()
.map(entry -> {
ItemStoreDto itemStoreDto = itemMapper.toItemStoreDto(entry.getKey(),
entry.getValue());
itemStoreDto.sortBySkuASC();
return itemStoreDto;
})
.collect(Collectors.toList());
return new ItemStoreResponseDto(result);
}

@PostMapping("/assign")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void assignItem(@RequestBody ItemAssignRequestDto itemAssignRequestDto) {
Expand Down

0 comments on commit 307f533

Please sign in to comment.