Skip to content

Commit

Permalink
#36 feat: 피드 불러오기 API 및 일반/간단일기 구분 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunBaee committed May 24, 2023
1 parent a7f349d commit f13ff60
Show file tree
Hide file tree
Showing 25 changed files with 245 additions and 107 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/chunbae/narchive/data/data/FeedData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ data class FeedData(
val user : UserData,
val uploadedAt : String,
val content : String?,/** 일반 일기 작성시 사용됨 */
val thumbNail : String, //TODO: 추후 서버 연결시 String으로 변경할 것
val thumbNail : String?, //TODO: 추후 서버 연결시 String으로 변경할 것
val imageCount : Int,
val locationAddress : String,
val locationAddress : String?,
val commentCount : Int,
val keywords : List<String>?,/** 간단 일기 작성시 사용됨 */
val isSimple : String /** T / F */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.chunbae.narchive.data.data

data class UserData(
val userIdx : Int,
val userProfileImage : Int, //TODO: 추후 서버 연결시 String으로 변경할 것
val userProfileImage : String,
val userNickName : String
)
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>
}
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)
}
}
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
)
}
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()))
}
}
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>>
}
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>>
}
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>>
}
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
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.chunbae.narchive.presentation.di.module

import com.chunbae.narchive.data.remote.repository.AuthRepositoryImpl
import com.chunbae.narchive.data.remote.repository.FeedRepositoryImpl
import com.chunbae.narchive.data.remote.repository.FirebaseRepositoryImpl
import com.chunbae.narchive.data.remote.repository.KakaoAiDiaryRepositoryImpl
import com.chunbae.narchive.data.remote.repository.KakaoBookSearchRepositoryImpl
import com.chunbae.narchive.data.remote.repository.KakaoLocationSearchRepositoryImpl
import com.chunbae.narchive.data.remote.repository.NormalDiaryRepositoryImpl
import com.chunbae.narchive.data.remote.repository.ProfileRepositoryImpl
import com.chunbae.narchive.domain.repository.AuthRepository
import com.chunbae.narchive.domain.repository.FeedRepository
import com.chunbae.narchive.domain.repository.FirebaseRepository
import com.chunbae.narchive.domain.repository.KakaoAiDiaryRepository
import com.chunbae.narchive.domain.repository.KakaoBookSearchRepository
Expand Down Expand Up @@ -43,4 +45,7 @@ abstract class RepositoryModule {

@Binds
abstract fun bindProfileRepository(profileRepositoryImpl: ProfileRepositoryImpl) : ProfileRepository

@Binds
abstract fun bindFeedRepository(feedRepositoryImpl: FeedRepositoryImpl) : FeedRepository
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.chunbae.narchive.presentation.di.module

import com.chunbae.narchive.data.remote.api.AuthService
import com.chunbae.narchive.data.remote.api.FeedService
import com.chunbae.narchive.data.remote.api.KakaoAiService
import com.chunbae.narchive.data.remote.api.KakaoService
import com.chunbae.narchive.data.remote.api.NormalDiaryService
Expand Down Expand Up @@ -46,4 +47,8 @@ class ServiceModule {
@Singleton
fun provideProfileService(@NarchiveRetrofit retrofit : Retrofit) : ProfileService = retrofit.create(ProfileService::class.java)

@Provides
@Singleton
fun provideFeedService(@NarchiveRetrofit retrofit: Retrofit) : FeedService = retrofit.create(FeedService::class.java)

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.chunbae.narchive.presentation.di.module

import com.chunbae.narchive.data.remote.source.AuthRemoteSource
import com.chunbae.narchive.data.remote.source.FeedRemoteSource
import com.chunbae.narchive.data.remote.source.FirebaseStorageRemoteSource
import com.chunbae.narchive.data.remote.source.KakaoAiDiaryRemoteSource
import com.chunbae.narchive.data.remote.source.KakaoBookSearchRemoteSource
import com.chunbae.narchive.data.remote.source.KakaoLocationSearchRemoteSource
import com.chunbae.narchive.data.remote.source.NormalDiaryRemoteSource
import com.chunbae.narchive.data.remote.source.ProfileRemoteSource
import com.chunbae.narchive.domain.source.AuthSource
import com.chunbae.narchive.domain.source.FeedSource
import com.chunbae.narchive.domain.source.FirebaseStorageSource
import com.chunbae.narchive.domain.source.KakaoAiDiarySource
import com.chunbae.narchive.domain.source.KakaoBookSearchSource
Expand Down Expand Up @@ -43,4 +45,7 @@ abstract class SourceModule {

@Binds
abstract fun bindProfileRemoteSource(profileRemoteSource: ProfileRemoteSource) : ProfileSource

@Binds
abstract fun bindFeedRemoteSource(feedRemoteSource: FeedRemoteSource) : FeedSource
}
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import com.chunbae.narchive.presentation.ui.comment.adapter.CommentAdapter

class DiaryCommentActivity : AppCompatActivity() {

private lateinit var binding : ActivityDiaryCommentBinding
private lateinit var binding: ActivityDiaryCommentBinding
private val commentAdapter by lazy {
CommentAdapter(getCommentDummies())

}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_diary_comment)
Expand All @@ -31,29 +32,13 @@ class DiaryCommentActivity : AppCompatActivity() {
}

private fun initBinding() {
binding.commentData = getCommentDummy()

}

private fun initComment() {
val dividerItemDecoration = DividerItemDecoration(this, LinearLayoutManager.VERTICAL)
binding.diaryCommentRvComments.addItemDecoration(dividerItemDecoration)
binding.diaryCommentRvComments.adapter = commentAdapter
// binding.diaryCommentRvComments.adapter = commentAdapter

}


/** Dummy */

private fun getCommentDummy() : CommentData =
CommentData(UserData(0, R.drawable.ic_launcher_background, "춘배"), "3일 전", "어제는 지연이와 함께 찜질방에 다녀왔다!\n요근래 찜질방에 갔던적이 없었는데 역시 따뜻한 물에 들어가있으니까\n" +
"피로가 쫙 풀리는 기분이었다!\n근데 음식값이 생각보다 비싸서 그건 좀 아쉬웠다..\n" +
"계란이 개당 천원꼴에 치킨이 3만원이라니..\n" +
"그나마 식혜가 제일 합리적이었다\n그래도 음식 가격만 제외하면 정말 잘 놀다 왔다!\n대만족!", getCommentDummies())

private fun getCommentDummies() : MutableList<Comment> =
mutableListOf<Comment>().apply {
for(i in 0 until 10) {
add(Comment(i, UserData(0, R.drawable.ic_launcher_background, "춘배"), "$i 번째 댓글", "$i 일 전"))
}
}
}
Loading

0 comments on commit f13ff60

Please sign in to comment.