Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mz 123 received envelope list api #104

Merged
merged 6 commits into from
Jan 30, 2024
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
15 changes: 9 additions & 6 deletions core/model/src/main/java/com/susu/core/model/Envelope.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.susu.core.model

import java.time.LocalDateTime
import kotlinx.datetime.LocalDateTime
import kotlinx.serialization.Serializable

@Serializable
data class Envelope(
val id: Long,
val uid: Long,
val type: String,
val friend: Friend,
val amount: Long,
val id: Long = 0,
val uid: Long = 0,
val type: String = "",
val amount: Long = 0,
val gift: String? = null,
val memo: String? = null,
val hasVisited: Boolean? = null,
val handedOverAt: LocalDateTime? = null,
val friend: Friend = Friend(),
val relationship: Relationship = Relationship(),
)
3 changes: 3 additions & 0 deletions core/model/src/main/java/com/susu/core/model/Friend.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.susu.core.model

import kotlinx.serialization.Serializable

@Serializable
data class Friend(
val id: Long = 0,
val uid: Long = 0,
Expand Down
4 changes: 3 additions & 1 deletion core/model/src/main/java/com/susu/core/model/Relationship.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.susu.core.model

import androidx.compose.runtime.Stable
import kotlinx.serialization.Serializable

@Stable
@Serializable
data class Relationship(
val id: Int = -1,
val id: Long = -1,
val relation: String = "",
val customRelation: String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.susu.core.model

data class SearchEnvelope(
val envelope: Envelope = Envelope(),
val category: Category = Category(),
val friend: Friend = Friend(),
val relation: Relationship = Relationship(),
)
2 changes: 2 additions & 0 deletions core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@
<string name="word_free">자유</string>
<string name="content_description_report_button">μ‹ κ³  λ²„νŠΌ</string>
<string name="word_all">전체</string>
<string name="word_visited">λ°©λ¬Έ</string>
<string name="word_not_visited">λ―Έλ°©λ¬Έ</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.susu.data.data.repository
import com.susu.core.model.Envelope
import com.susu.core.model.EnvelopeStatics
import com.susu.core.model.Relationship
import com.susu.core.model.SearchEnvelope
import com.susu.data.remote.api.EnvelopesService
import com.susu.data.remote.model.request.CategoryRequest
import com.susu.data.remote.model.request.EnvelopeRequest
Expand Down Expand Up @@ -65,4 +66,24 @@ class EnvelopesRepositoryImpl @Inject constructor(
},
),
).getOrThrow().toModel()

override suspend fun searchEnvelope(
friendIds: List<Int>?,
ledgerId: Long?,
types: String?,
fromAmount: Long?,
toAmount: Long?,
page: Int?,
size: Int?,
sort: String?,
): List<SearchEnvelope> = envelopesService.searchEnvelope(
friendIds = friendIds,
ledgerId = ledgerId,
types = types,
fromAmount = fromAmount,
toAmount = toAmount,
page = page,
size = size,
sort = sort,
).getOrThrow().toModel()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FriendRepositoryImpl @Inject constructor(
override suspend fun createFriend(
name: String,
phoneNumber: String?,
relationshipId: Int,
relationshipId: Long,
customRelation: String?,
): Long = friendService.createFriend(
FriendRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class LedgerRepositoryImpl @Inject constructor(
ledgerRequest = ledger.toData(),
).getOrThrow().toModel()

override suspend fun getLedger(id: Long): Ledger = ledgerService.getLedger(
id = id,
).getOrThrow().toModel()

override suspend fun deleteLedger(id: Long) = ledgerService.deleteLedgerList(
listOf(id),
).getOrThrow()
Expand Down
18 changes: 16 additions & 2 deletions data/src/main/java/com/susu/data/remote/api/EnvelopesService.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.susu.data.remote.api

import com.susu.data.remote.model.request.EnvelopeRequest
import com.susu.data.remote.model.response.EnvelopeResponse
import com.susu.data.remote.model.response.CreateEnvelopeResponse
import com.susu.data.remote.model.response.EnvelopesListResponse
import com.susu.data.remote.model.response.RelationShipListResponse
import com.susu.data.remote.model.response.SearchEnvelopeResponse
import com.susu.data.remote.retrofit.ApiResult
import retrofit2.http.Body
import retrofit2.http.GET
Expand All @@ -27,5 +28,18 @@ interface EnvelopesService {
@POST("envelopes")
suspend fun createEnvelope(
@Body envelopeRequest: EnvelopeRequest,
): ApiResult<EnvelopeResponse>
): ApiResult<CreateEnvelopeResponse>

@GET("envelopes")
suspend fun searchEnvelope(
@Query("friendIds") friendIds: List<Int>?,
@Query("ledgerId") ledgerId: Long?,
@Query("type") types: String?,
@Query("include") include: String = "CATEGORY,FRIEND,RELATIONSHIP,FRIEND_RELATIONSHIP",
@Query("fromAmount") fromAmount: Long?,
@Query("toAmount") toAmount: Long?,
@Query("page") page: Int?,
@Query("size") size: Int?,
@Query("sort") sort: String?,
): ApiResult<SearchEnvelopeResponse>
}
5 changes: 5 additions & 0 deletions data/src/main/java/com/susu/data/remote/api/LedgerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ interface LedgerService {
@Body ledgerRequest: LedgerRequest,
): ApiResult<LedgerResponse>

@GET("ledgers/{id}")
suspend fun getLedger(
@Path("id") id: Long,
): ApiResult<LedgerResponse>

@DELETE("ledgers")
suspend fun deleteLedgerList(@Query("ids") idList: List<Long>): ApiResult<Unit>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import kotlinx.serialization.Serializable
data class FriendRequest(
val name: String,
val phoneNumber: String? = null,
val relationshipId: Int,
val relationshipId: Long,
val customRelation: String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.susu.data.remote.model.response

import com.susu.core.model.Envelope
import com.susu.core.model.Relationship
import kotlinx.datetime.LocalDateTime
import kotlinx.serialization.Serializable

@Serializable
data class CreateEnvelopeResponse(
val envelope: EnvelopeResponse,
val friend: FriendInfo,
val friendRelationship: FriendRelationShipInfo,
val relationship: RelationshipInfo,
)

@Serializable
data class EnvelopeResponse(
val id: Long,
val uid: Long,
val type: String,
val amount: Long,
val gift: String? = null,
val memo: String? = null,
val hasVisited: Boolean? = null,
val handedOverAt: LocalDateTime? = null,
)

@Serializable
data class FriendRelationShipInfo(
val id: Long,
val friendId: Long,
val relationshipId: Long,
val customRelation: String? = null,
)

@Serializable
data class RelationshipInfo(
val id: Long,
val relation: String,
)

internal fun CreateEnvelopeResponse.toModel() = Envelope(
id = envelope.id,
uid = envelope.uid,
type = envelope.type,
amount = envelope.amount,
gift = envelope.gift,
memo = envelope.memo,
hasVisited = envelope.hasVisited,
handedOverAt = envelope.handedOverAt,
friend = friend.toModel(),
relationship = Relationship(
id = relationship.id,
relation = relationship.relation,
customRelation = friendRelationship.customRelation,
),
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data class Friend(

@Serializable
data class Relationship(
val id: Int,
val id: Long,
val relation: String,
val customRelation: String? = null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class RelationShipListResponse(

@Serializable
data class RelationConfigShipResponse(
val id: Int,
val id: Long,
val relation: String,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.susu.data.remote.model.response

import com.susu.core.model.Relationship
import com.susu.core.model.SearchEnvelope
import kotlinx.datetime.LocalDateTime
import kotlinx.serialization.Serializable

@Serializable
data class SearchEnvelopeResponse(
val data: List<SearchEnvelopeData>,
)

@Serializable
data class SearchEnvelopeData(
val envelope: Envelope,
val category: CategoryInfo,
val friend: FriendInfo,
val relationship: RelationInfo,
val friendRelationship: FriendRelationship,
)

@Serializable
data class Envelope(
val id: Long,
val uid: Long,
val type: String,
val amount: Long,
val gift: String? = null,
val memo: String? = null,
val hasVisited: Boolean? = null,
val handedOverAt: LocalDateTime,
)

@Serializable
data class RelationInfo(
val id: Long,
val relation: String,
)

@Serializable
data class FriendRelationship(
val id: Long,
val friendId: Long,
val relationshipId: Long,
val customRelation: String? = null,
)

internal fun SearchEnvelopeResponse.toModel() = data.map {
SearchEnvelope(
envelope = com.susu.core.model.Envelope(
id = it.envelope.id,
uid = it.envelope.uid,
type = it.envelope.type,
friend = it.friend.toModel(),
amount = it.envelope.amount,
gift = it.envelope.gift,
memo = it.envelope.memo,
hasVisited = it.envelope.hasVisited,
handedOverAt = it.envelope.handedOverAt,
),
category = it.category.toModel(),
friend = it.friend.toModel(),
relation = Relationship(
id = it.relationship.id,
relation = it.relationship.relation,
customRelation = it.friendRelationship.customRelation,
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.susu.domain.repository
import com.susu.core.model.Envelope
import com.susu.core.model.EnvelopeStatics
import com.susu.core.model.Relationship
import com.susu.core.model.SearchEnvelope
import kotlinx.datetime.LocalDateTime

interface EnvelopesRepository {
Expand All @@ -29,4 +30,15 @@ interface EnvelopesRepository {
categoryId: Long? = null,
customCategory: String? = null,
): Envelope

suspend fun searchEnvelope(
friendIds: List<Int>?,
ledgerId: Long?,
types: String?,
fromAmount: Long?,
toAmount: Long?,
page: Int? = null,
size: Int? = null,
sort: String? = null,
): List<SearchEnvelope>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface FriendRepository {
suspend fun createFriend(
name: String,
phoneNumber: String? = null,
relationshipId: Int,
relationshipId: Long,
customRelation: String? = null,
): Long

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ interface LedgerRepository {
id: Long,
)

suspend fun getLedger(
id: Long,
): Ledger

suspend fun getCreateLedgerConfig(): List<Int>
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CreateReceivedEnvelopeUseCase @Inject constructor(
val friendId: Long? = null,
val friendName: String? = null,
val phoneNumber: String? = null,
val relationshipId: Int? = null,
val relationshipId: Long? = null,
val customRelation: String? = null,
val ledgerId: Long,
val amount: Long,
Expand Down
Loading
Loading