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

feat: 홈화면 API 연결 #74

Merged
merged 6 commits into from
Jul 24, 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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.zzang.chongdae.data.mapper

import com.zzang.chongdae.data.remote.dto.response.RemoteOffering
import com.zzang.chongdae.domain.model.Offering

fun RemoteOffering.toDomain() =
Offering(
id = this.id,
title = this.title,
meetingAddress = this.meetingAddress,
thumbnailUrl = this.thumbnailUrl,
totalCount = this.totalCount,
currentCount = this.currentCount,
dividedPrice = this.dividedPrice,
condition = this.condition.toDomain(),
isOpen = this.isOpen,
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object NetworkManager {
return instance!!
}

fun service(): GroupPurchaseApiService = getRetrofit().create(GroupPurchaseApiService::class.java)
fun offeringsService(): OfferingsApiService = getRetrofit().create(OfferingsApiService::class.java)

fun offeringDetailService(): OfferingDetailApiService = getRetrofit().create(OfferingDetailApiService::class.java)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.zzang.chongdae.data.remote.api

import com.zzang.chongdae.data.remote.dto.request.ParticipationRequest
import com.zzang.chongdae.data.remote.dto.response.OfferingDetailResponse
import com.zzang.chongdae.data.remote.dto.response.ParticipationResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
Expand All @@ -20,5 +19,5 @@ interface OfferingDetailApiService {
@POST("/participations")
suspend fun postParticipations(
@Body participationRequest: ParticipationRequest,
): Response<ParticipationResponse>
): Response<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.zzang.chongdae.data.remote.api

import com.zzang.chongdae.data.remote.dto.response.OfferingsResponse
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query

interface OfferingsApiService {
@GET("/offerings")
suspend fun getArticles(
@Query("last-id") lastOfferingId: Long,
@Query("page-size") pageSize: Int,
): Response<OfferingsResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class OfferingDetailResponse(
@SerialName("deadline") val deadline: String,
@SerialName("currentCount") val currentCount: Int,
@SerialName("totalCount") val totalCount: Int,
@SerialName("thumbnailUrl") val thumbnailUrl: String,
@SerialName("thumbnailUrl") val thumbnailUrl: String?,
@SerialName("dividedPrice") val dividedPrice: Int,
@SerialName("totalPrice") val totalPrice: Int,
@SerialName("condition") val condition: RemoteOfferingCondition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class GroupPurchasesResponse(
@SerialName("responses") val responses: List<GroupPurchase>,
data class OfferingsResponse(
@SerialName("offerings") val offerings: List<RemoteOffering>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class GroupPurchase(
data class RemoteOffering(
@SerialName("id") val id: Long,
@SerialName("title") val title: String,
@SerialName("meetingAddress") val meetingAddress: String,
@SerialName("deadline") val deadline: String,
@SerialName("currentCount") val currentCount: Int,
@SerialName("totalCount") val totalCount: Int,
@SerialName("thumbnailUrl") val thumbnailUrl: String,
@SerialName("thumbnailUrl") val thumbnailUrl: String?,
@SerialName("dividedPrice") val dividedPrice: Int,
@SerialName("isClosed") val isClosed: Boolean,
@SerialName("condition") val condition: RemoteOfferingCondition,
@SerialName("isOpen") val isOpen: Boolean,
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package com.zzang.chongdae.data.remote.source

import com.zzang.chongdae.data.remote.dto.request.ParticipationRequest
import com.zzang.chongdae.data.remote.dto.response.OfferingDetailResponse
import com.zzang.chongdae.data.remote.dto.response.ParticipationResponse

interface OfferingDetailDataSource {
suspend fun fetchOfferingDetail(
offeringId: Long,
memberId: Long,
): Result<OfferingDetailResponse>

suspend fun saveParticipation(participationRequest: ParticipationRequest): Result<ParticipationResponse>
suspend fun saveParticipation(participationRequest: ParticipationRequest): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.zzang.chongdae.data.remote.source

import com.zzang.chongdae.data.remote.dto.response.OfferingsResponse

interface OfferingsDataSource {
suspend fun fetchOfferings(
lastOfferingId: Long,
pageSize: Int,
): Result<OfferingsResponse>
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.zzang.chongdae.data.remote.source.impl
import com.zzang.chongdae.data.remote.api.OfferingDetailApiService
import com.zzang.chongdae.data.remote.dto.request.ParticipationRequest
import com.zzang.chongdae.data.remote.dto.response.OfferingDetailResponse
import com.zzang.chongdae.data.remote.dto.response.ParticipationResponse
import com.zzang.chongdae.data.remote.source.OfferingDetailDataSource

class OfferingDetailDataSourceImpl(
Expand All @@ -18,7 +17,7 @@ class OfferingDetailDataSourceImpl(
?: throw IllegalStateException()
}

override suspend fun saveParticipation(participationRequest: ParticipationRequest): Result<ParticipationResponse> =
override suspend fun saveParticipation(participationRequest: ParticipationRequest): Result<Unit> =
runCatching {
service.postParticipations(participationRequest = participationRequest)
.body() ?: throw IllegalStateException()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.zzang.chongdae.data.remote.source.impl

import com.zzang.chongdae.data.remote.api.OfferingsApiService
import com.zzang.chongdae.data.remote.dto.response.OfferingsResponse
import com.zzang.chongdae.data.remote.source.OfferingsDataSource

class OfferingsDataSourceImpl(
private val service: OfferingsApiService,
) : OfferingsDataSource {
override suspend fun fetchOfferings(
lastOfferingId: Long,
pageSize: Int,
): Result<OfferingsResponse> =
runCatching {
service.getArticles(lastOfferingId, pageSize).body() ?: throw IllegalStateException()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.zzang.chongdae.data.mapper.toDomain
import com.zzang.chongdae.data.remote.dto.request.ParticipationRequest
import com.zzang.chongdae.data.remote.source.OfferingDetailDataSource
import com.zzang.chongdae.domain.model.OfferingDetail
import com.zzang.chongdae.domain.model.Participation
import com.zzang.chongdae.domain.repository.OfferingDetailRepository

class OfferingDetailRepositoryImpl(
Expand All @@ -24,10 +23,8 @@ class OfferingDetailRepositoryImpl(
override suspend fun saveParticipation(
memberId: Long,
offeringId: Long,
): Result<Participation> =
): Result<Unit> =
offeringDetailDataSource.saveParticipation(
participationRequest = ParticipationRequest(memberId, offeringId),
).mapCatching {
it.toDomain()
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.zzang.chongdae.data.repository.remote

import com.zzang.chongdae.data.mapper.toDomain
import com.zzang.chongdae.data.remote.source.OfferingsDataSource
import com.zzang.chongdae.domain.model.Offering
import com.zzang.chongdae.domain.repository.OfferingsRepository

class OfferingsRepositoryImpl(
private val offeringsDataSource: OfferingsDataSource,
) : OfferingsRepository {
override suspend fun fetchOfferings(
lastOfferingId: Long,
pageSize: Int,
): Result<List<Offering>> {
return offeringsDataSource.fetchOfferings(lastOfferingId, pageSize).mapCatching {
it.offerings.map { it.toDomain() }
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.zzang.chongdae.domain.model

import java.time.LocalDateTime

data class Article(
data class Offering(
val id: Long,
val thumbnailUrl: String,
val deadline: LocalDateTime,
val title: String,
val meetingAddress: String,
val splitPrice: Int,
val thumbnailUrl: String?,
val totalCount: Int,
val currentCount: Int,
val isClosed: Boolean,
val dividedPrice: Int,
val condition: OfferingCondition,
val isOpen: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class OfferingDetail(
val nickname: String,
val memberId: String,
val productUrl: String,
val thumbnailUrl: String,
val thumbnailUrl: String?,
val dividedPrice: Int,
val totalPrice: Int,
val deadline: LocalDateTime,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.zzang.chongdae.domain.repository

import com.zzang.chongdae.domain.model.OfferingDetail
import com.zzang.chongdae.domain.model.Participation

interface OfferingDetailRepository {
suspend fun fetchOfferingDetail(
Expand All @@ -12,5 +11,5 @@ interface OfferingDetailRepository {
suspend fun saveParticipation(
memberId: Long,
offeringId: Long,
): Result<Participation>
): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.zzang.chongdae.domain.repository

import com.zzang.chongdae.domain.model.Offering

interface OfferingsRepository {
suspend fun fetchOfferings(
lastOfferingId: Long,
pageSize: Int,
): Result<List<Offering>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,45 @@ fun ImageView.setImageResource(imageUrl: String?) {
}
}

@BindingAdapter("offeringsProductImageUrl")
fun ImageView.setOfferingsProductImageResource(imageUrl: String?) {
imageUrl.let {
Glide.with(context)
.load(it)
.error(R.drawable.img_main_product_default)
.fallback(R.drawable.img_main_product_default)
.into(this)
}
}

@BindingAdapter("offeringCondition")
fun TextView.bindConditionText(offeringCondition: OfferingCondition?) {
offeringCondition?.toStyle()?.let {
this.setTextAppearance(it)
}

offeringCondition?.let {
this.text = it.toComment(context)
this.setTextAppearance(it.toStyle())
}
}

private fun OfferingCondition.toComment(context: Context) =
when (this) {
OfferingCondition.FULL -> context.getString(R.string.main_offering_full) // 인원 만석
OfferingCondition.TIME_OUT -> context.getString(R.string.main_offering_closed) // 공구마감
OfferingCondition.CONFIRMED -> context.getString(R.string.main_offering_closed) // 공구마감
OfferingCondition.AVAILABLE -> context.getString(R.string.main_offering_continue) // 모집중
}

private fun OfferingCondition.toStyle() =
when (this) {
OfferingCondition.FULL -> R.style.Theme_AppCompat_TextView_Offering_Full // 인원 만석
OfferingCondition.TIME_OUT -> R.style.Theme_AppCompat_TextView_Offering_Closed // 공구마감
OfferingCondition.CONFIRMED -> R.style.Theme_AppCompat_TextView_Offering_Closed // 공구마감
OfferingCondition.AVAILABLE -> R.style.Theme_AppCompat_TextView_Offering_Continue // 모집중
}

@BindingAdapter("isVisible")
fun View.setIsVisible(isVisible: Boolean) {
visibility = if (isVisible) View.VISIBLE else View.GONE
Expand Down
Loading
Loading