diff --git a/backend/database/cabi_local.sql b/backend/database/cabi_local.sql index 668508da5..cf1645be0 100644 --- a/backend/database/cabi_local.sql +++ b/backend/database/cabi_local.sql @@ -742,7 +742,8 @@ VALUES (1, 0, 'EXTENSION_PREV', 'EXTENSION'), (17, 200, 'ADMIN_REWARD_200', 'ADMIN_REWARD'), (18, 500, 'ADMIN_REWARD_500', 'ADMIN_REWARD'), (19, 1000, 'ADMIN_REWARD_1000', 'ADMIN_REWARD'), - (20, 2000, 'ADMIN_REWARD_2000', 'ADMIN_REWARD'); + (20, 2000, 'ADMIN_REWARD_2000', 'ADMIN_REWARD'), + (21, 10, 'ADMIN_REWARD_COIN', 'ADMIN_REWARD'); /*!40000 ALTER TABLE `item` ENABLE KEYS */; UNLOCK TABLES; @@ -758,6 +759,7 @@ CREATE TABLE `item_history` `user_id` bigint(20) NOT NULL, `purchase_at` datetime(6) NOT NULL, `used_at` datetime(6) DEFAULT NULL, + `amount` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`), CONSTRAINT `item_history_item_id` FOREIGN KEY (`item_id`) REFERENCES `item` (`id`), CONSTRAINT `item_history_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) diff --git a/backend/src/main/java/org/ftclub/cabinet/admin/dto/AdminCoinAssignRequestDto.java b/backend/src/main/java/org/ftclub/cabinet/admin/dto/AdminCoinAssignRequestDto.java new file mode 100644 index 000000000..beb456125 --- /dev/null +++ b/backend/src/main/java/org/ftclub/cabinet/admin/dto/AdminCoinAssignRequestDto.java @@ -0,0 +1,15 @@ +package org.ftclub.cabinet.admin.dto; + +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.ftclub.cabinet.item.domain.Sku; + +@Getter +@AllArgsConstructor +public class AdminCoinAssignRequestDto { + + private List userIds; + private Sku itemSku; + private Long amount; +} diff --git a/backend/src/main/java/org/ftclub/cabinet/admin/item/controller/AdminItemController.java b/backend/src/main/java/org/ftclub/cabinet/admin/item/controller/AdminItemController.java index f3932160e..46035ef85 100644 --- a/backend/src/main/java/org/ftclub/cabinet/admin/item/controller/AdminItemController.java +++ b/backend/src/main/java/org/ftclub/cabinet/admin/item/controller/AdminItemController.java @@ -1,14 +1,26 @@ 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.AdminItemHistoryPaginationDto; import org.ftclub.cabinet.admin.item.service.AdminItemFacadeService; -import org.ftclub.cabinet.admin.statistics.service.AdminStatisticsFacadeService; import org.ftclub.cabinet.auth.domain.AuthGuard; 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; @@ -24,8 +36,8 @@ public class AdminItemController { private final AdminItemFacadeService adminItemFacadeService; - private final AdminStatisticsFacadeService adminStatisticsFacadeService; - + private final ItemQueryService itemQueryService; + private final ItemMapper itemMapper; @PostMapping("") @AuthGuard(level = AuthLevel.ADMIN_ONLY) @@ -34,11 +46,29 @@ public void createItem(@RequestBody ItemCreateDto itemCreateDto) { itemCreateDto.getSku(), itemCreateDto.getType()); } + @GetMapping("") + @AuthGuard(level = AuthLevel.ADMIN_ONLY) + public ItemStoreResponseDto getAllItems() { + List allItems = itemQueryService.getAllItems(); + Map> itemMap = allItems.stream() + .collect(groupingBy(Item::getType, + mapping(itemMapper::toItemDetailsDto, Collectors.toList()))); + List 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) { adminItemFacadeService.assignItem(itemAssignRequestDto.getUserIds(), - itemAssignRequestDto.getItemSku()); + itemAssignRequestDto.getItemSku(), itemAssignRequestDto.getAmount()); } /** diff --git a/backend/src/main/java/org/ftclub/cabinet/admin/item/service/AdminItemFacadeService.java b/backend/src/main/java/org/ftclub/cabinet/admin/item/service/AdminItemFacadeService.java index d8c456f03..dda0e8fed 100644 --- a/backend/src/main/java/org/ftclub/cabinet/admin/item/service/AdminItemFacadeService.java +++ b/backend/src/main/java/org/ftclub/cabinet/admin/item/service/AdminItemFacadeService.java @@ -15,11 +15,10 @@ import org.ftclub.cabinet.item.service.ItemCommandService; import org.ftclub.cabinet.item.service.ItemHistoryCommandService; import org.ftclub.cabinet.item.service.ItemHistoryQueryService; +import org.ftclub.cabinet.item.service.ItemPolicyService; import org.ftclub.cabinet.item.service.ItemQueryService; -import org.ftclub.cabinet.item.service.ItemRedisService; import org.ftclub.cabinet.mapper.ItemMapper; import org.ftclub.cabinet.user.service.UserCommandService; -import org.ftclub.cabinet.user.service.UserQueryService; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -33,11 +32,10 @@ public class AdminItemFacadeService { private final ItemCommandService itemCommandService; private final ItemHistoryQueryService itemHistoryQueryService; private final ItemHistoryCommandService itemHistoryCommandService; + private final ItemPolicyService itemPolicyService; private final ItemMapper itemMapper; - private final ItemRedisService itemRedisService; private final UserCommandService userCommandService; - private final UserQueryService userQueryService; @Transactional public void createItem(Integer Price, Sku sku, ItemType type) { @@ -45,22 +43,19 @@ public void createItem(Integer Price, Sku sku, ItemType type) { } @Transactional - public void assignItem(List userIds, Sku sku) { + public void assignItem(List userIds, Sku sku, Long amount) { Item item = itemQueryService.getBySku(sku); - Long price = item.getPrice(); LocalDateTime now = null; - if (price > 0) { + Long coinAmount = item.getPrice(); + if (sku.equals(Sku.ADMIN_REWARD_COIN)) { + itemPolicyService.verifyCoinAmount(amount); + coinAmount = amount; + } + if (coinAmount > 0) { now = LocalDateTime.now(); - userIds.forEach(userId -> { - long coinAmount = userQueryService.getUser(userId).getCoin(); - itemRedisService.saveCoinCount(userId, coinAmount + item.getPrice()); - - long totalCoinSupply = itemRedisService.getTotalCoinSupply(); - itemRedisService.saveTotalCoinSupply(totalCoinSupply + item.getPrice()); - userCommandService.updateCoinAmount(userId, price); - }); + userCommandService.addBulkCoin(userIds, coinAmount); } - itemHistoryCommandService.createItemHistories(userIds, item.getId(), now); + itemHistoryCommandService.createItemHistories(userIds, item.getId(), now, coinAmount); } @Transactional(readOnly = true) diff --git a/backend/src/main/java/org/ftclub/cabinet/dto/CoinHistoryDto.java b/backend/src/main/java/org/ftclub/cabinet/dto/CoinHistoryDto.java index 023469920..ef2b1afa3 100644 --- a/backend/src/main/java/org/ftclub/cabinet/dto/CoinHistoryDto.java +++ b/backend/src/main/java/org/ftclub/cabinet/dto/CoinHistoryDto.java @@ -13,7 +13,7 @@ public class CoinHistoryDto { private LocalDateTime date; - private Integer amount; + private Long amount; private String history; private String itemDetails; } diff --git a/backend/src/main/java/org/ftclub/cabinet/dto/ItemAssignRequestDto.java b/backend/src/main/java/org/ftclub/cabinet/dto/ItemAssignRequestDto.java index 20770c617..e8708378f 100644 --- a/backend/src/main/java/org/ftclub/cabinet/dto/ItemAssignRequestDto.java +++ b/backend/src/main/java/org/ftclub/cabinet/dto/ItemAssignRequestDto.java @@ -15,4 +15,5 @@ public class ItemAssignRequestDto { private Sku itemSku; private List userIds; + private Long amount; } diff --git a/backend/src/main/java/org/ftclub/cabinet/exception/ExceptionStatus.java b/backend/src/main/java/org/ftclub/cabinet/exception/ExceptionStatus.java index 39c570da2..f5047d2c3 100644 --- a/backend/src/main/java/org/ftclub/cabinet/exception/ExceptionStatus.java +++ b/backend/src/main/java/org/ftclub/cabinet/exception/ExceptionStatus.java @@ -84,7 +84,8 @@ public enum ExceptionStatus { INVALID_JWT_TOKEN(HttpStatus.BAD_REQUEST, "토큰이 없거나, 유효하지 않은 JWT 토큰입니다."), NOT_FOUND_SECTION(HttpStatus.BAD_REQUEST, "사물함 구역 정보를 찾을 수 없습니다."), ITEM_NOT_OWNED(HttpStatus.BAD_REQUEST, "해당 아이템을 보유하고 있지 않습니다"), - ITEM_USE_DUPLICATED(HttpStatus.FORBIDDEN, "아이템이 중복 사용되었습니다."); + ITEM_USE_DUPLICATED(HttpStatus.FORBIDDEN, "아이템이 중복 사용되었습니다."), + INVALID_AMOUNT(HttpStatus.BAD_REQUEST, "코인 지급양은 비어있을 수 없습니다."); final private int statusCode; final private String message; diff --git a/backend/src/main/java/org/ftclub/cabinet/item/domain/ItemHistory.java b/backend/src/main/java/org/ftclub/cabinet/item/domain/ItemHistory.java index 2784a5f72..8f85c32c4 100644 --- a/backend/src/main/java/org/ftclub/cabinet/item/domain/ItemHistory.java +++ b/backend/src/main/java/org/ftclub/cabinet/item/domain/ItemHistory.java @@ -75,11 +75,14 @@ public class ItemHistory { @Column(name = "USER_ID", nullable = false) private Long userId; + @Column(name = "AMOUNT", nullable = true) + private Long amount; - protected ItemHistory(long userId, long itemId, LocalDateTime usedAt) { + protected ItemHistory(Long userId, Long itemId, LocalDateTime assignedAt, Long amount) { this.userId = userId; this.itemId = itemId; - this.usedAt = usedAt; + this.usedAt = assignedAt; + this.amount = amount; } /** @@ -88,8 +91,8 @@ protected ItemHistory(long userId, long itemId, LocalDateTime usedAt) { * @param usedAt 아이템 사용일자 * @return 아이템 히스토리 객체 {@link ItemHistory} */ - public static ItemHistory of(long userId, long itemId, LocalDateTime usedAt) { - ItemHistory itemHistory = new ItemHistory(userId, itemId, usedAt); + public static ItemHistory of(Long userId, Long itemId, LocalDateTime usedAt, Long amount) { + ItemHistory itemHistory = new ItemHistory(userId, itemId, usedAt, amount); if (!itemHistory.isValid()) { throw ExceptionStatus.INVALID_ARGUMENT.asDomainException(); } diff --git a/backend/src/main/java/org/ftclub/cabinet/item/domain/Sku.java b/backend/src/main/java/org/ftclub/cabinet/item/domain/Sku.java index bda3b9beb..64b383a7a 100644 --- a/backend/src/main/java/org/ftclub/cabinet/item/domain/Sku.java +++ b/backend/src/main/java/org/ftclub/cabinet/item/domain/Sku.java @@ -25,11 +25,12 @@ public enum Sku { COIN_REWARD_1000("동전 줍기 20일 보상"), COIN_REWARD_2000("동전 줍기 20일 보상"), - ADMIN_REWARD_100("보상"), - ADMIN_REWARD_200("보상"), - ADMIN_REWARD_500("보상"), - ADMIN_REWARD_1000("보상"), - ADMIN_REWARD_2000("보상"), + ADMIN_REWARD_100("100"), + ADMIN_REWARD_200("200"), + ADMIN_REWARD_500("500"), + ADMIN_REWARD_1000("1000"), + ADMIN_REWARD_2000("2000"), + ADMIN_REWARD_COIN("지정 보상"), ; private final String details; diff --git a/backend/src/main/java/org/ftclub/cabinet/item/service/ItemFacadeService.java b/backend/src/main/java/org/ftclub/cabinet/item/service/ItemFacadeService.java index b6f0e5546..384977313 100644 --- a/backend/src/main/java/org/ftclub/cabinet/item/service/ItemFacadeService.java +++ b/backend/src/main/java/org/ftclub/cabinet/item/service/ItemFacadeService.java @@ -195,7 +195,8 @@ public CoinCollectionRewardResponseDto collectCoinAndIssueReward(Long userId) { // DB에 코인 저장 Item coinCollect = itemQueryService.getBySku(Sku.COIN_COLLECT); int reward = (int) (coinCollect.getPrice().longValue()); - itemHistoryCommandService.createCoinItemHistory(userId, coinCollect.getId()); + itemHistoryCommandService.createCoinItemHistory(userId, coinCollect.getId(), + coinCollect.getPrice()); // 출석 일자에 따른 랜덤 리워드 지급 Long coinCollectionCountInMonth = @@ -206,7 +207,8 @@ public CoinCollectionRewardResponseDto collectCoinAndIssueReward(Long userId) { Sku coinSku = itemPolicyService.getRewardSku(randomPercentage); Item coinReward = itemQueryService.getBySku(coinSku); - itemHistoryCommandService.createCoinItemHistory(userId, coinReward.getId()); + itemHistoryCommandService.createCoinItemHistory(userId, coinReward.getId(), + coinReward.getPrice()); reward += coinReward.getPrice(); } @@ -310,7 +312,7 @@ public void purchaseItem(Long userId, Sku sku) { itemPolicyService.verifyIsAffordable(userCoin, price); // 아이템 구매 처리 - itemHistoryCommandService.createItemHistory(user.getId(), item.getId()); + itemHistoryCommandService.createItemHistory(user.getId(), item.getId(), price); LockUtil.lockRedisCoin(userId, () -> { // 코인 차감 diff --git a/backend/src/main/java/org/ftclub/cabinet/item/service/ItemHistoryCommandService.java b/backend/src/main/java/org/ftclub/cabinet/item/service/ItemHistoryCommandService.java index 2863043c4..f76562608 100644 --- a/backend/src/main/java/org/ftclub/cabinet/item/service/ItemHistoryCommandService.java +++ b/backend/src/main/java/org/ftclub/cabinet/item/service/ItemHistoryCommandService.java @@ -17,20 +17,39 @@ public class ItemHistoryCommandService { private final ItemHistoryRepository itemHistoryRepository; - public void createItemHistory(Long userId, Long itemId) { - ItemHistory itemHistory = ItemHistory.of(userId, itemId, null); + public void createItemHistory(Long userId, Long itemId, Long amount) { + ItemHistory itemHistory = ItemHistory.of(userId, itemId, null, amount); itemHistoryRepository.save(itemHistory); } - public void createItemHistories(List userIds, Long itemId, LocalDateTime usedAt) { + public void createItemHistories(List userIds, Long itemId, LocalDateTime usedAt, + Long amount) { List itemHistories = userIds.stream() - .map(userId -> ItemHistory.of(userId, itemId, usedAt)) + .map(userId -> ItemHistory.of(userId, itemId, usedAt, amount)) .collect(Collectors.toList()); itemHistoryRepository.saveAll(itemHistories); } - public void createCoinItemHistory(Long userId, Long itemId) { - ItemHistory coinCollectItemHistory = ItemHistory.of(userId, itemId, LocalDateTime.now()); + public void createCoinItemHistory(Long userId, Long itemId, Long amount) { + ItemHistory coinCollectItemHistory = ItemHistory.of(userId, itemId, LocalDateTime.now(), + amount); itemHistoryRepository.save(coinCollectItemHistory); } + + /** + * 관리자가 코인 지급 시 ItemHistory에 기록을 남깁니다 + * + * @param userIds + * @param itemId + * @param usedAt + * @param amount + */ + public void createCoinAssignHistory(List userIds, Long itemId, LocalDateTime usedAt, + Long amount) { + List itemHistories = userIds.stream() + .map(userId -> ItemHistory.of(userId, itemId, usedAt, amount)) + .collect(Collectors.toList()); + + itemHistoryRepository.saveAll(itemHistories); + } } diff --git a/backend/src/main/java/org/ftclub/cabinet/item/service/ItemPolicyService.java b/backend/src/main/java/org/ftclub/cabinet/item/service/ItemPolicyService.java index f27d4bf75..49c7dd4e3 100644 --- a/backend/src/main/java/org/ftclub/cabinet/item/service/ItemPolicyService.java +++ b/backend/src/main/java/org/ftclub/cabinet/item/service/ItemPolicyService.java @@ -64,4 +64,10 @@ public Sku getRewardSku(int randomPercentage) { return Sku.COIN_REWARD_2000; } } + + public void verifyCoinAmount(Long amount) { + if (amount == null) { + throw ExceptionStatus.INVALID_AMOUNT.asServiceException(); + } + } } diff --git a/backend/src/main/java/org/ftclub/cabinet/mapper/ItemMapper.java b/backend/src/main/java/org/ftclub/cabinet/mapper/ItemMapper.java index 71939ee98..2649d97d4 100644 --- a/backend/src/main/java/org/ftclub/cabinet/mapper/ItemMapper.java +++ b/backend/src/main/java/org/ftclub/cabinet/mapper/ItemMapper.java @@ -37,9 +37,9 @@ public interface ItemMapper { ItemMapper INSTANCE = Mappers.getMapper(ItemMapper.class); @Mapping(target = "date", source = "itemHistory.purchaseAt") - @Mapping(target = "amount", source = "item.price") @Mapping(target = "history", source = "item.type.name") @Mapping(target = "itemDetails", source = "item.sku.details") + @Mapping(target = "amount", source = "itemHistory.amount") CoinHistoryDto toCoinHistoryDto(ItemHistory itemHistory, Item item); @Mapping(target = "itemSku", source = "item.sku") diff --git a/backend/src/main/java/org/ftclub/cabinet/user/repository/UserRepository.java b/backend/src/main/java/org/ftclub/cabinet/user/repository/UserRepository.java index 0a384bb73..cd495bac0 100644 --- a/backend/src/main/java/org/ftclub/cabinet/user/repository/UserRepository.java +++ b/backend/src/main/java/org/ftclub/cabinet/user/repository/UserRepository.java @@ -140,4 +140,10 @@ public interface UserRepository extends JpaRepository { @Query("SELECT u FROM User u WHERE u.deletedAt IS NULL") List findAllDeletedAtIsNull(); + + @Modifying(clearAutomatically = true) + @Query("UPDATE User u " + + "SET u.coin = u.coin + :amount " + + "WHERE u.id IN :userIds") + void updateBulkUserCoin(@Param("userIds") List userIds, @Param("amount") Long amount); } diff --git a/backend/src/main/java/org/ftclub/cabinet/user/service/LentExtensionManager.java b/backend/src/main/java/org/ftclub/cabinet/user/service/LentExtensionManager.java index cb569e574..380efefc8 100644 --- a/backend/src/main/java/org/ftclub/cabinet/user/service/LentExtensionManager.java +++ b/backend/src/main/java/org/ftclub/cabinet/user/service/LentExtensionManager.java @@ -46,7 +46,8 @@ public void issueLentExtension() { users.forEach(user -> { Long userId = user.getId(); user.addCoin(coinRewardItem.getPrice()); - itemHistoryCommandService.createCoinItemHistory(userId, coinRewardItem.getId()); + itemHistoryCommandService.createCoinItemHistory(userId, coinRewardItem.getId(), + coinRewardItem.getPrice()); }); } diff --git a/backend/src/main/java/org/ftclub/cabinet/user/service/UserCommandService.java b/backend/src/main/java/org/ftclub/cabinet/user/service/UserCommandService.java index 994e9f7b8..c94c56710 100644 --- a/backend/src/main/java/org/ftclub/cabinet/user/service/UserCommandService.java +++ b/backend/src/main/java/org/ftclub/cabinet/user/service/UserCommandService.java @@ -1,6 +1,7 @@ package org.ftclub.cabinet.user.service; import java.time.LocalDateTime; +import java.util.List; import javax.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.ftclub.cabinet.auth.domain.FtProfile; @@ -115,4 +116,8 @@ public void updateCoinAmount(Long userId, Long reward) { .orElseThrow(ExceptionStatus.NOT_FOUND_USER::asServiceException); user.addCoin(reward); } + + public void addBulkCoin(List userIds, Long amount) { + userRepository.updateBulkUserCoin(userIds, amount); + } } diff --git a/frontend/src/Cabinet/api/axios/axios.custom.ts b/frontend/src/Cabinet/api/axios/axios.custom.ts index 514135b75..620d3f275 100644 --- a/frontend/src/Cabinet/api/axios/axios.custom.ts +++ b/frontend/src/Cabinet/api/axios/axios.custom.ts @@ -371,6 +371,23 @@ export const axiosItems = async (): Promise => { const response = await instance.get(axiosItemsURL); return response; } catch (error) { + console.log(error); + logAxiosError( + error, + ErrorType.STORE, + "상점 아이템 목록 불러오는중 오류 발생" + ); + throw error; + } +}; + +const axiosAdminItemsURL = "/v5/admin/items"; +export const axiosAdminItems = async (): Promise => { + try { + const response = await instance.get(axiosAdminItemsURL); + return response; + } catch (error) { + console.log(error); logAxiosError( error, ErrorType.STORE, @@ -743,9 +760,9 @@ export const axiosLentClubCabinet = async ( try { const response = await instance.post( axiosLentClubCabinetURL + - clubId.toString() + - "/cabinets/" + - cabinetId.toString() + clubId.toString() + + "/cabinets/" + + cabinetId.toString() ); return response; } catch (error) { @@ -905,6 +922,7 @@ export const axiosSendSlackNotificationToChannel = async ( } }; +// TODO: 확인하고 필요없으면 지우기 const axiosItemAssignURL = "v5/admin/items/assign"; export const axiosItemAssign = async ( itemSku: string, @@ -922,6 +940,25 @@ export const axiosItemAssign = async ( } }; +const axiosCoinAssignURL = "v5/admin/items/assign"; +export const axiosCoinAssign = async ( + itemSku: string, + userIds: number[], + amount: number +): Promise => { + try { + const response = await instance.post(axiosCoinAssignURL, { + itemSku, + userIds, + amount, + }); + return response; + } catch (error) { + logAxiosError(error, ErrorType.STORE, "아이템 지급 중 오류 발생", true); + throw error; + } +}; + const axiosGetUserItemsURL = "/v5/admin/items/users/"; export const axiosGetUserItems = async ( userId: number, diff --git a/frontend/src/Cabinet/components/Modals/StoreModal/AdminItemProvisionModal.tsx b/frontend/src/Cabinet/components/Modals/StoreModal/AdminItemProvisionModal.tsx index 6b102b82e..80f809c8e 100644 --- a/frontend/src/Cabinet/components/Modals/StoreModal/AdminItemProvisionModal.tsx +++ b/frontend/src/Cabinet/components/Modals/StoreModal/AdminItemProvisionModal.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { useRecoilState } from "recoil"; import styled from "styled-components"; import { targetUserInfoState } from "@/Cabinet/recoil/atoms"; @@ -14,7 +14,10 @@ import { } from "@/Cabinet/components/Modals/ResponseModal/ResponseModal"; import { IItemDetail } from "@/Cabinet/types/dto/store.dto"; import { StoreItemType } from "@/Cabinet/types/enum/store.enum"; -import { axiosItemAssign, axiosItems } from "@/Cabinet/api/axios/axios.custom"; +import { + axiosCoinAssign, + axiosAdminItems, +} from "@/Cabinet/api/axios/axios.custom"; interface IPenaltyModalProps { onClose: () => void; @@ -35,15 +38,21 @@ const AdminItemProvisionModal: React.FC = ({ onClose }) => { const [isItemDropdownOpen, setIsItemDropdownOpen] = useState(false); const [isItemTypeDropdownOpen, setIsItemTypeDropdownOpen] = useState(false); const [targetUserInfo] = useRecoilState(targetUserInfoState); - + const coinRef = useRef(null); const HandleItemProvisionBtn = async () => { + let coinRefVal = coinRef.current!.value; + coinRefVal = coinRefVal == "" ? "0" : String(coinRefVal); setIsLoading(true); try { - await axiosItemAssign(selectedItemSku, [targetUserInfo.userId!]); + await axiosCoinAssign( + selectedItemSku, + [targetUserInfo.userId!], + Number(coinRefVal) + ); setModalTitle("아이템 지급완료"); } catch (error: any) { setHasErrorOnResponse(true); - if (error.response.ststus === 400) setModalTitle("아이템 지급실패"); + if (error.response.status === 400) setModalTitle("아이템 지급실패"); else error.response ? setModalTitle(error.response.data.message) @@ -72,7 +81,7 @@ const AdminItemProvisionModal: React.FC = ({ onClose }) => { const getItems = async () => { try { - const response = await axiosItems(); + const response = await axiosAdminItems(); setItems(response.data.items); } catch (error) { throw error; @@ -116,17 +125,19 @@ const AdminItemProvisionModal: React.FC = ({ onClose }) => { }, []); const getItemTypeOptions = (item: IItemDetail) => { + console.log(item.items); + return item.items.length === 1 ? [ - { - name: "타입이 없습니다", - value: item.items[0].itemSku, - hasNoOptions: true, - }, - ] + { + name: "타입이 없습니다", + value: item.items[0].itemSku, + hasNoOptions: true, + }, + ] : item.items.map((item) => { - return { name: item.itemDetails, value: item.itemSku }; - }); + return { name: item.itemDetails, value: item.itemSku }; + }); }; const modalContents: IModalContents = { @@ -152,6 +163,18 @@ const AdminItemProvisionModal: React.FC = ({ onClose }) => { 아이템 타입 + + + 코인 + { + if (e.key === "Enter") HandleItemProvisionBtn(); + }} + ref={coinRef} + maxLength={10} + id="input" + > + ), }; @@ -179,4 +202,19 @@ const ModalDropdownNameStyled = styled.div` font-size: 18px; `; +const CoinInputStyled = styled.input` + border: 1px solid var(--light-gray-line-btn-color); + width: 100%; + height: 60px; + border-radius: 10px; + text-align: start; + text-indent: 20px; + font-size: 1.125rem; + cursor: "input"; + color: "var(--normal-text-color)"; + &::placeholder { + color: "var(--line-color)"; + } +`; + export default AdminItemProvisionModal;