Skip to content

Commit

Permalink
Merge pull request #232 from SWM-KAWAI-MANS/refactor/match_service
Browse files Browse the repository at this point in the history
refactor : MatchApiService 하나로 통일
  • Loading branch information
nohjunh authored Oct 15, 2023
2 parents a191aea + 1c3ce9e commit f1bc16a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 67 deletions.
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.

0 comments on commit f1bc16a

Please sign in to comment.