Skip to content

Commit

Permalink
FEAT: 여러 유저에게 동일한 코인을 지급하는 Bulk add 기능
Browse files Browse the repository at this point in the history
  • Loading branch information
saewoo1 committed Oct 25, 2024
1 parent b3c2463 commit 2df4fe5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ public void assignItem(List<Long> userIds, Sku sku) {
public void assignCoin(List<Long> userIds, Sku sku, Long amount) {
Item item = itemQueryService.getBySku(sku);
LocalDateTime now = LocalDateTime.now();
userIds.forEach(userId -> {
userCommandService.updateCoinAmount(userId, amount);
});
userCommandService.addBulkUserCoin(userIds, amount);
itemHistoryCommandService.createCoinAssignHistory(userIds, item.getId(), now, amount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,10 @@ public interface UserRepository extends JpaRepository<User, Long> {

@Query("SELECT u FROM User u WHERE u.deletedAt IS NULL")
List<User> findAllDeletedAtIsNull();

@Modifying(clearAutomatically = true)
@Query("UPDATE User u "
+ "SET u.coin = u.coin + :amount "
+ "WHERE u.id IN :userIds")
void updateBulkUserCoin(@Param("userIds") List<Long> userIds, @Param("amount") Long amount);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -115,4 +116,8 @@ public void updateCoinAmount(Long userId, Long reward) {
.orElseThrow(ExceptionStatus.NOT_FOUND_USER::asServiceException);
user.addCoin(reward);
}

public void addBulkUserCoin(List<Long> userIds, Long amount) {
userRepository.updateBulkUserCoin(userIds, amount);
}
}

0 comments on commit 2df4fe5

Please sign in to comment.