-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#39 서비스 CompletableFuture 추가, 정적메소드네이밍 #40
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "39-CompletableFuture-\uC11C\uBE44\uC2A4\uCD94\uAC00"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ | |
import com.cosmetics.domain.goods.dto.GoodsManagement; | ||
import com.cosmetics.domain.goods.entity.GoodsManagementEntity; | ||
import com.cosmetics.domain.goods.repository.GoodsRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
@Service | ||
@Slf4j | ||
|
@@ -16,30 +18,29 @@ public class GoodsService { | |
private final GoodsRepository goodsRepository; | ||
|
||
@Transactional | ||
//@Async //써야하나? | ||
public GoodsManagement findByGoodsNo(Long goodsNo) { | ||
log.error("GoodsService Thread = {}", Thread.currentThread().getName()); | ||
//여기도 비동기처리를해야하나? | ||
GoodsManagementEntity goodsManagementEntity = goodsRepository.findByGoodsNo(goodsNo).orElseThrow(() -> new IllegalArgumentException("상품이 존재하지 않습니다.")); | ||
//entity -> dto | ||
return GoodsManagement.toDto(goodsManagementEntity); | ||
public CompletableFuture<GoodsManagement> findByGoodsNo(Long goodsNo) { | ||
return CompletableFuture.supplyAsync(() -> { | ||
log.error("GoodsService Thread = {}", Thread.currentThread().getName()); | ||
GoodsManagementEntity goodsManagementEntity = goodsRepository.findByGoodsNo(goodsNo).orElseThrow(() -> new IllegalArgumentException("상품이 존재하지 않습니다.")); | ||
return GoodsManagement.fromEntity(goodsManagementEntity); | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "failed to lazily initialize a collection of role: com.cosmetics.domain.goods.entity.GoodsManagementEntity.items: could not initialize proxy - no Session" |
||
|
||
@Transactional | ||
public GoodsManagement save(GoodsManagement goodsManagement) { | ||
//Service단은 따로 작업을 안했는데 이게 맞을까요? | ||
GoodsManagementEntity resultGoodsManagementEntity = goodsRepository.save(goodsManagement.toEntity()); | ||
|
||
//entity -> dto | ||
return GoodsManagement.toDto(resultGoodsManagementEntity); | ||
public CompletableFuture<GoodsManagement> save(GoodsManagement goodsManagement) { | ||
CompletableFuture<GoodsManagement> goodsManageFuture = CompletableFuture.supplyAsync(() -> { | ||
log.error("GoodsService Thread = {}", Thread.currentThread().getName()); | ||
GoodsManagementEntity resultGoodsManagementEntity = goodsRepository.save(goodsManagement.toEntity()); | ||
return GoodsManagement.fromEntity(resultGoodsManagementEntity); | ||
}); | ||
return goodsManageFuture; | ||
} | ||
|
||
@Transactional | ||
public GoodsManagement deleteByGoodsNo(Long goodsNo) { | ||
GoodsManagementEntity goodsManagementEntity = goodsRepository.findByGoodsNo(goodsNo).orElseThrow(() -> new IllegalArgumentException("상품이 존재하지 않습니다.")); | ||
long deleteCnt = goodsRepository.deleteByGoodsNo(goodsNo); | ||
|
||
//entity -> dto | ||
return GoodsManagement.toDto(goodsManagementEntity); | ||
return GoodsManagement.fromEntity(goodsManagementEntity); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gradle ci 에서 걸려서 수정한 것으로 넘어가시면됩니다.