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] API 연결 #36

Merged
merged 3 commits into from
Feb 3, 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ac.dnd.bookkeeping.android.data.remote.network.model.error.RegisterReq
import ac.dnd.bookkeeping.android.data.remote.network.model.error.RegisterRes
import ac.dnd.bookkeeping.android.data.remote.network.util.convert
import io.ktor.client.HttpClient
import io.ktor.client.request.delete
import io.ktor.client.request.header
import io.ktor.client.request.post
import io.ktor.client.request.setBody
Expand Down Expand Up @@ -77,7 +78,7 @@ class AuthenticationApi @Inject constructor(
}

suspend fun withdraw(): Result<Unit> {
return client.post("$baseUrl/api/v1/members/me")
return client.delete("$baseUrl/api/v1/members/me")
.convert(errorMessageMapper::map)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ac.dnd.bookkeeping.android.data.remote.network.api

import ac.dnd.bookkeeping.android.data.remote.network.di.AuthHttpClient
import ac.dnd.bookkeeping.android.data.remote.network.environment.BaseUrlProvider
import ac.dnd.bookkeeping.android.data.remote.network.environment.ErrorMessageMapper
import ac.dnd.bookkeeping.android.data.remote.network.model.group.AddGroupReq
import ac.dnd.bookkeeping.android.data.remote.network.model.group.AddGroupRes
import ac.dnd.bookkeeping.android.data.remote.network.model.group.EditGroupReq
import ac.dnd.bookkeeping.android.data.remote.network.model.group.GetGroupListRes
import ac.dnd.bookkeeping.android.data.remote.network.util.convert
import io.ktor.client.HttpClient
import io.ktor.client.request.delete
import io.ktor.client.request.get
import io.ktor.client.request.patch
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import javax.inject.Inject

class GroupApi @Inject constructor(
@AuthHttpClient private val client: HttpClient,
private val baseUrlProvider: BaseUrlProvider,
private val errorMessageMapper: ErrorMessageMapper
) {
private val baseUrl: String
get() = baseUrlProvider.get()

suspend fun addGroup(
name: String
): Result<AddGroupRes> {
return client.post("$baseUrl/api/v1/groups") {
setBody(
AddGroupReq(
name = name
)
)
}.convert(errorMessageMapper::map)
}

suspend fun editGroup(
id: Long,
name: String
): Result<Unit> {
return client.patch("$baseUrl/api/v1/groups/$id") {
setBody(
EditGroupReq(
name = name
)
)
}.convert(errorMessageMapper::map)
}

suspend fun deleteGroup(
id: Long,
): Result<Unit> {
return client.delete("$baseUrl/api/v1/groups/$id")
.convert(errorMessageMapper::map)
}

suspend fun getGroupList(): Result<GetGroupListRes> {
return client.get("$baseUrl/api/v1/groups/me")
.convert(errorMessageMapper::map)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package ac.dnd.bookkeeping.android.data.remote.network.api

import ac.dnd.bookkeeping.android.data.remote.network.di.AuthHttpClient
import ac.dnd.bookkeeping.android.data.remote.network.environment.BaseUrlProvider
import ac.dnd.bookkeeping.android.data.remote.network.environment.ErrorMessageMapper
import ac.dnd.bookkeeping.android.data.remote.network.model.heart.AddHeartReq
import ac.dnd.bookkeeping.android.data.remote.network.model.heart.AddHeartRes
import ac.dnd.bookkeeping.android.data.remote.network.model.heart.AddUnrecordedHeartReq
import ac.dnd.bookkeeping.android.data.remote.network.model.heart.AddUnrecordedHeartRes
import ac.dnd.bookkeeping.android.data.remote.network.model.heart.EditHeartReq
import ac.dnd.bookkeeping.android.data.remote.network.model.heart.GetHeartListRes
import ac.dnd.bookkeeping.android.data.remote.network.model.heart.GetRelatedHeartListRes
import ac.dnd.bookkeeping.android.data.remote.network.util.convert
import io.ktor.client.HttpClient
import io.ktor.client.request.delete
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import io.ktor.client.request.patch
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import kotlinx.datetime.LocalDate
import javax.inject.Inject

class HeartApi @Inject constructor(
@AuthHttpClient private val client: HttpClient,
private val baseUrlProvider: BaseUrlProvider,
private val errorMessageMapper: ErrorMessageMapper
) {
private val baseUrl: String
get() = baseUrlProvider.get()

suspend fun addHeart(
relationId: Long,
give: Boolean,
money: Long,
day: LocalDate,
event: String,
memo: String,
tags: List<String>
): Result<AddHeartRes> {
return client.post("$baseUrl/api/v1/hearts") {
setBody(
AddHeartReq(
relationId = relationId,
give = give,
money = money,
day = day,
event = event,
memo = memo,
tags = tags
)
)
}.convert(errorMessageMapper::map)
}

suspend fun editHeart(
id: Long,
money: Long,
day: LocalDate,
event: String,
memo: String = "",
tags: List<String>
): Result<Unit> {
return client.patch("$baseUrl/api/v1/hearts/$id") {
setBody(
EditHeartReq(
money = money,
day = day,
event = event,
memo = memo,
tags = tags
)
)
}.convert(errorMessageMapper::map)
}

suspend fun deleteHeart(
id: Long,
): Result<Unit> {
return client.delete("$baseUrl/api/v1/hearts/$id")
.convert(errorMessageMapper::map)
}

suspend fun addUnrecordedHeart(
scheduleId: Long,
money: Long,
tags: List<String>
): Result<AddUnrecordedHeartRes> {
return client.post("$baseUrl/api/v1/hearts/unrecorded-schedule") {
setBody(
AddUnrecordedHeartReq(
scheduleId = scheduleId,
money = money,
tags = tags
)
)
}.convert(errorMessageMapper::map)
}

suspend fun getHeartList(
sort: String = "recent",
name: String = ""
): Result<GetHeartListRes> {
return client.get("$baseUrl/api/v1/hearts/me") {
parameter("sort", sort) // recent, intimacy
parameter("name", name)
}.convert(errorMessageMapper::map)
}

suspend fun getRelatedHeartList(
id: Long,
sort: String = "recent"
): Result<GetRelatedHeartListRes> {
return client.get("$baseUrl/api/v1/hearts/me/$id") {
parameter("sort", sort) // recent, old
}.convert(errorMessageMapper::map)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import ac.dnd.bookkeeping.android.data.remote.network.di.NoAuthHttpClient
import ac.dnd.bookkeeping.android.data.remote.network.environment.BaseUrlProvider
import ac.dnd.bookkeeping.android.data.remote.network.environment.ErrorMessageMapper
import ac.dnd.bookkeeping.android.data.remote.network.model.member.CheckNicknameRes
import ac.dnd.bookkeeping.android.data.remote.network.model.member.EditProfileReq
import ac.dnd.bookkeeping.android.data.remote.network.model.member.GetProfileRes
import ac.dnd.bookkeeping.android.data.remote.network.util.convert
import io.ktor.client.HttpClient
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import io.ktor.client.request.patch
import io.ktor.client.request.setBody
import kotlinx.datetime.LocalDate
import javax.inject.Inject

class MemberApi @Inject constructor(
Expand All @@ -27,4 +32,27 @@ class MemberApi @Inject constructor(
parameter("nickname", nickname)
}.convert(errorMessageMapper::map)
}

suspend fun editProfile(
profileImageUrl: String,
nickname: String,
gender: String,
birth: LocalDate
): Result<Unit> {
return client.patch("$baseUrl/api/v1/members/me") {
setBody(
EditProfileReq(
profileImageUrl = profileImageUrl,
nickname = nickname,
gender = gender,
birth = birth
)
)
}.convert(errorMessageMapper::map)
}

suspend fun getProfile(): Result<GetProfileRes> {
return client.get("$baseUrl/api/v1/members/me")
.convert(errorMessageMapper::map)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package ac.dnd.bookkeeping.android.data.remote.network.api

import ac.dnd.bookkeeping.android.data.remote.network.di.AuthHttpClient
import ac.dnd.bookkeeping.android.data.remote.network.environment.BaseUrlProvider
import ac.dnd.bookkeeping.android.data.remote.network.environment.ErrorMessageMapper
import ac.dnd.bookkeeping.android.data.remote.network.model.relation.AddRelationReq
import ac.dnd.bookkeeping.android.data.remote.network.model.relation.AddRelationRes
import ac.dnd.bookkeeping.android.data.remote.network.model.relation.EditRelationReq
import ac.dnd.bookkeeping.android.data.remote.network.model.relation.GetRelationListRes
import ac.dnd.bookkeeping.android.data.remote.network.model.relation.GetRelationRes
import ac.dnd.bookkeeping.android.data.remote.network.util.convert
import io.ktor.client.HttpClient
import io.ktor.client.request.delete
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import io.ktor.client.request.patch
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import javax.inject.Inject

class RelationApi @Inject constructor(
@AuthHttpClient private val client: HttpClient,
private val baseUrlProvider: BaseUrlProvider,
private val errorMessageMapper: ErrorMessageMapper
) {
private val baseUrl: String
get() = baseUrlProvider.get()

suspend fun addRelation(
groupId: Long,
name: String,
imageUrl: String,
memo: String = ""
): Result<AddRelationRes> {
return client.post("$baseUrl/api/v1/relations") {
setBody(
AddRelationReq(
groupId = groupId,
name = name,
imageUrl = imageUrl,
memo = memo
)
)
}.convert(errorMessageMapper::map)
}

suspend fun editRelation(
id: Long,
groupId: Long,
name: String,
imageUrl: String,
memo: String = ""
): Result<Unit> {
return client.patch("$baseUrl/api/v1/relations/$id") {
setBody(
EditRelationReq(
groupId = groupId,
name = name,
imageUrl = imageUrl,
memo = memo
)
)
}.convert(errorMessageMapper::map)
}

suspend fun deleteRelation(
id: Long,
): Result<Unit> {
return client.delete("$baseUrl/api/v1/relations/$id")
.convert(errorMessageMapper::map)
}

suspend fun getRelation(
id: Long
): Result<GetRelationRes> {
return client.get("$baseUrl/api/v1/relations/me/$id")
.convert(errorMessageMapper::map)
}

suspend fun getRelationList(
name: String = ""
): Result<GetRelationListRes> {
return client.get("$baseUrl/api/v1/relations/me") {
parameter("name", name)
}.convert(errorMessageMapper::map)
}
}
Loading
Loading