Skip to content

Commit

Permalink
[LH-112] Link board api to the fragment #16
Browse files Browse the repository at this point in the history
  • Loading branch information
flash159483 committed Aug 7, 2023
1 parent 34d95d3 commit 82c95ce
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,31 @@ package com.lighthouse.android.data.api
import com.lighthouse.android.data.model.BaseResponse
import com.lighthouse.android.data.model.BoardDTO
import retrofit2.Response
import retrofit2.http.Field
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface BoardApiService {
@GET("api/v1/question/[category]")
@GET("api/board/v1/question/{category}")
suspend fun getQuestion(
@Path("category") category: Int,
order: String,
@Query("order") order: String,
@Query("page") page: Int,
): Response<BaseResponse<BoardDTO>>

@POST("api/board/v1/question")
suspend fun uploadQuestion(
@Field("memberId") userId: Int,
@Field("categoryId") categoryId: Int,
@Field("content") content: String,
): Response<BaseResponse<String>>

@POST("api/board/v1/question/{questionId}/addLike")
suspend fun updateLike(
@Path("questionId") questionId: Int,
@Field("memberId") memberId: Int,
): Response<BaseResponse<String>>

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,28 @@ data class BoardQuestionDTO(
@SerializedName("questionId")
val questionId: Int?,
@SerializedName("userId")
val userId: Int?,
val memberId: Int?,
@SerializedName("categoryId")
val categoryId: Int?,
@SerializedName("profileImage")
val profileImage: String?,
@SerializedName("name")
val name: String?,
@SerializedName("region")
val region: String?,
@SerializedName("contents")
val contents: String?,
@SerializedName("like")
val like: Int?,
) {
fun toVO() = BoardQuestionVO(
questionId = questionId ?: -1,
userId = userId ?: -1,
memberId = memberId ?: -1,
categoryId = categoryId ?: -1,
contents = contents ?: " ",
profileImage = profileImage ?: " ",
name = name ?: " ",
region = region ?: " ",
like = like ?: -1
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ data class ProfileDTO(
@SerializedName("profileImage")
val profileImage: String?,
@SerializedName("languages")
val language: List<LanguageDTO>?,
val languages: List<LanguageDTO>?,
@SerializedName("name")
val name: String?,
@SerializedName("region")
val region: String?,
@SerializedName("interests")
val interests: Map<String, List<String>>,
) {
fun toVO() =
ProfileVO(
id ?: -1,
description ?: "",
profileImage ?: "",
language?.map { it.toVO() } ?: listOf(),
languages?.map { it.toVO() } ?: listOf(),
name ?: "",
region ?: ""
region ?: "",
interests ?: mapOf()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,24 @@ class BoardRepositoryImpl @Inject constructor(
else -> Resource.Error(it.message ?: "No message found")
}
}

override fun uploadQuestion(
memberId: Int,
category: Int,
content: String,
): Flow<Resource<String>> =
datasource.uploadQuestion(memberId, category, content).map {
when (it) {
is Resource.Success -> Resource.Success(it.data!!)
else -> Resource.Error(it.message ?: "No message Found")
}
}

override fun updateLike(questionId: Int, memberId: Int): Flow<Resource<String>> =
datasource.updateLike(questionId, memberId).map {
when (it) {
is Resource.Success -> Resource.Success(it.data!!)
else -> Resource.Error(it.message ?: "No message Found")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ import kotlinx.coroutines.flow.Flow

interface BoardRemoteDataSource {
fun getBoardQuestions(category: Int, order: String, page: Int): Flow<Resource<BoardDTO>>
fun uploadQuestion(memberId: Int, categoryId: Int, content: String): Flow<Resource<String>>
fun updateLike(questionId: Int, memberId: Int): Flow<Resource<String>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,16 @@ class BoardRemoteDataSourceImpl @Inject constructor(
): Flow<Resource<BoardDTO>> = flow {
emit(changeResult(api.getQuestion(category, order, page)))
}

override fun uploadQuestion(
memberId: Int,
categoryId: Int,
content: String,
): Flow<Resource<String>> = flow {
emit(changeResult(api.uploadQuestion(memberId, categoryId, content)))
}

override fun updateLike(questionId: Int, memberId: Int): Flow<Resource<String>> = flow {
emit(changeResult(api.updateLike(questionId, memberId)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ import kotlinx.coroutines.flow.Flow

interface BoardRepository {
fun getBoardQuestions(category: Int, order: String, page: Int): Flow<Resource<BoardVO>>
fun uploadQuestion(memberId: Int, category: Int, content: String): Flow<Resource<String>>
fun updateLike(questionId: Int, memberId: Int): Flow<Resource<String>>
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.lighthouse.domain.response.vo


data class BoardQuestionVO(
val questionId: Int,
val userId: Int,
val memberId: Int,
val categoryId: Int,
val profileImage: String,
val name: String,
val region: String,
val contents: String,
val like: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ data class ProfileVO(
val id: Int,
val description: String,
val profileImage: String,
val language: List<LanguageVO>,
val languages: List<LanguageVO>,
val name: String,
val region: String,
val interests: Map<String, List<String>>,
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package com.lighthouse.domain.usecase

import com.lighthouse.domain.constriant.Resource
import com.lighthouse.domain.repository.BoardRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GetQuestionUseCase @Inject constructor(
private val repository: BoardRepository,
) {
fun invoke(category: Int, order: String, page: Int) =
repository.getBoardQuestions(category, order, page)


fun uploadQuestion(userId: Int, categoryId: Int, content: String): Flow<Resource<String>> =
repository.uploadQuestion(userId, categoryId, content)

fun updateLike(questionId: Int, memberId: Int): Flow<Resource<String>> =
repository.updateLike(questionId, memberId)

}

0 comments on commit 82c95ce

Please sign in to comment.