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 @@ -23,7 +23,6 @@
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.antlr.v4.runtime.misc.LogManager;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -317,8 +316,6 @@ public void unlockWeeklyCounsel(Long userId, LocalDate startDate, UnlockType typ
// 잉크 사용 시 처리
if (type == UnlockType.INK) {
User user = counsel.getUser();
if (user.getInk() < 10) throw new CustomException(EgoRoomErrorCode.INSUFFICIENT_INK);

user.useInk(10);
// 잉크 로그 작성
inkLogRepository.save(new InkLog(user, -10, InkLogType.WEEKLY_UNLOCK));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.example.egobook_be.domain.letters.service;


import com.example.egobook_be.domain.diary.dto.DiaryCreateResDto;
import com.example.egobook_be.domain.diary.enums.RewardType;
import com.example.egobook_be.domain.friend.repository.FriendRepository;
import com.example.egobook_be.domain.home.entity.Mission;
import com.example.egobook_be.domain.home.repository.MissionRepository;
Expand Down Expand Up @@ -139,7 +137,7 @@ public CreateLetterResponse createLetter(Long userId, CreateLetterRequest reques

// 3. 잉크 차감 (유료일 때만)
if (price > 0) {
user.usingInk(price); // 부족하면 여기서 예외 발생
user.useInk(price); // 부족하면 여기서 예외 발생

InkLog inkLog = InkLog.builder()
.user(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,20 @@ public ItemInfoResDto purchaseItem(Long userId, PurchaseItemReqDto reqDto){
}

// 2. 해당 사용자가 아이템을 살 수 있는지 확인한다.
if(user.getInk() < item.getPrice()) throw new CustomException(ShopErrorCode.INSUFFICIENT_INK_TO_BUY_ITEM);

// 3. 해당 아이템을 구매한다. (UserItem Table에 새로운 객체를 추가한다.)
UserItem userItem = UserItem.builder()
.user(user)
.item(item)
.isEquipped(false)
.build();
userItem = userItemRepository.save(userItem);
user.purchaseItem(item.getPrice());

// 4. 아이템 구매 후, 해당 아이템에 대한 정보를 반환한다.
return userItemMapper.toItemInfoResDto(userItem, item, getShopCloudFrontDomain());
if(user.getInk() >= item.getPrice()){
// 3. 해당 아이템을 구매한다. (UserItem Table에 새로운 객체를 추가한다.)
UserItem userItem = UserItem.builder()
.user(user)
.item(item)
.isEquipped(false)
.build();
userItem = userItemRepository.save(userItem);
user.useInk(item.getPrice());

// 4. 아이템 구매 후, 해당 아이템에 대한 정보를 반환한다.
return userItemMapper.toItemInfoResDto(userItem, item, getShopCloudFrontDomain());
}
throw new CustomException(ShopErrorCode.INSUFFICIENT_INK_TO_BUY_ITEM);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,7 @@ public void addInk(int amount) {
this.ink += amount;
}

public void purchaseItem(int price){
this.ink -= price;
}

public void useInk(int price){
this.ink -= price;
}

public void usingInk(int price){
if (price <= 0) return;

if (this.ink == null || this.ink < price) {
Expand Down
Loading