Skip to content

Commit

Permalink
#178 [refact] data모듈 내 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
murjune committed Aug 11, 2022
1 parent a8e0578 commit eebc8a9
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 91 deletions.
26 changes: 16 additions & 10 deletions data/src/main/java/com/hous/data/api/HomeApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,52 @@ import com.hous.data.entity.ResultData
import com.hous.data.model.WrapperClass
import com.hous.data.model.request.EventListRequest
import com.hous.data.model.response.HomeResponse
import retrofit2.http.*
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path


interface HomeApi {
@GET("room/{roomId}/home")
suspend fun getHomeList(
@Path("roomId") roomId: String
): com.hous.data.model.WrapperClass<com.hous.data.model.response.HomeResponse>
): WrapperClass<HomeResponse>

@DELETE("room/{roomId}/event/{eventId}")
suspend fun deleteEvent(
@Path("roomId") roomId: String,
@Path("eventId") eventId: String
): com.hous.data.model.WrapperClass<Any>
): WrapperClass<Any>

@GET("room/{roomId}/event/{eventId}")
suspend fun getEventList(
@Path("roomId") roomId: String,
@Path("eventId") eventId: String
): com.hous.data.model.WrapperClass<com.hous.data.entity.Event>
): WrapperClass<Event>

@PUT("room/{roomId}/event/{eventId}")
suspend fun putEventList(
@Path("roomId") roomId: String,
@Path("eventId") eventId: String,
@Body body: com.hous.data.model.request.EventListRequest
): com.hous.data.model.WrapperClass<Any>
@Body body: EventListRequest
): WrapperClass<Any>

@POST("room/{roomId}/event")
suspend fun addEvent(
@Path("roomId") roomId: String,
@Body body: com.hous.data.model.request.EventListRequest
): com.hous.data.model.WrapperClass<Any>
@Body body: EventListRequest
): WrapperClass<Any>

@GET("user/{homieId}")
suspend fun getHomieList(
@Path("homieId") homieId: String
): com.hous.data.model.WrapperClass<com.hous.data.entity.Homie>
): WrapperClass<Homie>

@GET("user/{userId}/type")
suspend fun getHomieResult(
@Path("userId") userId: String
): com.hous.data.model.WrapperClass<com.hous.data.entity.ResultData>
): WrapperClass<ResultData>
}
20 changes: 13 additions & 7 deletions data/src/main/java/com/hous/data/api/RulesApi.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.hous.data.api

import com.hous.data.entity.Rule
import com.hous.data.model.WrapperClass
import com.hous.data.model.request.MyToDoCheckRequest
import com.hous.data.model.request.TempManagerRequest
import com.hous.data.model.response.RulesTodayInfoListResponse
import com.hous.data.model.response.TempManagerResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.PUT
Expand All @@ -9,32 +15,32 @@ interface RulesApi {
@GET("room/{roomId}/rules")
suspend fun getTodayTodayInfoList(
@Path("roomId") roomId: String
): com.hous.data.model.WrapperClass<com.hous.data.model.response.RulesTodayInfoListResponse>
): WrapperClass<RulesTodayInfoListResponse>

@GET("/room/{roomId}/rule/{ruleId}/today")
suspend fun getTempManagerInfoList(
@Path("roomId") roomId: String,
@Path("ruleId") ruleId: String
): com.hous.data.model.WrapperClass<com.hous.data.model.response.TempManagerResponse>
): WrapperClass<TempManagerResponse>

@PUT("/room/{roomId}/rule/{ruleId}/today")
suspend fun putTempManagerInfoList(
@Path("roomId") roomId: String,
@Path("ruleId") ruleId: String,
@Body tmpRuleMembers: com.hous.data.model.response.TempManagerRequest
): com.hous.data.model.WrapperClass<Any>
@Body tmpRuleMembers: TempManagerRequest
): Any?

@GET("/room/{roomId}/rules/me")
suspend fun getMyTodoInfoList(
@Path("roomId") roomId: String
): com.hous.data.model.WrapperClass<List<com.hous.data.entity.Rule>>
): WrapperClass<List<Rule>>

@PUT("room/{roomId}/rule/{ruleId}/check")
suspend fun putMyToDoCheckList(
@Path("roomId") roomId: String,
@Path("ruleId") ruleId: String,
@Body isCheck: com.hous.data.model.request.MyToDoCheckRequest
): com.hous.data.model.WrapperClass<com.hous.data.model.request.MyToDoCheckRequest>
@Body isCheck: MyToDoCheckRequest
): WrapperClass<MyToDoCheckRequest>

@GET("/room/{roomId}/category/{categoryId}/rule")
suspend fun getRuleTableInfoList(
Expand Down
4 changes: 2 additions & 2 deletions data/src/main/java/com/hous/data/entity/Category.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hous.data.entity

import com.google.gson.annotations.SerializedName
import com.hous.domain.model.Category
import com.hous.domain.model.CategoryInfo

data class Category(
@SerializedName("_id") val id: String = "",
Expand All @@ -10,5 +10,5 @@ data class Category(
val ruleName: String = "",
var isChecked: Boolean = false
) {
fun toCategory() = Category(id, categoryName, categoryIcon, ruleName, isChecked)
fun toCategoryInfo() = CategoryInfo(id, categoryName, categoryIcon, ruleName, isChecked)
}
4 changes: 2 additions & 2 deletions data/src/main/java/com/hous/data/entity/Homie.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hous.data.entity

import com.google.gson.annotations.SerializedName
import com.hous.domain.model.Homie
import com.hous.domain.model.HomieInfo

data class Homie(
@SerializedName("_id") val id: String? = null,
Expand All @@ -16,7 +16,7 @@ data class Homie(
var isChecked: Boolean = false,
val notificationState: Boolean = false
) {
fun toHomie(): Homie = Homie(
fun toHomieInfo(): HomieInfo = HomieInfo(
id,
userName,
typeName,
Expand Down
17 changes: 15 additions & 2 deletions data/src/main/java/com/hous/data/entity/Rule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hous.data.entity

import com.google.gson.annotations.SerializedName
import com.hous.domain.model.RuleInfo

data class Rule(
@SerializedName("_id") val id: String = "",
Expand All @@ -11,5 +12,17 @@ data class Rule(
val isAllChecked: Boolean = false,
val membersCnt: Int = 0,
val typeColors: List<String> = emptyList(),
val categoryIcon: String = "",
)
val categoryIcon: String = ""
) {
fun toRuleInfo() = RuleInfo(
id,
isChecked,
ruleName,
todayMembersWithTypeColor.map { it.toHomieInfo() },
isTmpMember,
isAllChecked,
membersCnt,
typeColors,
categoryIcon
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hous.data.model.response
package com.hous.data.model.request

data class TempManagerRequest(
val tmpRuleMembers: List<String> = emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ data class TempManagerResponse(
@SerializedName("_id")
val id: String = "",
val homies: List<Homie> = emptyList()
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.util.Log
import com.hous.data.model.request.Member
import com.hous.data.model.request.NewRulesRequest
import com.hous.data.source.remote.RemoteNewRulesDataSource
import com.hous.domain.model.DayData
import com.hous.domain.model.DayDataInfo
import com.hous.domain.model.Manager
import com.hous.domain.model.NewRuleInfo
import com.hous.domain.model.State
Expand Down Expand Up @@ -43,12 +43,12 @@ class NewRulesRepositoryImpl @Inject constructor(
runCatching {
val response = remoteNewRulesDataSource.getNewRuleList(roomId)
NewRuleInfo(
response.data!!.ruleCategories.map { it.toCategory() },
response.data.homies.map { it.toHomie() }
response.data!!.ruleCategories.map { it.toCategoryInfo() },
response.data.homies.map { it.toHomieInfo() }
)
}

private fun dayToInt(dayDataList: List<DayData>): List<Int> {
private fun dayToInt(dayDataList: List<DayDataInfo>): List<Int> {
val tempList = mutableListOf<Int>()
for (index in 0 until 7) {
if (dayDataList[index].dayState == State.SELECT) tempList.add(index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,54 @@ package com.hous.data.repository
import com.hous.data.entity.Rule
import com.hous.data.model.WrapperClass
import com.hous.data.model.request.MyToDoCheckRequest
import com.hous.data.model.request.TempManagerRequest
import com.hous.data.model.response.RulesTableResponse
import com.hous.data.model.response.RulesTodayInfoListResponse
import com.hous.data.model.response.TempManagerRequest
import com.hous.data.model.response.TempManagerResponse
import com.hous.data.source.remote.RemoteRulesTodayDataSource
import com.hous.domain.model.RuleInfo
import com.hous.domain.model.TempManagerInfo
import com.hous.domain.model.rules.RulesTableInfo
import com.hous.domain.model.rules.RulesTodayInfo
import javax.inject.Inject

class RulesTodayRepositoryImpl @Inject constructor(
private val remoteRulesTodayDataSource: RemoteRulesTodayDataSource
) : RulesTodayRepository {
override suspend fun getTodayTodayInfoList(roomId: String): Result<WrapperClass<RulesTodayInfoListResponse>> {
return runCatching { remoteRulesTodayDataSource.getTodayTodayInfoList(roomId) }
}
override suspend fun getTodayTodayInfoList(roomId: String): RulesTodayInfo? =
remoteRulesTodayDataSource.getTodayTodayInfoList(roomId)

override suspend fun getTempManagerInfoList(
roomId: String,
rulesId: String
): Result<WrapperClass<TempManagerResponse>> {
return runCatching { remoteRulesTodayDataSource.getTempManagerInfoList(roomId, rulesId) }
}
): TempManagerInfo? = remoteRulesTodayDataSource.getTempManagerInfoList(roomId, rulesId)

override suspend fun putTempManagerInfoList(
roomId: String,
ruleId: String,
tmpRuleMembers: TempManagerRequest
): Result<WrapperClass<Any>> {
return runCatching {
remoteRulesTodayDataSource.putTempManagerInfoList(
roomId,
ruleId,
tmpRuleMembers
)
}
tmpRuleMembers: List<String>
): Any? {
return remoteRulesTodayDataSource.putTempManagerInfoList(
roomId,
ruleId,
TempManagerRequest(tmpRuleMembers)
)
}

override suspend fun getMyTodoInfoList(roomId: String): Result<WrapperClass<List<Rule>>> {
return runCatching {
remoteRulesTodayDataSource.getMyToDoInfoList(roomId)
}
override suspend fun getMyTodoInfoList(roomId: String): List<RuleInfo>? {
return remoteRulesTodayDataSource.getMyToDoInfoList(roomId)

}

override suspend fun putMyToDoCheckLust(
roomId: String,
ruleId: String,
isCheck: MyToDoCheckRequest
): Result<WrapperClass<MyToDoCheckRequest>> {
return runCatching {
remoteRulesTodayDataSource.putMyToDoCheckLust(roomId, ruleId, isCheck)
}
isCheck: Boolean
) {
remoteRulesTodayDataSource.putMyToDoCheckLust(roomId, ruleId, MyToDoCheckRequest(isCheck))
}

override suspend fun getRuleTableInfoList(
roomId: String,
categoryId: String
): Result<WrapperClass<RulesTableResponse>> {
return runCatching {
remoteRulesTodayDataSource.getRuleTableInfoList(roomId, categoryId)
}
}
): RulesTableInfo? =
remoteRulesTodayDataSource.getRuleTableInfoList(roomId, categoryId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,36 @@ import com.hous.data.entity.Rule
import com.hous.data.model.WrapperClass
import com.hous.data.model.request.MyToDoCheckRequest
import com.hous.data.model.response.RulesTableResponse
import com.hous.data.model.response.RulesTodayInfoListResponse
import com.hous.data.model.response.TempManagerRequest
import com.hous.data.model.response.TempManagerResponse
import com.hous.data.model.request.TempManagerRequest
import com.hous.domain.model.RuleInfo
import com.hous.domain.model.rules.RulesTodayInfo
import com.hous.domain.model.TempManagerInfo
import com.hous.domain.model.rules.RulesTableInfo

interface RemoteRulesTodayDataSource {
suspend fun getTodayTodayInfoList(roomId: String): WrapperClass<RulesTodayInfoListResponse>
suspend fun getTodayTodayInfoList(roomId: String): RulesTodayInfo?

suspend fun getTempManagerInfoList(
roomId: String,
ruleId: String
): WrapperClass<TempManagerResponse>
): TempManagerInfo?

suspend fun putTempManagerInfoList(
roomId: String,
ruleId: String,
tmpRuleMembers: TempManagerRequest
): WrapperClass<Any>
): Any?

suspend fun getMyToDoInfoList(roomId: String): WrapperClass<List<Rule>>
suspend fun getMyToDoInfoList(roomId: String): List<RuleInfo>?

suspend fun putMyToDoCheckLust(
roomId: String,
ruleId: String,
isCheck: MyToDoCheckRequest
): WrapperClass<MyToDoCheckRequest>
)

suspend fun getRuleTableInfoList(
roomId: String,
categoryId: String
): WrapperClass<RulesTableResponse>
): RulesTableInfo?
}
Loading

0 comments on commit eebc8a9

Please sign in to comment.