Skip to content

Commit

Permalink
#84 [fix] merge conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
emjayMJkim committed Jan 17, 2024
2 parents 921d221 + 54b39e7 commit 382d6a0
Show file tree
Hide file tree
Showing 21 changed files with 505 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.sopetit.softie.data.entity.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class AddDailyRoutineRequest(
@SerialName("routineId")
val routineId: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.sopetit.softie.data.entity.response

import com.sopetit.softie.domain.entity.DailyAchieve
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class AchieveDailyResponse(
@SerialName("routineId")
val routineId: Int,
@SerialName("isAchieve")
val isAchieve: Boolean,
@SerialName("achieveCount")
val achieveCount: Int
) {
fun toAchieveDaily(): DailyAchieve = DailyAchieve(
routineId = this.routineId,
isAchieve = this.isAchieve,
achieveCount = this.achieveCount
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.sopetit.softie.data.entity.response

import com.sopetit.softie.domain.entity.AddRoutine
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class AddDailyRoutineResponse(
@SerialName("routineId")
val routineId: Int
) {
fun toAddDailyRoutine(): AddRoutine = AddRoutine(
routineId = this.routineId
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.sopetit.softie.data.entity.response

import com.sopetit.softie.domain.entity.Routine
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

data class DailyCardResponse(
@SerialName("routines")
val routines: List<RoutineItem>
) {
@Serializable
data class RoutineItem(
@SerialName("routineId")
val routineId: Int,
@SerialName("content")
val content: String
)

fun toRoutine() = routines.map {
Routine(
routineId = it.routineId,
content = it.content
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.sopetit.softie.data.entity.response

import com.sopetit.softie.domain.entity.DailyRoutine
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class DailyRoutineResponse(
@SerialName("routines")
val routines: List<DailyRoutineItem>
) {
@Serializable
data class DailyRoutineItem(
@SerialName("routineId")
val routineId: Int,
@SerialName("content")
val content: String,
@SerialName("iconImageUrl")
val iconImageUrl: String,
@SerialName("achieveCount")
val achieveCount: Int,
@SerialName("isAchieve")
val isAchieve: Boolean
)

fun toUserDailyRoutine() = routines.map {
DailyRoutine(
routineId = it.routineId,
content = it.content,
iconImageUrl = it.iconImageUrl,
achieveCount = it.achieveCount,
isAchieve = it.isAchieve
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.sopetit.softie.data.repositoryImpl

import com.sopetit.softie.data.source.DailyRoutineDataSource
import com.sopetit.softie.domain.entity.AddRoutine
import com.sopetit.softie.domain.entity.DailyAchieve
import com.sopetit.softie.domain.entity.DailyRoutine
import com.sopetit.softie.domain.entity.Routine
import com.sopetit.softie.domain.entity.Theme
import com.sopetit.softie.domain.repository.DailyRoutineRepository
Expand All @@ -9,6 +12,18 @@ import javax.inject.Inject
class DailyRoutineRepositoryImpl @Inject constructor(
private val dailyRoutineDataSource: DailyRoutineDataSource
) : DailyRoutineRepository {
override suspend fun getDailyRoutine(): Result<List<DailyRoutine>> =
runCatching { dailyRoutineDataSource.getDailyRoutine() }.mapCatching { response ->
requireNotNull(response.data).toUserDailyRoutine()
}

override suspend fun patchAchieveDaily(routineId: Int): Result<DailyAchieve> =
runCatching { dailyRoutineDataSource.patchAchieveDaily(routineId) }.map { response ->
requireNotNull(response.data).toAchieveDaily()
}

override suspend fun deleteDailyRoutine(routineIdList: List<Int>): Result<Unit> =
runCatching { dailyRoutineDataSource.deleteDailyRoutine(routineIdList) }

override suspend fun getTheme(): Result<List<Theme>> = runCatching {
dailyRoutineDataSource.getTheme()
Expand All @@ -21,4 +36,11 @@ class DailyRoutineRepositoryImpl @Inject constructor(
}.mapCatching { dailyRoutineList ->
requireNotNull(dailyRoutineList.data).toRoutine()
}

override suspend fun postAddDailyRoutine(routineId: Int): Result<AddRoutine> =
runCatching {
dailyRoutineDataSource.postAddDailyRoutine(routineId)
}.map { response ->
requireNotNull(response.data).toAddDailyRoutine()
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
package com.sopetit.softie.data.service

import com.sopetit.softie.data.entity.BaseResponse
import com.sopetit.softie.data.entity.response.AchieveDailyResponse
import com.sopetit.softie.data.entity.response.AddDailyRoutineResponse
import com.sopetit.softie.data.entity.response.DailyCardResponse
import com.sopetit.softie.data.entity.response.DailyRoutineListResponse
import com.sopetit.softie.data.entity.response.DailyRoutineResponse
import com.sopetit.softie.data.entity.response.ThemeListResponse
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface DailyRoutineService {

@GET("api/v1/routines/daily/themes")
suspend fun getTheme(): BaseResponse<ThemeListResponse>

@GET("api/v1/routines/daily")
suspend fun getRoutineList(
@Query("themes") themes: List<Int>
): BaseResponse<DailyRoutineListResponse>

@GET("api/v1/routines/daily/member")
suspend fun getDailyRoutine(): BaseResponse<DailyRoutineResponse>

@PATCH("api/v1/routines/daily/member/routine/{routineId}")
suspend fun patchAchieveDaily(@Path("routineId") routineId: Int): BaseResponse<AchieveDailyResponse>

@DELETE("api/v1/routines/daily/member")
suspend fun deleteDailyRoutine(@Query("routines") routineIdList: List<Int>): BaseResponse<Unit>

@POST("api/v1/routines/daily/member")
suspend fun postAddDailyRoutine(@Body routineId: Int): BaseResponse<AddDailyRoutineResponse>

@GET("api/v1/routines/daily/theme/{themeId}")
suspend fun getDailyCardList(@Path("themeId") themeId: Int): BaseResponse<DailyCardResponse>
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
package com.sopetit.softie.data.source

import com.sopetit.softie.data.entity.BaseResponse
import com.sopetit.softie.data.entity.response.AchieveDailyResponse
import com.sopetit.softie.data.entity.response.AddDailyRoutineResponse
import com.sopetit.softie.data.entity.response.DailyRoutineListResponse
import com.sopetit.softie.data.entity.response.DailyRoutineResponse
import com.sopetit.softie.data.entity.response.ThemeListResponse
import com.sopetit.softie.data.service.DailyRoutineService
import javax.inject.Inject

class DailyRoutineDataSource @Inject constructor(
private val dailyRoutineService: DailyRoutineService
) {
suspend fun getDailyRoutine(): BaseResponse<DailyRoutineResponse> =
dailyRoutineService.getDailyRoutine()

suspend fun patchAchieveDaily(routineId: Int): BaseResponse<AchieveDailyResponse> =
dailyRoutineService.patchAchieveDaily(routineId)

suspend fun deleteDailyRoutine(routineIdList: List<Int>): BaseResponse<Unit> =
dailyRoutineService.deleteDailyRoutine(routineIdList)

suspend fun getTheme(): BaseResponse<ThemeListResponse> = dailyRoutineService.getTheme()

suspend fun getRoutineList(themeId: List<Int>): BaseResponse<DailyRoutineListResponse> =
dailyRoutineService.getRoutineList(themeId)

suspend fun postAddDailyRoutine(routineId: Int): BaseResponse<AddDailyRoutineResponse> =
dailyRoutineService.postAddDailyRoutine(routineId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.sopetit.softie.domain.entity

data class AddRoutine(
val routineId: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sopetit.softie.domain.entity

data class DailyAchieve(
val routineId: Int,
val isAchieve: Boolean,
val achieveCount: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sopetit.softie.domain.entity

data class UserDailyRoutine(
val routineId: Int,
val iconImageUrl: String,
val content: String,
val backgroundImageUrl: String
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.sopetit.softie.domain.repository

import com.sopetit.softie.domain.entity.AddRoutine
import com.sopetit.softie.domain.entity.DailyAchieve
import com.sopetit.softie.domain.entity.DailyRoutine
import com.sopetit.softie.domain.entity.Routine
import com.sopetit.softie.domain.entity.Theme

interface DailyRoutineRepository {

suspend fun getDailyRoutine(): Result<List<DailyRoutine>>
suspend fun patchAchieveDaily(routineId: Int): Result<DailyAchieve>
suspend fun deleteDailyRoutine(routineIdList: List<Int>): Result<Unit>
suspend fun getTheme(): Result<List<Theme>>

suspend fun getRoutineList(themeId: List<Int>): Result<List<Routine>>

suspend fun postAddDailyRoutine(routineId: Int): Result<AddRoutine>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sopetit.softie.domain.usecase

import com.sopetit.softie.domain.repository.DailyRoutineRepository
import javax.inject.Inject

class DeleteDailyRoutineUseCase @Inject constructor(
private val deleteDailyRoutine: DailyRoutineRepository
) {
suspend operator fun invoke(routineIdList: List<Int>) =
deleteDailyRoutine.deleteDailyRoutine(routineIdList)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.sopetit.softie.domain.usecase

import com.sopetit.softie.domain.repository.DailyRoutineRepository
import javax.inject.Inject

class GetDailyRoutineUseCase @Inject constructor(
private val dailyRoutineRepository: DailyRoutineRepository
) {
suspend operator fun invoke() = dailyRoutineRepository.getDailyRoutine()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sopetit.softie.domain.usecase

import com.sopetit.softie.domain.repository.DailyRoutineRepository
import javax.inject.Inject

class PatchAchieveDailyUseCase @Inject constructor(
private val achieveDailyRepository: DailyRoutineRepository
) {
suspend operator fun invoke(routineId: Int) =
achieveDailyRepository.patchAchieveDaily(routineId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sopetit.softie.domain.usecase

import com.sopetit.softie.domain.repository.DailyRoutineRepository
import javax.inject.Inject

class PostAddDailyRoutineUseCase @Inject constructor(
private val dailyRoutineRepository: DailyRoutineRepository
) {
suspend operator fun invoke(routineId: Int) =
dailyRoutineRepository.postAddDailyRoutine(routineId)
}
Loading

0 comments on commit 382d6a0

Please sign in to comment.