Skip to content

Commit

Permalink
refactor: service분리
Browse files Browse the repository at this point in the history
  • Loading branch information
Namyunsuk committed Jul 30, 2024
1 parent 7cd98a7 commit 28165f9
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 66 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package com.zzang.chongdae.data.remote.api

import com.zzang.chongdae.data.remote.dto.request.CommentRequest
import com.zzang.chongdae.data.remote.dto.response.CommentRoomsResponse
import com.zzang.chongdae.data.remote.dto.response.CommentsResponse
import com.zzang.chongdae.data.remote.dto.response.MeetingsResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface CommentDetailApiService {
@GET("/offerings/{offering-id}/meetings")
suspend fun getMeetings(
@Path("offering-id") offeringId: Long,
): Response<MeetingsResponse>

@POST("/comments")
suspend fun postComment(
@Body commentRequest: CommentRequest,
): Response<Unit>
interface CommentsApiService {
@GET("/comments")
suspend fun getCommentRooms(
@Query("member-id") memberId: Long,
): Response<CommentRoomsResponse>

@GET("/comments/{offering-id}")
suspend fun getComments(
@Path("offering-id") offeringId: Long,
@Query("member-id") memberId: Long,
): Response<CommentsResponse>

@POST("/comments")
suspend fun postComment(
@Body commentRequest: CommentRequest,
): Response<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ object NetworkManager {

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

fun offeringDetailService(): OfferingDetailApiService = getRetrofit().create(OfferingDetailApiService::class.java)
fun participatoinsService(): ParticipationsApiService = getRetrofit().create(ParticipationsApiService::class.java)

fun commentDetailService(): CommentDetailApiService = getRetrofit().create(CommentDetailApiService::class.java)

fun commentRoomService(): CommentRoomsApiService = getRetrofit().create(CommentRoomsApiService::class.java)
fun commentsService(): CommentsApiService = getRetrofit().create(CommentsApiService::class.java)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.zzang.chongdae.data.remote.api

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

interface OfferingsApiService {
Expand All @@ -11,4 +14,15 @@ interface OfferingsApiService {
@Query("last-id") lastOfferingId: Long,
@Query("page-size") pageSize: Int,
): Response<OfferingsResponse>

@GET("/offerings/{offering-id}")
suspend fun getOfferingDetail(
@Path("offering-id") offeringId: Long,
@Query("member-id") memberId: Long,
): Response<OfferingDetailResponse>

@GET("/offerings/{offering-id}/meetings")
suspend fun getMeetings(
@Path("offering-id") offeringId: Long,
): Response<MeetingsResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.zzang.chongdae.data.remote.api

import com.zzang.chongdae.data.remote.dto.request.ParticipationRequest
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.POST

interface ParticipationsApiService {
@POST("/participations")
suspend fun postParticipations(
@Body participationRequest: ParticipationRequest,
): Response<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.zzang.chongdae.data.remote.source.impl

import com.zzang.chongdae.data.remote.api.CommentDetailApiService
import com.zzang.chongdae.data.remote.api.CommentsApiService
import com.zzang.chongdae.data.remote.api.OfferingsApiService
import com.zzang.chongdae.data.remote.dto.request.CommentRequest
import com.zzang.chongdae.data.remote.dto.response.CommentsResponse
import com.zzang.chongdae.data.remote.dto.response.MeetingsResponse
import com.zzang.chongdae.data.remote.source.CommentDetailDataSource
import retrofit2.Response

class CommentDetailDataSourceImpl(
private val service: CommentDetailApiService,
private val offeringsApiService: OfferingsApiService,
private val commentsApiService: CommentsApiService,
) : CommentDetailDataSource {
override suspend fun getMeetings(offeringId: Long): Result<MeetingsResponse> {
return runCatching {
val response: Response<MeetingsResponse> = service.getMeetings(offeringId)
val response: Response<MeetingsResponse> = offeringsApiService.getMeetings(offeringId)
if (response.isSuccessful) {
response.body() ?: error("에러 발생: null")
} else {
Expand All @@ -23,7 +25,7 @@ class CommentDetailDataSourceImpl(

override suspend fun saveComment(commentRequest: CommentRequest): Result<Unit> =
runCatching {
service.postComment(commentRequest = commentRequest)
commentsApiService.postComment(commentRequest = commentRequest)
.body() ?: throw IllegalStateException()
}

Expand All @@ -32,7 +34,8 @@ class CommentDetailDataSourceImpl(
memberId: Long,
): Result<CommentsResponse> =
runCatching {
val response: Response<CommentsResponse> = service.getComments(offeringId, memberId)
val response: Response<CommentsResponse> =
commentsApiService.getComments(offeringId, memberId)
if (response.isSuccessful) {
response.body() ?: error("에러 발생: null")
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.zzang.chongdae.data.remote.source.impl

import com.zzang.chongdae.data.remote.api.CommentRoomsApiService
import com.zzang.chongdae.data.remote.api.CommentsApiService
import com.zzang.chongdae.data.remote.dto.response.CommentRoomsResponse
import com.zzang.chongdae.data.remote.source.CommentRoomsDataSource

class CommentRoomsDataSourceImpl(
private val service: CommentRoomsApiService,
private val commentsApiService: CommentsApiService,
) : CommentRoomsDataSource {
override suspend fun fetchCommentRooms(memberId: Long): Result<CommentRoomsResponse> {
return runCatching {
service.getCommentRooms(memberId).body() ?: throw IllegalStateException()
commentsApiService.getCommentRooms(memberId).body() ?: throw IllegalStateException()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package com.zzang.chongdae.data.remote.source.impl

import com.zzang.chongdae.data.remote.api.OfferingDetailApiService
import com.zzang.chongdae.data.remote.api.OfferingsApiService
import com.zzang.chongdae.data.remote.api.ParticipationsApiService
import com.zzang.chongdae.data.remote.dto.request.ParticipationRequest
import com.zzang.chongdae.data.remote.dto.response.OfferingDetailResponse
import com.zzang.chongdae.data.remote.source.OfferingDetailDataSource

class OfferingDetailDataSourceImpl(
private val service: OfferingDetailApiService,
private val offeringsApiService: OfferingsApiService,
private val participationsApiService: ParticipationsApiService,
) : OfferingDetailDataSource {
override suspend fun fetchOfferingDetail(
offeringId: Long,
memberId: Long,
): Result<OfferingDetailResponse> =
runCatching {
service.getOfferingDetail(offeringId = offeringId, memberId = memberId).body()
offeringsApiService.getOfferingDetail(offeringId = offeringId, memberId = memberId)
.body()
?: throw IllegalStateException()
}

override suspend fun saveParticipation(participationRequest: ParticipationRequest): Result<Unit> =
runCatching {
service.postParticipations(participationRequest = participationRequest)
participationsApiService.postParticipations(participationRequest = participationRequest)
.body() ?: throw IllegalStateException()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CommentRoomsFragment : Fragment(), OnCommentRoomClickListener {
private val viewModel by viewModels<CommentRoomsViewModel> {
CommentRoomsViewModel.getFactory(
CommentRoomsRepositoryImpl(
CommentRoomsDataSourceImpl(NetworkManager.commentRoomService()),
CommentRoomsDataSourceImpl(NetworkManager.commentsService()),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class CommentDetailActivity : AppCompatActivity() {
offeringId,
offeringTitle,
CommentDetailRepositoryImpl(
CommentDetailDataSourceImpl(NetworkManager.commentDetailService()),
CommentDetailDataSourceImpl(
NetworkManager.offeringsService(),
NetworkManager.commentsService(),
),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class OfferingDetailActivity : AppCompatActivity() {
OfferingDetailViewModel.getFactory(
offeringId,
OfferingDetailRepositoryImpl(
OfferingDetailDataSourceImpl(NetworkManager.offeringDetailService()),
OfferingDetailDataSourceImpl(
NetworkManager.offeringsService(),
NetworkManager.participatoinsService(),
),
),
)
}
Expand Down

0 comments on commit 28165f9

Please sign in to comment.