Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] entity 추가, dataStore 추가 #99

Merged
merged 25 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b0e46ac
[FIX/#21] activityViewModel로 수정
gaeun5744 Sep 3, 2023
840c52d
[REFACTOR/#68] 회고상세조회 뷰 Dto -> Entity 변경
gaeun5744 Sep 3, 2023
aa600c4
[REFACTOR/#68] 초대코드 api Dto -> Entity 변경
gaeun5744 Sep 4, 2023
418aeaf
[REFACTOR/#68] 프로젝트 참여하기 requestDto -> entity
gaeun5744 Sep 4, 2023
387da7e
[RENAME/#68] RequestInvitationCode -> RequestJoinProject 로 파일명 변경
gaeun5744 Sep 4, 2023
96237a0
[DELETE] 불필요한 변수 제거
gaeun5744 Sep 4, 2023
a629c2d
[REFACTOR/#21] viewModelProvider -> activityViewModel
gaeun5744 Sep 4, 2023
ff9ba77
[DELETE] 불필요한 import 제거
gaeun5744 Sep 4, 2023
fc99262
[REFACTOR/#21] viewModelProvider -> activityViewModel
gaeun5744 Sep 4, 2023
783ebae
[REFACTOR/#68] 프로젝트 회고조회 api Dto -> Entity
gaeun5744 Sep 4, 2023
347003f
[REFACTOR/#68] 회고 주기 조회 api Dto -> Entity
gaeun5744 Sep 4, 2023
2314170
[FIX] git 충돌 해결
gaeun5744 Sep 4, 2023
d17ce8f
[FIX] import 주소 수정
gaeun5744 Sep 4, 2023
2afdfe1
Merge pull request #15 from gaeun5744/refactor/#68-allview-Dto
gaeun5744 Sep 4, 2023
b25ac87
[ADD] implement dataStore 추가
gaeun5744 Sep 4, 2023
e8dc8df
Merge branch 'develop' of github.com:gaeun5744/Puzzling_Android into …
gaeun5744 Sep 4, 2023
54852af
[FEAT] KeyStore를 이용한 암호화 service 구현
gaeun5744 Sep 5, 2023
f54a139
[FIX] import 수정
gaeun5744 Sep 6, 2023
94b2f52
[ADD/#40] Token entity 추가
gaeun5744 Sep 6, 2023
4817595
[ADD/#40] Token dataSource 추가
gaeun5744 Sep 6, 2023
57e4c46
[FEAT/#40] encrypted datastore data layer까지 구현
gaeun5744 Sep 23, 2023
d0c98a4
[RENAME] Login -> Auth 파일명 변경
gaeun5744 Sep 24, 2023
d58bfa7
[FEAT/#40] kakaoLogin DI 적용
gaeun5744 Sep 24, 2023
9a70255
[FEAT/#40] dataStore UseCase 구현
gaeun5744 Sep 26, 2023
3f1a6ea
Merge pull request #16 from gaeun5744/refactor/#40-source-dataStore
gaeun5744 Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ dependencies {
implementation "com.kakao.sdk:v2-share:2.15.0" // 메시지(카카오톡 공유)
//EncryptedSharedPreference
implementation "androidx.security:security-crypto-ktx:1.1.0-alpha06"
// dataStore
implementation "androidx.datastore:datastore-preferences:1.0.0"


}
// hilt dependency와 함께 추가
kapt {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.puzzling.puzzlingaos.data.datasource.local

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.datastore.core.Serializer
import com.puzzling.puzzlingaos.data.entity.Token
import com.puzzling.puzzlingaos.data.service.CryptoService
import kotlinx.serialization.json.Json
import org.apache.commons.lang3.SerializationException
import java.io.InputStream
import java.io.OutputStream
import javax.inject.Inject

@RequiresApi(Build.VERSION_CODES.M)
class TokenDataSource @Inject constructor(private val cryptoService: CryptoService) : Serializer<Token> {
override val defaultValue: Token
get() = Token()

override suspend fun readFrom(input: InputStream): Token {
val decryptedBytes = cryptoService.decrypt(input)
return try {
Json.decodeFromString(
deserializer = Token.serializer(),
string = decryptedBytes.decodeToString(),
)
} catch (e: SerializationException) {
e.printStackTrace()
defaultValue
}
}

override suspend fun writeTo(t: Token, output: OutputStream) {
cryptoService.encrypt(
bytes = Json.encodeToString(
serializer = Token.serializer(),
value = t,
).encodeToByteArray(),
outputStream = output,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.puzzling.puzzlingaos.data.datasource.remote

import com.puzzling.puzzlingaos.data.model.request.RequestInvitationCode
import com.puzzling.puzzlingaos.data.model.request.RequestJoinProject
import com.puzzling.puzzlingaos.data.model.request.RequestProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseInvitationCodeDto
import com.puzzling.puzzlingaos.data.model.response.ResponseJoinProjectDto
Expand All @@ -15,7 +15,7 @@ interface ProjectDataSource {

suspend fun joinProject(
memberId: Int,
request: RequestInvitationCode,
request: RequestJoinProject,
): ResponseJoinProjectDto

suspend fun isValidInvitationCode(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.puzzling.puzzlingaos.data.datasource.remote.impl

import com.puzzling.puzzlingaos.data.datasource.remote.ProjectDataSource
import com.puzzling.puzzlingaos.data.model.request.RequestInvitationCode
import com.puzzling.puzzlingaos.data.model.request.RequestJoinProject
import com.puzzling.puzzlingaos.data.model.request.RequestProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseInvitationCodeDto
import com.puzzling.puzzlingaos.data.model.response.ResponseJoinProjectDto
Expand All @@ -22,7 +22,7 @@ class ProjectDataSourceImpl @Inject constructor(

override suspend fun joinProject(
memberId: Int,
request: RequestInvitationCode,
request: RequestJoinProject,
): ResponseJoinProjectDto = apiService.joinProject(memberId, request)

override suspend fun isValidInvitationCode(invitationCode: String): ResponseInvitationCodeDto =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.puzzling.puzzlingaos.data.entity

import kotlinx.serialization.Serializable

@Serializable
data class Token(
val accessToken: String? = null,
)
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.puzzling.puzzlingaos.data.model.request

import com.puzzling.puzzlingaos.domain.entity.JoinProjectInfo
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestInvitationCode(
data class RequestJoinProject(
@SerialName("projectId")
val projectId: Int,
@SerialName("memberProjectNickname")
val memberProjectNickname: String,
@SerialName("memberProjectRole")
val memberProjectRole: String,
)

fun JoinProjectInfo.toRequestJoinProjectDto() = RequestJoinProject(
projectId,
memberProjectNickname,
memberProjectRole,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.puzzling.puzzlingaos.data.model.response

import com.puzzling.puzzlingaos.domain.entity.DetailRetro
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -12,7 +13,7 @@ data class ResponseDetailRetroDto(
@SerialName("message")
val message: String,
@SerialName("data")
val data: Data?,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

val data: Data,
) {
@Serializable
data class Data(
Expand Down Expand Up @@ -42,5 +43,18 @@ data class ResponseDetailRetroDto(
val content: String,
)
}

fun toDetailRetro() = reviews.map { reviews ->
DetailRetro(
reviewId = reviews.reviewId,
reviewDay = reviews.reviewDay,
reviewDate = reviews.reviewDate,
reviewTemplateId = reviews.reviewTemplateId,
content = reviews.contents?.map { content ->
DetailRetro.Content(content.title, content.content)
},

)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.puzzling.puzzlingaos.data.model.response

import com.puzzling.puzzlingaos.domain.entity.InvitationCode
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -12,13 +13,15 @@ data class ResponseInvitationCodeDto(
@SerialName("message")
val message: String,
@SerialName("data")
val data: InvitationCodeData?,
val data: InvitationCodeData,
) {
@Serializable
data class InvitationCodeData(
@SerialName("projectId")
val projectId: Int,
@SerialName("projectName")
val projectName: String,
)
) {
fun toInvitationCode() = InvitationCode(projectId, projectName)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.puzzling.puzzlingaos.data.model.response

import com.puzzling.puzzlingaos.domain.entity.ProjectReview
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -12,7 +13,7 @@ data class ResponseMyRetroListDto(
@SerialName("message")
val message: String,
@SerialName("data")
val data: List<ReviewData>?,
val data: List<ReviewData>,
) {
@Serializable
data class ReviewData(
Expand All @@ -23,5 +24,12 @@ data class ResponseMyRetroListDto(
@SerialName("contents")
val contents: String,
)
}

fun toProjectReview() = data.map { reviewData ->
ProjectReview(
reviewData.reviewId,
reviewData.reviewDate,
reviewData.contents,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.puzzling.puzzlingaos.data.model.response

import com.puzzling.puzzlingaos.domain.entity.ReviewCycle
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -12,13 +13,15 @@ data class ResponseProjectRetroWeekDto(
@SerialName("message")
val message: String,
@SerialName("data")
val data: ProjectCycle?,
val data: ProjectCycle,
) {
@Serializable
data class ProjectCycle(
@SerialName("projectName")
val projectName: String,
@SerialName("projectReviewCycle")
val projectReviewCycle: String,
)
) {
fun toReviewCycle() = ReviewCycle(projectName, projectReviewCycle)
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
package com.puzzling.puzzlingaos.data.repository

import com.puzzling.puzzlingaos.data.datasource.remote.MyPageDataSource
import com.puzzling.puzzlingaos.data.model.response.ResponseDetailRetroDto
import com.puzzling.puzzlingaos.data.model.response.ResponseMyRetroListDto
import com.puzzling.puzzlingaos.domain.entity.DetailRetro
import com.puzzling.puzzlingaos.domain.entity.ProjectReview
import com.puzzling.puzzlingaos.domain.repository.MyPageRepository
import javax.inject.Inject

class MyPageRepositoryImpl @Inject constructor(private val myPageDataSource: MyPageDataSource) :
MyPageRepository {
override suspend fun getMyProjectReview(memberId: Int, projectId: Int): ResponseMyRetroListDto {
return myPageDataSource.getMyProjectReview(memberId, projectId)
}
override suspend fun getMyProjectReview(
memberId: Int,
projectId: Int,
): Result<List<ProjectReview>> =
runCatching {
myPageDataSource.getMyProjectReview(memberId, projectId).toProjectReview()
}

override suspend fun getMyDetailReview(
memberId: Int,
projectId: Int,
startDate: String,
endDate: String,
): ResponseDetailRetroDto {
return myPageDataSource.getMyDetailReview(memberId, projectId, startDate, endDate)
): Result<List<DetailRetro>> = runCatching {
myPageDataSource.getMyDetailReview(
memberId,
projectId,
startDate,
endDate,
).data.toDetailRetro()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package com.puzzling.puzzlingaos.data.repository

import android.util.Log
import com.puzzling.puzzlingaos.data.datasource.remote.ProjectDataSource
import com.puzzling.puzzlingaos.data.model.request.RequestInvitationCode
import com.puzzling.puzzlingaos.data.model.request.RequestProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseInvitationCodeDto
import com.puzzling.puzzlingaos.data.model.request.toRequestJoinProjectDto
import com.puzzling.puzzlingaos.data.model.response.ResponseJoinProjectDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRetroWeekDto
import com.puzzling.puzzlingaos.domain.entity.InvitationCode
import com.puzzling.puzzlingaos.domain.entity.JoinProjectInfo
import com.puzzling.puzzlingaos.domain.entity.ReviewCycle
import com.puzzling.puzzlingaos.domain.repository.ProjectRepository
import javax.inject.Inject

Expand All @@ -28,16 +29,17 @@ class ProjectRepositoryImpl @Inject constructor(

override suspend fun joinProject(
memberId: Int,
request: RequestInvitationCode,
): ResponseJoinProjectDto {
return projectDataSource.joinProject(memberId, request)
request: JoinProjectInfo,
): Result<ResponseJoinProjectDto> = runCatching {
projectDataSource.joinProject(memberId, request.toRequestJoinProjectDto())
}

override suspend fun isValidInvitationCode(invitationCode: String): ResponseInvitationCodeDto {
return projectDataSource.isValidInvitationCode(invitationCode)
}
override suspend fun isValidInvitationCode(invitationCode: String): Result<InvitationCode> =
runCatching {
projectDataSource.isValidInvitationCode(invitationCode).data.toInvitationCode()
}

override suspend fun getProjectWeekCycle(projectId: Int): ResponseProjectRetroWeekDto {
return projectDataSource.getProjectWeekCycle(projectId)
override suspend fun getProjectWeekCycle(projectId: Int): Result<ReviewCycle> = runCatching {
projectDataSource.getProjectWeekCycle(projectId).data.toReviewCycle()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.puzzling.puzzlingaos.data.repository

import androidx.datastore.core.DataStore
import com.puzzling.puzzlingaos.data.entity.Token
import com.puzzling.puzzlingaos.domain.repository.TokenRepository
import kotlinx.coroutines.flow.first
import javax.inject.Inject

class TokenRepositoryImpl @Inject constructor(private val dataStore: DataStore<Token>) :
TokenRepository {
override suspend fun setToken(token: String) {
dataStore.updateData { Token(token) }
}

override suspend fun getToken(): Token = dataStore.data.first()
}
Loading
Loading