Skip to content

Commit

Permalink
feat: @CacheEvict 설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yonghwankim-dev committed Oct 23, 2024
1 parent 257fd19 commit 1d973aa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ public ApiResponse<Void> deletePortfolio(@PathVariable Long portfolioId,

// 포트폴리오 다수 삭제
@DeleteMapping
public ApiResponse<Void> deletePortfolios(@RequestBody PortfoliosDeleteRequest request) {
portFolioService.deletePortfolios(request.getPortfolioIds());
public ApiResponse<Void> deletePortfolios(@RequestBody PortfoliosDeleteRequest request,
@MemberAuthenticationPrincipal MemberAuthentication authentication) {
portFolioService.deletePortfolios(request.getPortfolioIds(), authentication.getId());
return ApiResponse.success(PortfolioSuccessCode.OK_DELETE_PORTFOLIO);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.stream.Collectors;

import org.jetbrains.annotations.NotNull;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class PortFolioService {

@Transactional
@Secured("ROLE_USER")
@CacheEvict(value = "myAllPortfolioNames", key = "#memberId")
public PortFolioCreateResponse createPortfolio(PortfolioCreateRequest request, Long memberId) {
validateSecuritiesFirm(request.getSecuritiesFirm());

Expand Down Expand Up @@ -90,6 +92,7 @@ private void validateUniquePortfolioName(String name, Member member) {
}

@Transactional
@CacheEvict(value = "myAllPortfolioNames", key = "#memberId")
@Authorized(serviceClass = PortfolioAuthorizedService.class)
@Secured("ROLE_USER")
public PortfolioModifyResponse updatePortfolio(PortfolioModifyRequest request, @ResourceId Long portfolioId,
Expand All @@ -109,6 +112,7 @@ public PortfolioModifyResponse updatePortfolio(PortfolioModifyRequest request, @
}

@Transactional
@CacheEvict(value = "myAllPortfolioNames", key = "#memberId")
@Authorized(serviceClass = PortfolioAuthorizedService.class)
@Secured("ROLE_USER")
public void deletePortfolio(@ResourceId Long portfolioId, Long memberId) {
Expand All @@ -133,9 +137,11 @@ public void deletePortfolio(@ResourceId Long portfolioId, Long memberId) {
}

@Transactional
@CacheEvict(value = "myAllPortfolioNames", key = "#memberId")
@Authorized(serviceClass = PortfolioAuthorizedService.class)
@Secured("ROLE_USER")
public void deletePortfolios(@ResourceIds List<Long> portfolioIds) {
public void deletePortfolios(@ResourceIds List<Long> portfolioIds, @NotNull Long memberId) {
log.info("portfolio multiple delete service request: portfolioIds={}, memberId={}", portfolioIds, memberId);
for (Long portfolioId : portfolioIds) {
Portfolio portfolio = findPortfolio(portfolioId);
List<Long> portfolioStockIds = portfolioHoldingRepository.findAllByPortfolio(portfolio).stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ void deletePortfolios() {
List<Long> portfolioIds = Arrays.asList(portfolio.getId(), portfolio2.getId());
setAuthentication(member);
// when
service.deletePortfolios(portfolioIds);
service.deletePortfolios(portfolioIds, member.getId());

// then
assertThat(portfolioRepository.existsById(portfolio.getId())).isFalse();
Expand All @@ -550,7 +550,7 @@ void deletePortfolios_whenDeleteOtherMemberPortfolio_thenThrowException() {

setAuthentication(hacker);
// when
Throwable throwable = catchThrowable(() -> service.deletePortfolios(portfolioIds));
Throwable throwable = catchThrowable(() -> service.deletePortfolios(portfolioIds, member.getId()));

// then
assertThat(throwable)
Expand Down

0 comments on commit 1d973aa

Please sign in to comment.