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

refactor : MatchApiService 하나로 통일 #232

Merged
merged 2 commits into from
Oct 15, 2023
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 @@ -15,42 +15,37 @@ import online.partyrun.partyrunapplication.core.network.model.request.RunningDis
import online.partyrun.partyrunapplication.core.network.model.response.CancelMatchResponse
import online.partyrun.partyrunapplication.core.network.model.response.MatchInfoResponse
import online.partyrun.partyrunapplication.core.network.service.MatchApiService
import online.partyrun.partyrunapplication.core.network.service.MatchDecisionApiService
import online.partyrun.partyrunapplication.core.network.service.WaitingMatchApiService
import timber.log.Timber
import javax.inject.Inject

class MatchDataSourceImpl @Inject constructor(
@SSEOkHttpClient private val okHttpClient: OkHttpClient,
@SSERequestBuilder private val request: Request.Builder,
private val waitingMatchApiService: WaitingMatchApiService,
private val matchDecisionApiService: MatchDecisionApiService,
private val matchApiService: MatchApiService
) : MatchDataSource {
private lateinit var matchEventSource: EventSource
private lateinit var matchResultSource: EventSource

override suspend fun registerMatch(runningDistanceRequest: RunningDistanceRequest): ApiResponse<MatchStatusResponse> =
waitingMatchApiService.registerMatch(runningDistanceRequest)
matchApiService.registerMatch(runningDistanceRequest)

override suspend fun acceptMatch(matchDecisionRequest: MatchDecisionRequest): ApiResponse<MatchStatusResponse> =
matchDecisionApiService.acceptMatch(matchDecisionRequest)
matchApiService.acceptMatch(matchDecisionRequest)

override suspend fun declineMatch(matchDecisionRequest: MatchDecisionRequest): ApiResponse<MatchStatusResponse> =
matchDecisionApiService.declineMatch(matchDecisionRequest)
matchApiService.declineMatch(matchDecisionRequest)

override suspend fun getRunnerIds(): ApiResponse<MatchInfoResponse> =
matchApiService.getRunnerIds()

override suspend fun cancelMatchWaitingEvent(): ApiResponse<CancelMatchResponse> =
matchApiService.cancelMatchWaitingEvent()


override fun createMatchEventSourceListener(
onEvent: (data: String) -> Unit,
onClosed: () -> Unit,
onFailure: () -> Unit
) : EventSourceListener {
): EventSourceListener {
return createEventListener(onEvent, onClosed, onFailure)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import online.partyrun.partyrunapplication.core.network.service.ResultApiService
import online.partyrun.partyrunapplication.core.network.service.MatchDecisionApiService
import online.partyrun.partyrunapplication.core.network.service.MemberApiService
import online.partyrun.partyrunapplication.core.network.service.BattleApiService
import online.partyrun.partyrunapplication.core.network.service.MatchApiService
import online.partyrun.partyrunapplication.core.network.service.PartyApiService
import online.partyrun.partyrunapplication.core.network.service.SignInApiService
import online.partyrun.partyrunapplication.core.network.service.SingleApiService
import online.partyrun.partyrunapplication.core.network.service.WaitingMatchApiService
import retrofit2.Retrofit
import retrofit2.Retrofit.Builder
import javax.inject.Singleton

@Module
Expand All @@ -30,22 +27,6 @@ object ApiServiceModule {
.build()
.create(SignInApiService::class.java)

@Singleton
@Provides
fun provideWaitingMatchApiService(@RESTOkHttpClient okHttpClient: OkHttpClient, retrofit: Builder): WaitingMatchApiService =
retrofit
.client(okHttpClient)
.build()
.create(WaitingMatchApiService::class.java)

@Singleton
@Provides
fun provideMatchDecisionApiService(@RESTOkHttpClient okHttpClient: OkHttpClient, retrofit: Builder): MatchDecisionApiService =
retrofit
.client(okHttpClient)
.build()
.create(MatchDecisionApiService::class.java)

@Singleton
@Provides
fun provideResultApiService(@RESTOkHttpClient okHttpClient: OkHttpClient, retrofit: Retrofit.Builder): ResultApiService =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ import online.partyrun.partyrunapplication.core.network.datasource.SingleDataSou
import online.partyrun.partyrunapplication.core.network.service.BattleApiService
import online.partyrun.partyrunapplication.core.network.service.MatchApiService
import online.partyrun.partyrunapplication.core.network.service.ResultApiService
import online.partyrun.partyrunapplication.core.network.service.MatchDecisionApiService
import online.partyrun.partyrunapplication.core.network.service.MemberApiService
import online.partyrun.partyrunapplication.core.network.service.PartyApiService
import online.partyrun.partyrunapplication.core.network.service.SignInApiService
import online.partyrun.partyrunapplication.core.network.service.SingleApiService
import online.partyrun.partyrunapplication.core.network.service.WaitingMatchApiService
import javax.inject.Singleton

@Module
Expand All @@ -40,15 +38,11 @@ object DataSourceModule {
fun provideMatchDataSource(
@SSEOkHttpClient okHttpClient: OkHttpClient,
@SSERequestBuilder request: Request.Builder,
waitingMatchApiService: WaitingMatchApiService,
matchDecisionApiService: MatchDecisionApiService,
matchApiService: MatchApiService
): MatchDataSource {
return MatchDataSourceImpl(
okHttpClient,
request,
waitingMatchApiService,
matchDecisionApiService,
matchApiService
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
package online.partyrun.partyrunapplication.core.network.service

import online.partyrun.partyrunapplication.core.common.network.ApiResponse
import online.partyrun.partyrunapplication.core.network.model.request.MatchDecisionRequest
import online.partyrun.partyrunapplication.core.network.model.request.RunningDistanceRequest
import online.partyrun.partyrunapplication.core.network.model.response.CancelMatchResponse
import online.partyrun.partyrunapplication.core.network.model.response.MatchInfoResponse
import online.partyrun.partyrunapplication.core.network.model.response.MatchStatusResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST

interface MatchApiService {
@POST("/api/waiting")
suspend fun registerMatch(
@Body body: RunningDistanceRequest
): ApiResponse<MatchStatusResponse>

@POST("/api/matching/members/join")
suspend fun acceptMatch(
@Body body: MatchDecisionRequest
): ApiResponse<MatchStatusResponse>

@POST("/api/matching/members/join")
suspend fun declineMatch(
@Body body: MatchDecisionRequest
): ApiResponse<MatchStatusResponse>

@GET("/api/matching/recent/members")
suspend fun getRunnerIds(): ApiResponse<MatchInfoResponse>
Expand Down

This file was deleted.

This file was deleted.