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
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
isCoreLibraryDesugaringEnabled = true
}
kotlinOptions {
jvmTarget = "11"
Expand Down Expand Up @@ -105,4 +106,5 @@ dependencies {
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ssafy.tiggle.data.datasource.remote
import com.ssafy.tiggle.data.model.BaseResponse
import com.ssafy.tiggle.data.model.EmptyResponse
import com.ssafy.tiggle.data.model.piggybank.request.CreatePiggyBankRequestDto
import com.ssafy.tiggle.data.model.piggybank.request.PiggyBankEntriesRequestDto
import com.ssafy.tiggle.data.model.piggybank.request.PiggyBankSettingRequestDto
import com.ssafy.tiggle.data.model.piggybank.request.PrimaryAccountRequestDto
import com.ssafy.tiggle.data.model.piggybank.request.SendSMSRequestDto
Expand All @@ -11,8 +12,10 @@ import com.ssafy.tiggle.data.model.piggybank.request.VerificationRequestDto
import com.ssafy.tiggle.data.model.piggybank.request.VerifySMSRequestDto
import com.ssafy.tiggle.data.model.piggybank.response.AccountHolderResponseDto
import com.ssafy.tiggle.data.model.piggybank.response.CreatePiggyBankResponseDto
import com.ssafy.tiggle.data.model.piggybank.response.MainAccountDetailResponseDto
import com.ssafy.tiggle.data.model.piggybank.response.MainAccountResponseDto
import com.ssafy.tiggle.data.model.piggybank.response.PiggyBankAccountResponseDto
import com.ssafy.tiggle.data.model.piggybank.response.PiggyBankEntriesResponseDto
import com.ssafy.tiggle.data.model.piggybank.response.PiggyBankSettingResponseDto
import com.ssafy.tiggle.data.model.piggybank.response.VerificationCheckResponseDto
import com.ssafy.tiggle.data.model.piggybank.response.VerifySMSResponseDto
Expand Down Expand Up @@ -76,4 +79,17 @@ interface PiggyBankApiService {
suspend fun setEsgCategory(
@Path("categoryId") categoryId: Int
): BaseResponse<PiggyBankSettingResponseDto>

@GET("accounts/transactions")
suspend fun getTransactions(
@Query("accountNo") accountNo: String,
@Query("cursor") cursor: String? = null,
@Query("size") size: Int = 20,
@Query("sort") sort: String = "DESC"
): BaseResponse<MainAccountDetailResponseDto>

@POST("piggybank/entries")
suspend fun getPiggyBankEntries(
@Body body: PiggyBankEntriesRequestDto
): BaseResponse<PiggyBankEntriesResponseDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.ssafy.tiggle.data.model.piggybank.request

data class PiggyBankEntriesRequestDto(
val type: String? = null, // CHANGE, DUTCHPAY
val cursor: String? = null, // 커서 기반 페이징
val size: Int? = null, // 페이지 사이즈
val from: String? = null, // 조회 시작일 (yyyy-MM-dd)
val to: String? = null, // 조회 종료일 (yyyy-MM-dd)
val sortKey: String? = null // 정렬 기준 키
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.ssafy.tiggle.data.model.piggybank.response

import com.ssafy.tiggle.domain.entity.piggybank.DomainTransaction
import com.ssafy.tiggle.domain.entity.piggybank.MainAccountDetail

data class MainAccountDetailResponseDto(
val transactions: List<Transaction>,
val nextCursor: String?,
val hasNext: Boolean,
val size: Int
)

data class Transaction(
val transactionId: String,
val transactionDate: String,
val transactionTime: String,
val transactionType: String,
val description: String,
val amount: Int,
val balanceAfter: Int
)

fun MainAccountDetailResponseDto.toDomain(): MainAccountDetail =
MainAccountDetail(
transactions = transactions.map { it.toDomain() },
nextCursor = nextCursor,
hasNext = hasNext,
size = size
)

fun Transaction.toDomain(): DomainTransaction =
DomainTransaction(
transactionId = transactionId,
transactionDate = transactionDate,
transactionTime = transactionTime,
transactionType = transactionType,
description = description,
amount = amount,
balanceAfter = balanceAfter
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.ssafy.tiggle.data.model.piggybank.response

import com.ssafy.tiggle.domain.entity.piggybank.PiggyBankEntry

data class PiggyBankEntriesResponseDto(
val items: List<PiggyBankEntryItem>,
val nextCursor: String?,
val size: Int,
val hasNext: Boolean
) {

}

data class PiggyBankEntryItem(
val id: String,
val type: String,
val amount: Long,
val occurredAt: String,
val title: String
)

fun PiggyBankEntriesResponseDto.toDomain(): List<PiggyBankEntry> =
items.map {
it.toDomain()
}


fun PiggyBankEntryItem.toDomain(): PiggyBankEntry =
PiggyBankEntry(
id = id,
type = type,
amount = amount,
occurredAt = occurredAt,
title = title
)
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package com.ssafy.tiggle.data.repository

import com.ssafy.tiggle.data.datasource.remote.PiggyBankApiService
import com.ssafy.tiggle.data.model.BaseResponse
import com.ssafy.tiggle.data.model.piggybank.request.CreatePiggyBankRequestDto
import com.ssafy.tiggle.data.model.piggybank.request.PiggyBankEntriesRequestDto
import com.ssafy.tiggle.data.model.piggybank.request.PiggyBankSettingRequestDto
import com.ssafy.tiggle.data.model.piggybank.request.PrimaryAccountRequestDto
import com.ssafy.tiggle.data.model.piggybank.request.SendSMSRequestDto
import com.ssafy.tiggle.data.model.piggybank.request.VerificationCheckRequestDto
import com.ssafy.tiggle.data.model.piggybank.request.VerificationRequestDto
import com.ssafy.tiggle.data.model.piggybank.request.VerifySMSRequestDto
import com.ssafy.tiggle.data.model.piggybank.response.PiggyBankEntriesResponseDto
import com.ssafy.tiggle.data.model.piggybank.response.VerifySMSResponseDto
import com.ssafy.tiggle.data.model.piggybank.response.toDomain
import com.ssafy.tiggle.domain.entity.piggybank.AccountHolder
import com.ssafy.tiggle.domain.entity.piggybank.MainAccount
import com.ssafy.tiggle.domain.entity.piggybank.MainAccountDetail
import com.ssafy.tiggle.domain.entity.piggybank.PiggyBank
import com.ssafy.tiggle.domain.entity.piggybank.PiggyBankAccount
import com.ssafy.tiggle.domain.entity.piggybank.PiggyBankEntry
import com.ssafy.tiggle.domain.repository.PiggyBankRepository
import javax.inject.Inject
import javax.inject.Singleton
Expand Down Expand Up @@ -224,4 +229,57 @@ class PiggyBankRepositoryImpl @Inject constructor(
}
}

override suspend fun getTransactions(
accountNo: String,
cursor: String?
): Result<MainAccountDetail> {
return try {
// size, sort 기본값은 스웨거 기본(20, DESC)에 맞춤
val response = piggyBankApiService.getTransactions(
accountNo = accountNo,
cursor = cursor,
size = 20,
sort = "DESC"
)

if (response.result && response.data != null) {
Result.success(response.data.toDomain())
} else {
Result.failure(Exception(response.message ?: "거래내역 조회에 실패했습니다."))
}
} catch (e: Exception) {
Result.failure(e)
}
}

override suspend fun getPiggyBankEntries(
type: String,
cursor: String?,
size: Int?,
from: String?,
to: String?,
sortKey: String?
): Result<List<PiggyBankEntry>> {
return try {
val request = PiggyBankEntriesRequestDto(
type = type,
cursor = cursor,
size = size,
from = from,
to = to,
sortKey = sortKey
)
val response: BaseResponse<PiggyBankEntriesResponseDto> =
piggyBankApiService.getPiggyBankEntries(request)
if (response.result && response.data != null) {
Result.success(response.data.toDomain())
} else {
Result.failure(Exception(response.message ?: "저금 기록 조회에 실패했습니다."))

}
} catch (e: Exception) {
Result.failure(e)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.ssafy.tiggle.domain.entity.piggybank

data class MainAccountDetail(
val transactions: List<DomainTransaction> = emptyList(),
val nextCursor: String? = null,
val hasNext: Boolean = false,
val size: Int = 0
)

data class DomainTransaction(
val transactionId: String = "",
val transactionDate: String = "",
val transactionTime: String = "",
val transactionType: String = "",
val description: String = "",
val amount: Int = 0,
val balanceAfter: Int = 0
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ssafy.tiggle.domain.entity.piggybank

data class PiggyBankEntry(
val id: String = "",
val type: String = "",
val amount: Long = 0L,
val occurredAt: String = "",
val title: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.ssafy.tiggle.domain.repository
import com.ssafy.tiggle.data.model.piggybank.response.VerifySMSResponseDto
import com.ssafy.tiggle.domain.entity.piggybank.AccountHolder
import com.ssafy.tiggle.domain.entity.piggybank.MainAccount
import com.ssafy.tiggle.domain.entity.piggybank.MainAccountDetail
import com.ssafy.tiggle.domain.entity.piggybank.PiggyBank
import com.ssafy.tiggle.domain.entity.piggybank.PiggyBankAccount
import com.ssafy.tiggle.domain.entity.piggybank.PiggyBankEntry

interface PiggyBankRepository {
suspend fun getAccountHolder(accountNo: String): Result<AccountHolder>
Expand Down Expand Up @@ -34,4 +36,18 @@ interface PiggyBankRepository {
): Result<PiggyBank>

suspend fun setEsgCategory(categoryId: Int): Result<PiggyBank>
suspend fun getTransactions(
accountNo: String,
cursor: String? = null
): Result<MainAccountDetail>

suspend fun getPiggyBankEntries(
type: String,
cursor: String? = null,
size: Int? = null,
from: String? = null,
to: String? = null,
sortKey: String? = null
): Result<List<PiggyBankEntry>>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ssafy.tiggle.domain.usecase.piggybank

import com.ssafy.tiggle.domain.entity.piggybank.MainAccountDetail
import com.ssafy.tiggle.domain.repository.PiggyBankRepository
import javax.inject.Inject

class GetMainAccountDetailUseCase @Inject constructor(
private val repository: PiggyBankRepository
) {
suspend operator fun invoke(
accountNo: String,
cursor: String? = null
): Result<MainAccountDetail> {
return repository.getTransactions(accountNo, cursor)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.ssafy.tiggle.domain.usecase.piggybank

import com.ssafy.tiggle.domain.entity.piggybank.PiggyBankEntry
import com.ssafy.tiggle.domain.repository.PiggyBankRepository
import javax.inject.Inject

class GetPiggyBankEntryUseCase @Inject constructor(
private val repository: PiggyBankRepository
) {
suspend operator fun invoke(
type: String,
cursor: String? = null,
size: Int? = null,
from: String? = null,
to: String? = null,
sortKey: String? = null
): Result<List<PiggyBankEntry>> {
return repository.getPiggyBankEntries(
type = type,
cursor = cursor,
size = size,
from = from,
to = to,
sortKey = sortKey
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ data class PiggyBankUseCases @Inject constructor(
val getMainAccountUseCase: GetMainAccountUseCase,
val getPiggyBankAccountUseCase: GetPiggyBankAccountUseCase,
val setPiggyBankSettingUseCase: SetPiggyBankSettingUseCase,
val setEsgCategoryUseCase: SetEsgCategoryUseCase
val setEsgCategoryUseCase: SetEsgCategoryUseCase,
val getMainAccountDetailUseCase: GetMainAccountDetailUseCase,
val getPiggyBankEntryUseCase: GetPiggyBankEntryUseCase
)
Loading