Skip to content

Commit

Permalink
Merge pull request #18 from wsi1212/feature/detail
Browse files Browse the repository at this point in the history
상세 페이지 만들기
  • Loading branch information
wsi1212 authored Jan 26, 2024
2 parents 3a6eec5 + 0e44f53 commit f16792c
Show file tree
Hide file tree
Showing 105 changed files with 1,755 additions and 384 deletions.
12 changes: 6 additions & 6 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package kr.hs.dgsw.mentomenv2.data.remote
package kr.hs.dgsw.mentomenv2.data.datasource

import kotlinx.coroutines.flow.Flow
import kr.hs.dgsw.mentomenv2.data.response.TokenResponse
import kr.hs.dgsw.mentomenv2.domain.model.Token

interface AuthDataSource {
fun signIn(code: String): Flow<Token>

fun getAccessToken(): Flow<TokenResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package kr.hs.dgsw.mentomenv2.data.datasource

import kotlinx.coroutines.flow.Flow
import kr.hs.dgsw.mentomenv2.data.request.CommentSubmitRequest
import kr.hs.dgsw.mentomenv2.data.request.CommentUpdateRequest
import kr.hs.dgsw.mentomenv2.domain.model.Comment

interface CommentDataSource {
fun getCommentList(postId: Int): Flow<List<Comment>>

fun submitComment(commentSubmitRequest: CommentSubmitRequest): Flow<Unit>

fun updateComment(commentUpdateRequest: CommentUpdateRequest): Flow<Unit>

fun deleteComment(commentId: Int): Flow<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kr.hs.dgsw.mentomenv2.data.remote
package kr.hs.dgsw.mentomenv2.data.datasource

import kotlinx.coroutines.flow.Flow
import kr.hs.dgsw.mentomenv2.domain.model.Token
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package kr.hs.dgsw.mentomenv2.data.remote
package kr.hs.dgsw.mentomenv2.data.datasource

import kotlinx.coroutines.flow.Flow
import kr.hs.dgsw.mentomenv2.data.response.ImgUrlResponseDto
import kr.hs.dgsw.mentomenv2.data.response.ImgUrlResponse
import okhttp3.MultipartBody

interface FileDataSource {
fun postFile(files: List<MultipartBody.Part>): Flow<List<ImgUrlResponseDto>>
fun postFile(files: List<MultipartBody.Part>): Flow<List<ImgUrlResponse>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kr.hs.dgsw.mentomenv2.data.datasource

import kotlinx.coroutines.flow.Flow
import kr.hs.dgsw.mentomenv2.domain.model.Post
import kr.hs.dgsw.mentomenv2.domain.model.User

interface MyDataSource {
fun getMyInfo(): Flow<User>

fun getMyPost(): Flow<List<Post>>
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kr.hs.dgsw.mentomenv2.data.remote
package kr.hs.dgsw.mentomenv2.data.datasource

import kotlinx.coroutines.flow.Flow
import kr.hs.dgsw.mentomenv2.domain.model.Post
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kr.hs.dgsw.mentomenv2.data.datasource.cache
package kr.hs.dgsw.mentomenv2.data.datasourceimpl.cache

import android.util.Log
import androidx.datastore.core.DataStore
Expand All @@ -9,7 +9,8 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kr.hs.dgsw.mentomenv2.data.remote.DataStoreDataSource
import kr.hs.dgsw.mentomenv2.data.datasource.DataStoreDataSource
import kr.hs.dgsw.mentomenv2.domain.exception.MenToMenException
import kr.hs.dgsw.mentomenv2.domain.model.Token
import javax.inject.Inject

Expand Down Expand Up @@ -43,7 +44,11 @@ class DataStoreDataSourceImpl
"DataStoreDataSourceImpl",
"Token: ${accessToken.first()}, ${refreshToken.first()} 토큰 호출 성공",
)
emit(Token(accessToken.first(), refreshToken.first()))
if (accessToken.first() == "" || refreshToken.first() == "") {
throw MenToMenException("토큰이 없습니다.")
} else {
emit(Token(accessToken.first(), refreshToken.first()))
}
}

override fun getData(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package kr.hs.dgsw.mentomenv2.data.datasourceimpl.remote

import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kr.hs.dgsw.mentomenv2.data.datasource.AuthDataSource
import kr.hs.dgsw.mentomenv2.data.datasourceimpl.remote.base.RetrofitDataSourceImpl
import kr.hs.dgsw.mentomenv2.data.request.DAuthClientRequest
import kr.hs.dgsw.mentomenv2.data.response.TokenResponse
import kr.hs.dgsw.mentomenv2.data.service.AuthService
import kr.hs.dgsw.mentomenv2.domain.exception.MenToMenException
import kr.hs.dgsw.mentomenv2.domain.model.Token
import kr.hs.dgsw.mentomenv2.domain.usecase.token.GetTokenUseCase
import javax.inject.Inject

class AuthDataSourceImpl
@Inject
constructor(
getTokenUseCase: GetTokenUseCase,
) : RetrofitDataSourceImpl<AuthService>(getTokenUseCase), AuthDataSource {
override val api: AuthService
get() = createApi(AuthService::class.java)

override fun signIn(code: String): Flow<Token> {
Log.d("AuthDataSourceImpl", "signIn out return flow: $code")
return flow {
emit(api.signIn(DAuthClientRequest(code)).data)
}
}

override fun getAccessToken(): Flow<TokenResponse> {
return flow {
val response = api.refreshToken().execute()

if (response.isSuccessful) {
emit(response.body()?.data ?: TokenResponse())
} else {
throw MenToMenException("토큰을 갱신하는데 실패했습니다.")
}
}.flowOn(Dispatchers.IO)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package kr.hs.dgsw.mentomenv2.data.datasourceimpl.remote

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kr.hs.dgsw.mentomenv2.data.datasource.CommentDataSource
import kr.hs.dgsw.mentomenv2.data.request.CommentSubmitRequest
import kr.hs.dgsw.mentomenv2.data.request.CommentUpdateRequest
import kr.hs.dgsw.mentomenv2.data.service.CommentService
import kr.hs.dgsw.mentomenv2.domain.exception.MenToMenException
import kr.hs.dgsw.mentomenv2.domain.model.Comment
import javax.inject.Inject

class CommentDataSourceImpl
@Inject
constructor(
private val api: CommentService,
) : CommentDataSource {
override fun getCommentList(postId: Int): Flow<List<Comment>> {
return flow {
val response = api.getCommentList(postId).execute()

if (response.isSuccessful) {
emit(response.body()?.data ?: emptyList())
} else {
throw MenToMenException("댓글 목록을 불러오는데 실패했습니다.")
}
}.flowOn(Dispatchers.IO)
}

override fun submitComment(commentSubmitRequest: CommentSubmitRequest): Flow<Unit> {
return flow {
val response = api.submitComment(commentSubmitRequest).execute()

if (response.isSuccessful) {
emit(response.body()?.data ?: Unit)
} else {
throw MenToMenException("댓글을 작성하는데 실패했습니다.")
}
}.flowOn(Dispatchers.IO)
}

override fun updateComment(commentUpdateRequest: CommentUpdateRequest): Flow<Unit> {
return flow {
val response = api.updateComment(commentUpdateRequest).execute()

if (response.isSuccessful) {
emit(response.body()?.data ?: Unit)
} else {
throw MenToMenException("댓글을 수정하는데 실패했습니다.")
}
}.flowOn(Dispatchers.IO)
}

override fun deleteComment(commentId: Int): Flow<Unit> {
return flow {
val response = api.deleteComment(commentId).execute()

if (response.isSuccessful) {
emit(response.body()?.data ?: Unit)
} else {
throw MenToMenException("댓글을 삭제하는데 실패했습니다.")
}
}.flowOn(Dispatchers.IO)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package kr.hs.dgsw.mentomenv2.data.datasource.remote
package kr.hs.dgsw.mentomenv2.data.datasourceimpl.remote

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kr.hs.dgsw.mentomenv2.data.remote.FileDataSource
import kr.hs.dgsw.mentomenv2.data.response.ImgUrlResponseDto
import kr.hs.dgsw.mentomenv2.data.datasource.FileDataSource
import kr.hs.dgsw.mentomenv2.data.response.ImgUrlResponse
import kr.hs.dgsw.mentomenv2.data.service.FileService
import okhttp3.MultipartBody
import javax.inject.Inject
Expand All @@ -15,7 +15,7 @@ class FileDataSourceImpl
constructor(
private val api: FileService,
) : FileDataSource {
override fun postFile(files: List<MultipartBody.Part>): Flow<List<ImgUrlResponseDto>> {
override fun postFile(files: List<MultipartBody.Part>): Flow<List<ImgUrlResponse>> {
return flow {
val response = api.postFile(files).execute()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package kr.hs.dgsw.mentomenv2.data.datasourceimpl.remote

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kr.hs.dgsw.mentomenv2.data.datasource.MyDataSource
import kr.hs.dgsw.mentomenv2.data.service.MyService
import kr.hs.dgsw.mentomenv2.domain.model.Post
import kr.hs.dgsw.mentomenv2.domain.model.StdInfo
import kr.hs.dgsw.mentomenv2.domain.model.User
import retrofit2.HttpException
import javax.inject.Inject

class MyDataSourceImpl
@Inject
constructor(
private val myApi: MyService,
) : MyDataSource {
override fun getMyInfo(): Flow<User> =
flow {
val response = myApi.getUserInfo().execute()
if (response.isSuccessful) {
if (response.body()?.data?.profileImage == null) {
emit(
User(
email = response.body()?.data?.email ?: "",
name = response.body()?.data?.name ?: "",
profileImage = "",
roles = response.body()?.data?.roles ?: "",
stdInfo = response.body()?.data?.stdInfo ?: StdInfo(0, 0, 0),
userId = response.body()?.data?.userId ?: 0,
),
)
} else {
emit(response.body()?.data ?: User())
}
} else {
throw HttpException(response)
}
}.flowOn(Dispatchers.IO)

override fun getMyPost(): Flow<List<Post>> =
flow {
val response = myApi.getMyPost().execute()

if (response.isSuccessful) {
emit(response.body()?.data ?: emptyList())
} else {
throw HttpException(response)
}
}.flowOn(Dispatchers.IO)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package kr.hs.dgsw.mentomenv2.data.datasource.remote
package kr.hs.dgsw.mentomenv2.data.datasourceimpl.remote

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kr.hs.dgsw.mentomenv2.data.remote.PostDataSource
import kr.hs.dgsw.mentomenv2.data.datasource.PostDataSource
import kr.hs.dgsw.mentomenv2.data.service.PostService
import kr.hs.dgsw.mentomenv2.domain.model.Post
import kr.hs.dgsw.mentomenv2.domain.params.PostSubmitParam
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kr.hs.dgsw.mentomenv2.data.datasourceimpl.remote.base

abstract class BaseDataSourceImpl<API> {
abstract val api: API
}
Loading

0 comments on commit f16792c

Please sign in to comment.