Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -9,6 +9,7 @@
import leets.weeth.domain.account.domain.entity.Receipt;
import leets.weeth.domain.account.domain.service.AccountGetService;
import leets.weeth.domain.account.domain.service.AccountSaveService;
import leets.weeth.domain.account.domain.service.ReceiptGetService;
import leets.weeth.domain.file.application.dto.response.FileResponse;
import leets.weeth.domain.file.application.mapper.FileMapper;
import leets.weeth.domain.file.domain.service.FileGetService;
Expand All @@ -25,16 +26,18 @@ public class AccountUseCaseImpl implements AccountUseCase {

private final AccountGetService accountGetService;
private final AccountSaveService accountSaveService;
private final ReceiptGetService receiptGetService;
private final FileGetService fileGetService;
private final CardinalGetService cardinalGetService;

private final AccountMapper accountMapper;
private final ReceiptMapper receiptMapper;
private final FileMapper fileMapper;

@Override
public AccountDTO.Response find(Integer cardinal) {
Account account = accountGetService.find(cardinal);
List<Receipt> receipts = account.getReceipts();
List<Receipt> receipts = receiptGetService.findAllByAccountId(account.getId());
List<ReceiptDTO.Response> response = receipts.stream()
.map(receipt -> receiptMapper.to(receipt, getFiles(receipt.getId())))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
import leets.weeth.domain.account.domain.entity.Receipt;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ReceiptRepository extends JpaRepository<Receipt, Long> {
List<Receipt> findAllByAccountIdOrderByIdDesc(Long accountId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id도 괜찮긴 하지만, 직관성을 위해서 created_at을 기준으로 정렬하는건 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 생성 시점이 중요하기에 정렬 기준을 id -> createdAt으로 변경했습니다

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ReceiptGetService {
Expand All @@ -16,4 +18,8 @@ public Receipt find(Long id) {
return receiptRepository.findById(id)
.orElseThrow(ReceiptNotFoundException::new);
}

public List<Receipt> findAllByAccountId(Long accountId) {
return receiptRepository.findAllByAccountIdOrderByIdDesc(accountId);
}
}