-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#36 feat: 피드 불러오기 API 및 일반/간단일기 구분 적용
- Loading branch information
Showing
25 changed files
with
245 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/chunbae/narchive/data/remote/api/FeedService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.chunbae.narchive.data.remote.api | ||
|
||
import com.chunbae.narchive.data.remote.response.ResponseFeedData | ||
import retrofit2.Response | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface FeedService { | ||
|
||
@GET("/diaries") | ||
suspend fun getDiaryFeedData( | ||
@Query("page") page : Int | ||
) : Response<ResponseFeedData> | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/chunbae/narchive/data/remote/repository/FeedRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.chunbae.narchive.data.remote.repository | ||
|
||
import com.chunbae.narchive.data.remote.response.ResponseFeedData | ||
import com.chunbae.narchive.domain.repository.FeedRepository | ||
import com.chunbae.narchive.domain.source.FeedSource | ||
import javax.inject.Inject | ||
|
||
class FeedRepositoryImpl @Inject constructor(private val feedSource: FeedSource): FeedRepository { | ||
override suspend fun getFeedData(page: Int): Result<MutableList<ResponseFeedData.ResponseFeedResult>> { | ||
return feedSource.getFeedData(page) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/chunbae/narchive/data/remote/response/ResponseFeedData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.chunbae.narchive.data.remote.response | ||
|
||
import com.chunbae.narchive.presentation.util.BaseResponse | ||
|
||
data class ResponseFeedData ( | ||
val result : List<ResponseFeedResult> | ||
) : BaseResponse() { | ||
data class ResponseFeedResult( | ||
val feedIdx : Int, | ||
val nickName : String, | ||
val profilePath : String, | ||
val updatedAt : String, | ||
val isSimple : String, | ||
val content : String, | ||
val thumbnailPath : String, | ||
val imageCount : Int, | ||
val locationName : String, | ||
val commentCount : Int | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/chunbae/narchive/data/remote/source/FeedRemoteSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.chunbae.narchive.data.remote.source | ||
|
||
import com.chunbae.narchive.data.remote.api.FeedService | ||
import com.chunbae.narchive.data.remote.response.ResponseFeedData | ||
import com.chunbae.narchive.domain.source.FeedSource | ||
import javax.inject.Inject | ||
|
||
class FeedRemoteSource @Inject constructor(private val feedService: FeedService): FeedSource { | ||
override suspend fun getFeedData(page: Int): Result<MutableList<ResponseFeedData.ResponseFeedResult>> { | ||
val res = feedService.getDiaryFeedData(page) | ||
if (res.isSuccessful) { | ||
return Result.success(res.body()!!.result as MutableList) | ||
} | ||
return Result.failure(IllegalArgumentException(res.message())) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/chunbae/narchive/domain/repository/FeedRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.chunbae.narchive.domain.repository | ||
|
||
import com.chunbae.narchive.data.remote.response.ResponseFeedData | ||
|
||
interface FeedRepository { | ||
|
||
suspend fun getFeedData(page : Int) : Result<MutableList<ResponseFeedData.ResponseFeedResult>> | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/chunbae/narchive/domain/source/FeedSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.chunbae.narchive.domain.source | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import com.chunbae.narchive.data.remote.response.ResponseFeedData | ||
|
||
interface FeedSource { | ||
|
||
suspend fun getFeedData(page : Int) : Result<MutableList<ResponseFeedData.ResponseFeedResult>> | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/chunbae/narchive/domain/usecase/DiaryUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.chunbae.narchive.domain.usecase | ||
|
||
import com.chunbae.narchive.data.data.FeedData | ||
import com.chunbae.narchive.data.data.LocationData | ||
|
||
interface DiaryUseCase { | ||
|
||
suspend fun postMapping(content : String, locationData: LocationData?, images : MutableList<String>?) : Result<String> | ||
|
||
suspend fun getMapping(page : Int) : Result<MutableList<FeedData>> | ||
} |
64 changes: 64 additions & 0 deletions
64
app/src/main/java/com/chunbae/narchive/domain/usecase/DiaryUseCaseImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.chunbae.narchive.domain.usecase | ||
|
||
import com.chunbae.narchive.data.data.FeedData | ||
import com.chunbae.narchive.data.data.LocationData | ||
import com.chunbae.narchive.data.data.UserData | ||
import com.chunbae.narchive.data.remote.request.RequestNormalDiaryData | ||
import com.chunbae.narchive.data.remote.response.ResponseFeedData | ||
import com.chunbae.narchive.domain.repository.FeedRepository | ||
import com.chunbae.narchive.domain.repository.NormalDiaryRepository | ||
import javax.inject.Inject | ||
|
||
class DiaryUseCaseImpl @Inject constructor( | ||
private val repo: NormalDiaryRepository, | ||
private val feedRepo: FeedRepository | ||
) : DiaryUseCase { | ||
|
||
override suspend fun postMapping( | ||
content: String, | ||
locationData: LocationData?, | ||
images: MutableList<String>? | ||
): Result<String> { | ||
return repo.postNormalDiary(content.mapToRequest(locationData, images)) | ||
} | ||
|
||
override suspend fun getMapping(page: Int): Result<MutableList<FeedData>> { | ||
return feedRepo.getFeedData(page).map { it.mapToFeedData() } | ||
} | ||
|
||
|
||
private fun String.mapToRequest( | ||
locationData: LocationData?, | ||
images: MutableList<String>? | ||
): RequestNormalDiaryData { | ||
return RequestNormalDiaryData( | ||
this, | ||
locationData?.place_name, | ||
locationData?.road_address_name, | ||
locationData?.x?.toDouble(), | ||
locationData?.y?.toDouble(), | ||
images | ||
) | ||
} | ||
|
||
private fun MutableList<ResponseFeedData.ResponseFeedResult>.mapToFeedData(): MutableList<FeedData> { | ||
val returnList = mutableListOf<FeedData>() | ||
this.forEach { | ||
returnList.add( | ||
FeedData( | ||
feedIdx = it.feedIdx, | ||
user = UserData(0, it.profilePath, it.nickName), | ||
uploadedAt = it.updatedAt, | ||
content = if(it.isSimple == "F") it.content else null, | ||
keywords = if(it.isSimple == "T") it.content.split(",") else null, | ||
thumbNail = it.thumbnailPath, | ||
imageCount = it.imageCount, | ||
locationAddress = it.locationName, | ||
commentCount = it.commentCount, | ||
isSimple = it.isSimple | ||
) | ||
) | ||
} | ||
return returnList | ||
} | ||
} |
8 changes: 0 additions & 8 deletions
8
app/src/main/java/com/chunbae/narchive/domain/usecase/NormalDiaryUseCase.kt
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
app/src/main/java/com/chunbae/narchive/domain/usecase/NormalDiaryUseCaseImpl.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
app/src/main/java/com/chunbae/narchive/presentation/di/module/UseCaseModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
package com.chunbae.narchive.presentation.di.module | ||
|
||
import com.chunbae.narchive.domain.usecase.NormalDiaryUseCase | ||
import com.chunbae.narchive.domain.usecase.NormalDiaryUseCaseImpl | ||
import com.chunbae.narchive.domain.usecase.DiaryUseCase | ||
import com.chunbae.narchive.domain.usecase.DiaryUseCaseImpl | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class UseCaseModule { | ||
@Binds | ||
abstract fun bindNormalDiaryUseCase(normalDiaryUseCaseImpl : NormalDiaryUseCaseImpl): NormalDiaryUseCase | ||
abstract fun bindDiaryUseCase(diaryUseCaseImpl : DiaryUseCaseImpl): DiaryUseCase | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.