Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -4,12 +4,15 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.umc.valuedi.domain.asset.exception.code.AssetSuccessCode;
import org.umc.valuedi.domain.asset.dto.res.AssetResDTO;
import org.umc.valuedi.domain.asset.dto.res.BankResDTO;
import org.umc.valuedi.domain.asset.dto.res.CardResDTO;
import org.umc.valuedi.domain.asset.service.AssetQueryService;
import org.umc.valuedi.domain.asset.service.query.AssetQueryService;
import org.umc.valuedi.domain.asset.service.command.AssetSyncFacadeService;
import org.umc.valuedi.domain.connection.service.ConnectionQueryService;
import org.umc.valuedi.global.apiPayload.ApiResponse;
import org.umc.valuedi.global.apiPayload.code.GeneralSuccessCode;
Expand All @@ -25,6 +28,7 @@ public class AssetController implements AssetControllerDocs {

private final ConnectionQueryService connectionQueryService;
private final AssetQueryService assetQueryService;
private final AssetSyncFacadeService assetSyncFacadeService;


@GetMapping("/cards")
Expand Down Expand Up @@ -65,8 +69,8 @@ public ApiResponse<BankResDTO.BankAccountListDTO> getAllBankAccounts(
return ApiResponse.onSuccess(GeneralSuccessCode.OK, assetQueryService.getAllBankAccounts(memberId));
}

@GetMapping("/banks/{bankCode}/accounts")
public ApiResponse<BankResDTO.BankAccountListDTO> getAccountsByBank(
@GetMapping("/banks/{bankCode}")
public ApiResponse<BankResDTO.BankAssetResponse> getAccountsByBank(
@PathVariable String bankCode,
@CurrentMember Long memberId
) {
Expand All @@ -79,4 +83,12 @@ public ApiResponse<AssetResDTO.AssetSummaryCountDTO> getAssetCount(
) {
return ApiResponse.onSuccess(GeneralSuccessCode.OK, assetQueryService.getAssetSummaryCount(memberId));
}

@PostMapping("/sync/refresh")
public ApiResponse<Void> refreshAssetSync(
@CurrentMember Long memberId
) {
assetSyncFacadeService.refreshAssetSync(memberId);
return ApiResponse.onSuccess(AssetSuccessCode.SYNC_REQUEST_SUCCESS, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,26 @@ ApiResponse<CardResDTO.CardListDTO> getCardsByIssuer(
"result": {
"accountList": [
{
"accountId": 1,
"accountName": "KB๋‚˜๋ผ์‚ฌ๋ž‘์šฐ๋Œ€ํ†ต์žฅ",
"balanceAmount": 150000,
"organization": "0004",
"createdAt": "2024-05-20T10:00:00"
"createdAt": "2024-05-20T10:00:00",
"goalInfo": null
},
{
"accountId": 2,
"accountName": "KB๊ตญ๋ฏผONEํ†ต์žฅ",
"balanceAmount": 300000,
"organization": "0004",
"createdAt": "2024-05-21T10:00:00",
"goalInfo": {
"goalId": 2,
"title": "์—ฌํ–‰"
}
}
],
"totalCount": 1
"totalCount": 2
}
}
"""
Expand All @@ -205,38 +218,77 @@ ApiResponse<CardResDTO.CardListDTO> getCardsByIssuer(
})
ApiResponse<BankResDTO.BankAccountListDTO> getAllBankAccounts(@CurrentMember Long memberId);

@Operation(summary = "์€ํ–‰๋ณ„ ๊ณ„์ขŒ ๋ชฉ๋ก ์กฐํšŒ", description = "ํŠน์ • ์€ํ–‰์— ์—ฐ๋™๋œ ๊ณ„์ขŒ ๋ชฉ๋ก์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@Operation(summary = "์€ํ–‰๋ณ„ ๊ณ„์ขŒ ๋ฐ ๋ชฉํ‘œ ๋ชฉ๋ก ์กฐํšŒ", description = "ํŠน์ • ์€ํ–‰์— ์—ฐ๋™๋œ ๊ณ„์ขŒ์™€ ๋ชฉํ‘œ ๋ชฉ๋ก์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "์„ฑ๊ณต - ์€ํ–‰๋ณ„ ๊ณ„์ขŒ ๋ชฉ๋ก ๋ฐ˜ํ™˜",
content = @Content(
schema = @Schema(implementation = ApiResponse.class),
examples = @ExampleObject(
name = "์„ฑ๊ณต ์˜ˆ์‹œ",
value = """
{
"isSuccess": true,
"code": "COMMON200",
"message": "์„ฑ๊ณต์ž…๋‹ˆ๋‹ค.",
"result": {
"accountList": [
{
"accountName": "KB๋‚˜๋ผ์‚ฌ๋ž‘์šฐ๋Œ€ํ†ต์žฅ",
"balanceAmount": 150000,
"organization": "0004",
"createdAt": "2024-05-20T10:00:00"
}
],
"totalCount": 1
}
}
"""
)
examples = {
@ExampleObject(
name = "๋ชฉํ‘œ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ",
value = """
{
"isSuccess": true,
"code": "COMMON200",
"message": "์š”์ฒญ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ฒ˜๋ฆฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.",
"result": {
"bankName": "์šฐ๋ฆฌ์€ํ–‰",
"totalBalance": 240732,
"accountList": [
{
"accountId": 2,
"accountName": "์ €์ถ•์˜ˆ๊ธˆ",
"balanceAmount": 220732,
"connectedGoalId": null
},
{
"accountId": 3,
"accountName": "์ฒญ์•ฝ์ €์ถ•",
"balanceAmount": 20000,
"connectedGoalId": 101
}
],
"goalList": [
{
"goalId": 2,
"title": "์—ฌํ–‰ํ–‰",
"linkedAccountId": 2
}
]
}
}
"""
),
@ExampleObject(
name = "๋ชฉํ‘œ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ",
value = """
{
"isSuccess": true,
"code": "COMMON200",
"message": "์š”์ฒญ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ฒ˜๋ฆฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.",
"result": {
"bankName": "์šฐ๋ฆฌ์€ํ–‰",
"totalBalance": 100000,
"accountList": [
{
"accountId": 2,
"accountName": "์ €์ถ•์˜ˆ๊ธˆ",
"balanceAmount": 100000,
"connectedGoalId": null
}
],
"goalList": []
}
}
"""
)
}
)
)
})
ApiResponse<BankResDTO.BankAccountListDTO> getAccountsByBank(
ApiResponse<BankResDTO.BankAssetResponse> getAccountsByBank(
@Parameter(description = "์€ํ–‰ ์ฝ”๋“œ (์˜ˆ: 0020)") String organization,
@CurrentMember Long memberId
);
Expand Down Expand Up @@ -267,4 +319,52 @@ ApiResponse<BankResDTO.BankAccountListDTO> getAccountsByBank(
)
})
ApiResponse<AssetResDTO.AssetSummaryCountDTO> getAssetCount(@CurrentMember Long memberId);

@Operation(
summary = "์ „์ฒด ์ž์‚ฐ ์ƒˆ๋กœ๊ณ ์นจ(๋™๊ธฐํ™”) ์š”์ฒญ API",
description = """
์‚ฌ์šฉ์ž๊ฐ€ ์—ฐ๋™ํ•œ ๋ชจ๋“  ๊ธˆ์œต์‚ฌ์˜ ์ตœ์‹  ๊ฑฐ๋ž˜๋‚ด์—ญ ์ˆ˜์ง‘์„ **๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์‹œ์ž‘**ํ•˜๋„๋ก ์š”์ฒญํ•ฉ๋‹ˆ๋‹ค.
- **์ฆ‰์‹œ ์‘๋‹ต**: API๋Š” ๋™๊ธฐํ™” ์ž‘์—…์„ ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ๋„˜๊ธฐ๊ณ  ์ฆ‰์‹œ '์š”์ฒญ ์„ฑ๊ณต' ์‘๋‹ต์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
- **๊ฒฐ๊ณผ ํ™•์ธ**: ์‹ค์ œ ๋™๊ธฐํ™” ๊ฒฐ๊ณผ๋Š” ์ž ์‹œ ํ›„ ์ž์‚ฐ ๊ด€๋ จ ๋‹ค๋ฅธ API๋ฅผ ํ†ตํ•ด ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
- **10๋ถ„ ์ฟจํƒ€์ž„**: ๋งˆ์ง€๋ง‰ ๋™๊ธฐํ™” ์‹œ๊ฐ„์œผ๋กœ๋ถ€ํ„ฐ 10๋ถ„ ์ด๋‚ด์—๋Š” ์žฌํ˜ธ์ถœํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
"""
)
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "์„ฑ๊ณต - ๋™๊ธฐํ™” ์ž‘์—…์ด ์„ฑ๊ณต์ ์œผ๋กœ ์‹œ์ž‘๋จ",
content = @Content(
schema = @Schema(implementation = ApiResponse.class),
examples = @ExampleObject(
name = "์„ฑ๊ณต ์˜ˆ์‹œ",
value = """
{
"isSuccess": true,
"code": "ASSET200_1",
"message": "์ž์‚ฐ ๋™๊ธฐํ™” ์š”์ฒญ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ ‘์ˆ˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ž ์‹œ ํ›„ ๋ฐ์ดํ„ฐ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”.",
"result": null
}
"""
)
)
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "429",
description = "์‹คํŒจ - 10๋ถ„ ์ฟจํƒ€์ž„ ์ œํ•œ",
content = @Content(
schema = @Schema(implementation = ApiResponse.class),
examples = @ExampleObject(
name = "์ฟจํƒ€์ž„ ์‹คํŒจ ์˜ˆ์‹œ",
value = """
{
"isSuccess": false,
"code": "ASSET429_1",
"message": "์ž์‚ฐ ๋™๊ธฐํ™”๋Š” 10๋ถ„์— ํ•œ ๋ฒˆ๋งŒ ์š”์ฒญํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
}
"""
)
)
)
})
ApiResponse<Void> refreshAssetSync(@Parameter(hidden = true) @CurrentMember Long memberId);
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
package org.umc.valuedi.domain.asset.converter;

import org.springframework.stereotype.Component;
import org.umc.valuedi.domain.asset.dto.res.AssetResDTO;
import org.umc.valuedi.domain.asset.dto.res.BankResDTO;
import org.umc.valuedi.domain.asset.dto.res.CardResDTO;
import org.umc.valuedi.domain.asset.entity.BankAccount;
import org.umc.valuedi.domain.asset.entity.Card;
import org.umc.valuedi.domain.connection.enums.Organization;
import org.umc.valuedi.domain.goal.entity.Goal;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class AssetConverter {

// ๊ฐœ๋ณ„ BankAccount ์—”ํ‹ฐํ‹ฐ -> BankAccountInfo ๋ณ€ํ™˜
public static BankResDTO.BankAccountInfo toBankAccountInfo(BankAccount account) {
BankResDTO.GoalInfo goalInfo = null;
if (account.getGoal() != null) {
Goal goal = account.getGoal();

goalInfo = BankResDTO.GoalInfo.builder()
.goalId(goal.getId())
.title(goal.getTitle())
.build();
}

return BankResDTO.BankAccountInfo.builder()
.accountId(account.getId())
.accountName(account.getAccountName())
.balanceAmount(account.getBalanceAmount())
.organization(account.getCodefConnection().getOrganization()) // ๊ธฐ๊ด€์ฝ”๋“œ ์ถ”์ถœ
.createdAt(account.getCreatedAt())
.goalInfo(goalInfo)
.build();
}

Expand Down Expand Up @@ -66,4 +79,42 @@ public static AssetResDTO.AssetSummaryCountDTO toAssetSummaryCountDTO(long accou
.totalAssetCount(accountCount + cardCount)
.build();
}

// ํŠน์ • ์€ํ–‰์˜ ์ž์‚ฐ ํ˜„ํ™ฉ ์‘๋‹ต DTO ๋ณ€ํ™˜
public static BankResDTO.BankAssetResponse toBankAssetResponse(String organizationCode, List<BankAccount> accounts) {
String bankName = Organization.getNameByCode(organizationCode);

long totalBalance = 0L;
List<BankResDTO.AccountInfo> accountList = new ArrayList<>(accounts.size());
List<BankResDTO.GoalSimpleInfo> goalList = new ArrayList<>();

for (BankAccount account : accounts) {
totalBalance += (account.getBalanceAmount() != null ? account.getBalanceAmount() : 0L);

Goal goal = account.getGoal();
Long connectedGoalId = (goal != null) ? goal.getId() : null;

accountList.add(BankResDTO.AccountInfo.builder()
.accountId(account.getId())
.accountName(account.getAccountName())
.balanceAmount(account.getBalanceAmount())
.connectedGoalId(connectedGoalId)
.build());

if (goal != null) {
goalList.add(BankResDTO.GoalSimpleInfo.builder()
.goalId(goal.getId())
.title(goal.getTitle())
.linkedAccountId(account.getId())
.build());
}
}

return BankResDTO.BankAssetResponse.builder()
.bankName(bankName)
.totalBalance(totalBalance)
.accountList(accountList)
.goalList(goalList)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.List;

@Schema(description = "์ž์‚ฐ ํ†ตํ•ฉ ์‘๋‹ต DTO")
public class AssetResDTO {

Expand All @@ -24,4 +27,28 @@ public static class AssetSummaryCountDTO {
@Schema(description = "์ด ์—ฐ๋™ ์ž์‚ฐ ์ˆ˜ (๊ณ„์ขŒ + ์นด๋“œ)", example = "8")
private Long totalAssetCount;
}
}

@Getter
@AllArgsConstructor
@Builder
@Schema(description = "AssetFetchService์˜ ๋‚ด๋ถ€ ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ DTO (API ์‘๋‹ต์œผ๋กœ ์ง์ ‘ ์‚ฌ์šฉ๋˜์ง€ ์•Š์Œ)")
public static class AssetSyncResult {
@Schema(description = "์ƒˆ๋กœ ์ˆ˜์ง‘๋œ ์€ํ–‰ ๊ฑฐ๋ž˜๋‚ด์—ญ ์ˆ˜")
private int newBankTransactionCount;

@Schema(description = "์ƒˆ๋กœ ์ˆ˜์ง‘๋œ ์นด๋“œ ์Šน์ธ๋‚ด์—ญ ์ˆ˜")
private int newCardApprovalCount;

@Schema(description = "๋ฐ์ดํ„ฐ ์ˆ˜์ง‘์— ์„ฑ๊ณตํ•œ ๊ธฐ๊ด€ ๋ชฉ๋ก")
private List<String> successOrganizations;

@Schema(description = "๋ฐ์ดํ„ฐ ์ˆ˜์ง‘์— ์‹คํŒจํ•œ ๊ธฐ๊ด€ ๋ชฉ๋ก")
private List<String> failureOrganizations;

@Schema(description = "๊ฐ€๊ณ„๋ถ€ ๋™๊ธฐํ™”์— ์‚ฌ์šฉ๋  ์กฐํšŒ ์‹œ์ž‘์ผ")
private LocalDate fromDate;

@Schema(description = "๊ฐ€๊ณ„๋ถ€ ๋™๊ธฐํ™”์— ์‚ฌ์šฉ๋  ์กฐํšŒ ์ข…๋ฃŒ์ผ")
private LocalDate toDate;
}
}
Loading
Loading