Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ android {
compose = true
buildConfig = true
}
buildFeatures {
compose = true
buildConfig = true
}
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/paw/key/data/di/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ object NetworkModule {
.addConverterFactory(converterFactory)
.client(client)
.build()
}
}
9 changes: 9 additions & 0 deletions app/src/main/java/com/paw/key/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.paw.key.data.remote.datasource.mypage.MypageDataSource
import com.paw.key.data.remote.datasource.mypage.MypageDataSourceImpl
import com.paw.key.data.repository.mypage.MypageRepositoryImpl
import com.paw.key.data.repositoryimpl.ArchivedListRepositoryImpl
import com.paw.key.data.repositoryimpl.DbtiRepositoryImpl
import com.paw.key.data.repositoryimpl.LikeRepositoryImpl
import com.paw.key.data.repositoryimpl.RegionRepositoryImpl
import com.paw.key.data.repositoryimpl.SavedListRepositoryImpl
Expand All @@ -24,6 +25,7 @@ import com.paw.key.data.repositoryimpl.user.UserRepositoryImpl
import com.paw.key.data.repositoryimpl.walk.WalkRepositoryImpl
import com.paw.key.data.repositoryimpl.walkpreparation.WalkPreparationRepositoryImpl
import com.paw.key.domain.repository.ArchivedListRepository
import com.paw.key.domain.repository.DbtiRepository
import com.paw.key.domain.repository.LikeRepository
import com.paw.key.domain.repository.RegionRepository
import com.paw.key.domain.repository.SavedListRepository
Expand Down Expand Up @@ -165,4 +167,11 @@ interface RepositoryModule {
impl: WalkRepositoryImpl
) : WalkRepository


//DBTI
@Binds
@Singleton
abstract fun bindDbtiRepository(
dbtiRepositoryImpl: DbtiRepositoryImpl
): DbtiRepository
}
7 changes: 7 additions & 0 deletions app/src/main/java/com/paw/key/data/di/ServiceModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.paw.key.data.di

import com.paw.key.data.service.ArchivedListService
import com.paw.key.data.service.DbtiService
import com.paw.key.data.service.LikeService
import com.paw.key.data.service.SavedListService
import com.paw.key.data.service.auth.ReissueService
Expand Down Expand Up @@ -79,6 +80,7 @@ object ServiceModule {
fun provideImageS3Service(@Named("s3") retrofit: Retrofit): S3Service =
retrofit.create()

// 리뷰
@Provides
@Singleton
fun provideWalkPreparationService(retrofit: Retrofit): WalkPreparationService =
Expand All @@ -104,4 +106,9 @@ object ServiceModule {
@Singleton
fun provideMypageService(retrofit: Retrofit): MypageService =
retrofit.create()

@Provides
@Singleton
fun provideDbtiService(retrofit: Retrofit): DbtiService =
retrofit.create()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.paw.key.data.dto.request.dbti

import kotlinx.serialization.Serializable

@Serializable
data class DbtiResultRequest(
val optionIds: List<Int>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.paw.key.data.dto.response.dbti

import kotlinx.serialization.Serializable

@Serializable
data class DbtiQuestionsResponse(
val code: String,
val message: String,
val data: QuestionsData
)

@Serializable
data class QuestionsData(
val questions: List<QuestionDto>
)

@Serializable
data class QuestionDto(
val id: Int,
val category: CategoryDto,
val content: String,
val options: List<OptionDto>
)

@Serializable
data class CategoryDto(
val code: String,
val name: String
)

@Serializable
data class OptionDto(
val id: Int,
val content: String,
val imageUrl: String?,
val value: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.paw.key.data.dto.response.dbti

import kotlinx.serialization.Serializable

@Serializable
data class DbtiResultResponse(
val code: String,
val message: String,
val data: DbtiResultData
)

@Serializable
data class DbtiResultData(
val type: String,
val name: String,
val image: String?,
val keyword: List<String>,
val description: String,
val analysis: List<AnalysisDto>
)

@Serializable
data class AnalysisDto(
val axis: String,
val leftLabel: String,
val rightLabel: String,
val dominantSide: String,
val score: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.paw.key.data.remote.datasource

import com.paw.key.data.dto.request.dbti.DbtiResultRequest
import com.paw.key.data.dto.response.dbti.DbtiQuestionsResponse
import com.paw.key.data.dto.response.dbti.DbtiResultResponse
import com.paw.key.data.service.DbtiService
import javax.inject.Inject

class DbtiDataSource @Inject constructor(
private val dbtiService: DbtiService
) {
suspend fun getQuestions(token: String): DbtiQuestionsResponse {
return dbtiService.getQuestions("Bearer $token")
}

suspend fun submitResult(
petId: Long,
token: String,
optionIds: List<Int>
): DbtiResultResponse {
return dbtiService.submitResult(
petId = petId,
authorization = "Bearer $token",
request = DbtiResultRequest(optionIds = optionIds)
)
}

suspend fun getResult(
petId: Long,
token: String
): DbtiResultResponse {
return dbtiService.getResult(
petId = petId,
authorization = "Bearer $token"
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.paw.key.data.repositoryimpl

import com.paw.key.data.remote.datasource.DbtiDataSource
import com.paw.key.domain.entity.DBTI.DbtiAnalysisEntity
import com.paw.key.domain.entity.DBTI.DbtiResultEntity
import com.paw.key.domain.entity.dbti.DbtiOptionEntity
import com.paw.key.domain.entity.dbti.DbtiQuestionEntity
import com.paw.key.domain.repository.DbtiRepository
import javax.inject.Inject

class DbtiRepositoryImpl @Inject constructor(
private val dbtiDataSource: DbtiDataSource
) : DbtiRepository {

override suspend fun getQuestions(): Result<List<DbtiQuestionEntity>> {
return runCatching {
val response = dbtiDataSource.getQuestions("YOUR_TOKEN") // TODO: 실제 토큰으로 변경
response.data.questions.map { questionDto ->
DbtiQuestionEntity(
id = questionDto.id,
categoryCode = questionDto.category.code,
categoryName = questionDto.category.name,
content = questionDto.content,
options = questionDto.options.map { optionDto ->
DbtiOptionEntity(
id = optionDto.id,
content = optionDto.content,
imageUrl = optionDto.imageUrl,
value = optionDto.value
)
}
)
}
}
}

override suspend fun submitResult(
petId: Long,
optionIds: List<Int>
): Result<DbtiResultEntity> {
return runCatching {
val response = dbtiDataSource.submitResult(
petId = petId,
token = "YOUR_TOKEN", // TODO: 실제 토큰으로 변경
optionIds = optionIds
)

DbtiResultEntity(
type = response.data.type,
name = response.data.name,
image = response.data.image,
keyword = response.data.keyword,
description = response.data.description,
analysis = response.data.analysis.map { analysisDto ->
DbtiAnalysisEntity(
axis = analysisDto.axis,
leftLabel = analysisDto.leftLabel,
rightLabel = analysisDto.rightLabel,
dominantSide = analysisDto.dominantSide,
score = analysisDto.score
)
}
)
}
}

override suspend fun getResult(petId: Long): Result<DbtiResultEntity> {
return runCatching {
val response = dbtiDataSource.getResult(
petId = petId,
token = "YOUR_TOKEN" // TODO: 실제 토큰으로 변경
)

DbtiResultEntity(
type = response.data.type,
name = response.data.name,
image = response.data.image,
keyword = response.data.keyword,
description = response.data.description,
analysis = response.data.analysis.map { analysisDto ->
DbtiAnalysisEntity(
axis = analysisDto.axis,
leftLabel = analysisDto.leftLabel,
rightLabel = analysisDto.rightLabel,
dominantSide = analysisDto.dominantSide,
score = analysisDto.score
)
}
)
}
}
}
30 changes: 30 additions & 0 deletions app/src/main/java/com/paw/key/data/service/DBTI/DbtiService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.paw.key.data.service

import com.paw.key.data.dto.request.dbti.DbtiResultRequest
import com.paw.key.data.dto.response.dbti.DbtiQuestionsResponse
import com.paw.key.data.dto.response.dbti.DbtiResultResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST
import retrofit2.http.Path

interface DbtiService {
@GET("pets/dbti/questions")
suspend fun getQuestions(
@Header("Authorization") authorization: String
): DbtiQuestionsResponse

@POST("pets/dbti/{petId}")
suspend fun submitResult(
@Path("petId") petId: Long,
@Header("Authorization") authorization: String,
@Body request: DbtiResultRequest
): DbtiResultResponse

@GET("pets/dbti/{petId}")
suspend fun getResult(
@Path("petId") petId: Long,
@Header("Authorization") authorization: String
): DbtiResultResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.paw.key.domain.entity.dbti

data class DbtiQuestionEntity(
val id: Int,
val categoryCode: String,
val categoryName: String,
val content: String,
val options: List<DbtiOptionEntity>
)

data class DbtiOptionEntity(
val id: Int,
val content: String,
val imageUrl: String?,
val value: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.paw.key.domain.entity.DBTI

data class DbtiResultEntity(
val type: String,
val name: String,
val image: String?,
val keyword: List<String>,
val description: String,
val analysis: List<DbtiAnalysisEntity>
)

data class DbtiAnalysisEntity(
val axis: String,
val leftLabel: String,
val rightLabel: String,
val dominantSide: String,
val score: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.paw.key.domain.repository

import com.paw.key.domain.entity.DBTI.DbtiResultEntity
import com.paw.key.domain.entity.dbti.DbtiQuestionEntity

interface DbtiRepository {
suspend fun getQuestions(): Result<List<DbtiQuestionEntity>>

suspend fun submitResult(
petId: Long,
optionIds: List<Int>
): Result<DbtiResultEntity>

suspend fun getResult(petId: Long): Result<DbtiResultEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.paw.key.domain.usecase

import com.paw.key.domain.entity.dbti.DbtiQuestionEntity
import com.paw.key.domain.repository.DbtiRepository
import javax.inject.Inject

class GetDbtiQuestionsUseCase @Inject constructor(
private val repository: DbtiRepository
) {
suspend operator fun invoke(): Result<List<DbtiQuestionEntity>> {
return repository.getQuestions()
}
}
Loading
Loading