-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44324da
commit d24e54c
Showing
11 changed files
with
245 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...va/com/daon/onjung/onjung/application/dto/response/ReadUserOnjungOverviewResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.daon.onjung.onjung.application.dto.response; | ||
|
||
import com.daon.onjung.core.dto.SelfValidating; | ||
import com.daon.onjung.core.exception.error.ErrorCode; | ||
import com.daon.onjung.core.exception.type.CommonException; | ||
import com.daon.onjung.core.utility.DateTimeUtil; | ||
import com.daon.onjung.onjung.domain.Donation; | ||
import com.daon.onjung.onjung.domain.Receipt; | ||
import com.daon.onjung.onjung.domain.Share; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
public class ReadUserOnjungOverviewResponseDto extends SelfValidating<ReadUserOnjungOverviewResponseDto> { | ||
|
||
@JsonProperty("store_list") | ||
@NotNull(message = "store_list는 null일 수 없습니다.") | ||
private final List<StoreDto> storeList; | ||
|
||
@Builder | ||
public ReadUserOnjungOverviewResponseDto(List<StoreDto> storeList) { | ||
this.storeList = storeList; | ||
this.validateSelf(); | ||
} | ||
|
||
@Getter | ||
public static class StoreDto extends SelfValidating<StoreDto> { | ||
|
||
@JsonProperty("onjung_type") | ||
@NotNull(message = "onjung_type은 null일 수 없습니다.") | ||
private final String onjungType; | ||
|
||
@JsonProperty("store_name") | ||
@NotNull(message = "store_name은 null일 수 없습니다.") | ||
private final String storeName; | ||
|
||
@JsonProperty("store_title") | ||
@NotNull(message = "store_title은 null일 수 없습니다.") | ||
private final String storeTitle; | ||
|
||
@JsonProperty("amount") | ||
@NotNull(message = "amount는 null일 수 없습니다.") | ||
private final Integer amount; | ||
|
||
@JsonProperty("date") | ||
@NotNull(message = "date는 null일 수 없습니다.") | ||
private final String date; | ||
|
||
@Builder | ||
public StoreDto(String onjungType, String storeName, String storeTitle, Integer amount, String date) { | ||
this.onjungType = onjungType; | ||
this.storeName = storeName; | ||
this.storeTitle = storeTitle; | ||
this.amount = amount; | ||
this.date = date; | ||
this.validateSelf(); | ||
} | ||
|
||
public static StoreDto of(String onjungType, String storeName, String storeTitle, Integer amount, String date) { | ||
return StoreDto.builder() | ||
.onjungType(onjungType) | ||
.storeName(storeName) | ||
.storeTitle(storeTitle) | ||
.amount(amount) | ||
.date(date) | ||
.build(); | ||
} | ||
} | ||
|
||
public static ReadUserOnjungOverviewResponseDto of(List<Object> sortedEntities) { | ||
|
||
List<StoreDto> storeList = sortedEntities.stream() | ||
.map(entity -> { | ||
if (entity instanceof Donation donation) { | ||
return StoreDto.of( | ||
"DONATION", | ||
donation.getStore().getName(), | ||
donation.getStore().getTitle(), | ||
donation.getDonationAmount(), | ||
DateTimeUtil.convertLocalDateTimeToDotSeparatedDateTime(donation.getCreatedAt()) | ||
); | ||
} else if (entity instanceof Receipt receipt) { | ||
return StoreDto.of( | ||
"RECEIPT", | ||
receipt.getStore().getName(), | ||
receipt.getStore().getTitle(), | ||
receipt.getPaymentAmount(), | ||
DateTimeUtil.convertLocalDateTimeToDotSeparatedDateTime(receipt.getCreatedAt()) | ||
); | ||
} else if (entity instanceof Share share) { | ||
return StoreDto.of( | ||
"SHARE", | ||
share.getStore().getName(), | ||
share.getStore().getTitle(), | ||
share.getCount() * 100, | ||
DateTimeUtil.convertLocalDateTimeToDotSeparatedDateTime(share.getCreatedAt().atStartOfDay()) | ||
); | ||
} | ||
throw new CommonException(ErrorCode.INVALID_ARGUMENT); | ||
}) | ||
.collect(Collectors.toList()); | ||
|
||
return ReadUserOnjungOverviewResponseDto.builder() | ||
.storeList(storeList) | ||
.build(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/daon/onjung/onjung/application/service/ReadUserOnjungOverviewService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.daon.onjung.onjung.application.service; | ||
|
||
import com.daon.onjung.account.domain.User; | ||
import com.daon.onjung.account.repository.mysql.UserRepository; | ||
import com.daon.onjung.core.exception.error.ErrorCode; | ||
import com.daon.onjung.core.exception.type.CommonException; | ||
import com.daon.onjung.onjung.application.dto.response.ReadUserOnjungOverviewResponseDto; | ||
import com.daon.onjung.onjung.application.usecase.ReadUserOnjungOverviewUseCase; | ||
import com.daon.onjung.onjung.domain.Donation; | ||
import com.daon.onjung.onjung.domain.Onjung; | ||
import com.daon.onjung.onjung.domain.Receipt; | ||
import com.daon.onjung.onjung.domain.Share; | ||
import com.daon.onjung.onjung.domain.service.OnjungService; | ||
import com.daon.onjung.onjung.repository.mysql.DonationRepository; | ||
import com.daon.onjung.onjung.repository.mysql.ReceiptRepository; | ||
import com.daon.onjung.onjung.repository.mysql.ShareRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReadUserOnjungOverviewService implements ReadUserOnjungOverviewUseCase { | ||
|
||
private final UserRepository userRepository; | ||
private final DonationRepository donationRepository; | ||
private final ShareRepository shareRepository; | ||
private final ReceiptRepository receiptRepository; | ||
|
||
private final OnjungService onjungService; | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public ReadUserOnjungOverviewResponseDto execute( | ||
UUID accountId) { | ||
|
||
// 유저 조회 | ||
User user = userRepository.findById(accountId) | ||
.orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_RESOURCE)); | ||
|
||
// 유저의 동참, 공유, 영수증 인증 조회 | ||
List<Donation> donations = donationRepository.findAllByUser(user); | ||
List<Share> shares = shareRepository.findAllByUser(user); | ||
List<Receipt> receipts = receiptRepository.findAllByUser(user); | ||
|
||
Onjung onjung = onjungService.createOnjung(donations, receipts, shares); | ||
|
||
// 생성 시간 기준으로 정렬 | ||
List<Object> sortedOnjungByCreatedAt = onjungService.sortOnjungByCreatedAt(onjung); | ||
|
||
return ReadUserOnjungOverviewResponseDto.of(sortedOnjungByCreatedAt); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/daon/onjung/onjung/application/usecase/ReadUserOnjungOverviewUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.daon.onjung.onjung.application.usecase; | ||
|
||
import com.daon.onjung.core.annotation.bean.UseCase; | ||
import com.daon.onjung.onjung.application.dto.response.ReadUserOnjungOverviewResponseDto; | ||
|
||
import java.util.UUID; | ||
|
||
@UseCase | ||
public interface ReadUserOnjungOverviewUseCase { | ||
|
||
ReadUserOnjungOverviewResponseDto execute(UUID accountId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters