Skip to content

Commit

Permalink
Merge pull request #104 from YAPP-Github/feature/issue-103-create-tim…
Browse files Browse the repository at this point in the history
…etable

[ISSUE-103]  약속생성 - 시간표 UI & Api 연동
  • Loading branch information
KwonDae authored Jul 22, 2022
2 parents 563fe3e + 99bbee5 commit eefeba0
Show file tree
Hide file tree
Showing 30 changed files with 778 additions and 121 deletions.
11 changes: 11 additions & 0 deletions data/src/main/java/com/yapp/growth/data/api/GrowthApi.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package com.yapp.growth.data.api

import com.yapp.growth.data.internal.response.CreateTimeTableResponseImpl
import com.yapp.growth.data.internal.response.PromisingTimeTableResponseImpl
import com.yapp.growth.data.internal.response.TimeRequestResponseImpl
import com.yapp.growth.data.parameter.TimeRequestParameter
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path

interface GrowthApi {

@GET("/api/promisings/{promisingId}/time-table")
suspend fun getResponseTimeTable(@Path("promisingId") promisingId: String): PromisingTimeTableResponseImpl

@GET("/api/promisings/session/{uuid}")
suspend fun getCreateTimeTable(@Path("uuid") uuid: String): CreateTimeTableResponseImpl

@POST("/api/promisings/session/{uuid}/time-response")
suspend fun sendTimeCheckedOfDay(@Path("uuid") uuid: String, @Body timeRequestParameter: TimeRequestParameter): TimeRequestResponseImpl

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.yapp.growth.data.di

import com.yapp.growth.data.source.ConfirmPlanDataSource
import com.yapp.growth.data.source.ConfirmPlanDataSourceImpl
import com.yapp.growth.data.internal.source.ConfirmPlanDataSourceImpl
import com.yapp.growth.data.internal.source.CreateTimeTableDataSourceImpl
import com.yapp.growth.data.source.CreateTimeTableDataSource
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -15,4 +17,8 @@ internal abstract class DataSourceModule {
@Binds
@Singleton
abstract fun bindConfirmPlanDataSource(confirmPlanDataSource: ConfirmPlanDataSourceImpl): ConfirmPlanDataSource

@Binds
@Singleton
abstract fun bindCreateTimeTableDataSource(createTimeTableDataSource: CreateTimeTableDataSourceImpl): CreateTimeTableDataSource
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.yapp.growth.data.di

import com.yapp.growth.data.repository.ConfirmPlanRepositoryImpl
import com.yapp.growth.data.repository.CreateTimeTableRepositoryImpl
import com.yapp.growth.domain.repository.ConfirmPlanRepository
import com.yapp.growth.domain.repository.CreateTimeTableRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -15,4 +17,8 @@ internal abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindConfirmPlanRepository(confirmPlanRepository: ConfirmPlanRepositoryImpl): ConfirmPlanRepository

@Binds
@Singleton
abstract fun bindCreateTimeTableRepository(createTimeTableRepository: CreateTimeTableRepositoryImpl): CreateTimeTableRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.yapp.growth.data.internal.response

import com.yapp.growth.data.response.CreateTimeTableResponse

data class CreateTimeTableResponseImpl(
override val minTime: String,
override val maxTime: String,
override val totalCount: Int,
override val unit: Float,
override val availableDates: List<String>
): CreateTimeTableResponse
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.yapp.growth.data.internal.response

import com.yapp.growth.data.response.TimeRequestResponse

data class TimeRequestResponseImpl(
override val id: Long

): TimeRequestResponse
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.yapp.growth.data.internal.source

import com.yapp.growth.data.api.GrowthApi
import com.yapp.growth.data.api.handleApi
import com.yapp.growth.data.mapper.toTimeTable
import com.yapp.growth.data.source.ConfirmPlanDataSource
import com.yapp.growth.domain.NetworkResult
import com.yapp.growth.domain.entity.TimeTable
import javax.inject.Inject

internal class ConfirmPlanDataSourceImpl @Inject constructor(
private val retrofitApi: GrowthApi
) : ConfirmPlanDataSource {

override suspend fun getRespondUsers(promisingId: Long): NetworkResult<TimeTable> =
handleApi {
retrofitApi.getResponseTimeTable(promisingId.toString()).toTimeTable()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.yapp.growth.data.internal.source

import com.yapp.growth.data.api.GrowthApi
import com.yapp.growth.data.api.handleApi
import com.yapp.growth.data.mapper.toCreateTimeTable
import com.yapp.growth.data.mapper.toLong
import com.yapp.growth.data.parameter.TimeCheckedOfDayParameter
import com.yapp.growth.data.parameter.TimeRequestParameter
import com.yapp.growth.data.source.CreateTimeTableDataSource
import com.yapp.growth.domain.NetworkResult
import com.yapp.growth.domain.entity.CreateTimeTable
import com.yapp.growth.domain.entity.TimeCheckedOfDay
import javax.inject.Inject

internal class CreateTimeTableDataSourceImpl @Inject constructor(
private val retrofitApi: GrowthApi
): CreateTimeTableDataSource {

override suspend fun getCreateTimeTable(uuid: String): NetworkResult<CreateTimeTable> =
handleApi {
retrofitApi.getCreateTimeTable(uuid).toCreateTimeTable()
}

override suspend fun sendTimeCheckedOfDay(
uuid: String,
timeCheckedOfDays: List<TimeCheckedOfDay>
): NetworkResult<Long> =
handleApi {
val parameter = TimeRequestParameter(
unit = 0.5f,
timeTable = timeCheckedOfDays.map {
TimeCheckedOfDayParameter(
date = it.date,
times = it.timeList
)
}
)
retrofitApi.sendTimeCheckedOfDay(uuid, parameter).toLong()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.yapp.growth.data.mapper

import com.yapp.growth.data.response.CreateTimeTableResponse
import com.yapp.growth.data.response.TimeRequestResponse
import com.yapp.growth.domain.entity.CreateTimeTable
import com.yapp.growth.domain.entity.TimeCheckedOfDay
import java.text.SimpleDateFormat
import java.util.*

private val parseFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.KOREA)
private val hourFormat = SimpleDateFormat("HH:mm", Locale.KOREA)

fun CreateTimeTableResponse.toCreateTimeTable(): CreateTimeTable {
val response = this
return CreateTimeTable(
totalCount = response.totalCount/2,
minTime = response.minTime,
maxTime = response.maxTime,
availableDates = response.availableDates,
hourList = makeHourList(response.minTime, response.totalCount/2),
)
}

fun TimeRequestResponse.toLong(): Long {
return this.id
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.*
private val parseFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.KOREA)
private val hourFormat = SimpleDateFormat("HH:mm", Locale.KOREA)

fun PromisingTimeTableResponse.toResponsePlan(): TimeTable {
fun PromisingTimeTableResponse.toTimeTable(): TimeTable {
val response = this
return TimeTable(
users = response.members.toUserList(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.yapp.growth.data.parameter

data class TimeRequestParameter(
val unit: Float,
val timeTable: List<TimeCheckedOfDayParameter>
)

data class TimeCheckedOfDayParameter(
val date: String,
val times: List<Boolean>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.yapp.growth.data.repository

import com.yapp.growth.data.source.CreateTimeTableDataSource
import com.yapp.growth.domain.NetworkResult
import com.yapp.growth.domain.entity.CreateTimeTable
import com.yapp.growth.domain.entity.TimeCheckedOfDay
import com.yapp.growth.domain.repository.CreateTimeTableRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
internal class CreateTimeTableRepositoryImpl @Inject constructor(
private val dataSource: CreateTimeTableDataSource
): CreateTimeTableRepository {

override suspend fun getCreateTimeTable(uuid: String): NetworkResult<CreateTimeTable> {
return dataSource.getCreateTimeTable(uuid)
}

override suspend fun sendTimeCheckedOfDay(
uuid: String,
timeCheckedOfDays: List<TimeCheckedOfDay>
): NetworkResult<Long> {
return dataSource.sendTimeCheckedOfDay(uuid, timeCheckedOfDays)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.yapp.growth.data.response

interface CreateTimeTableResponse {
val minTime: String
val maxTime: String
val totalCount: Int
val unit: Float
val availableDates: List<String>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yapp.growth.data.response

interface TimeRequestResponse {
val id: Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import com.yapp.growth.domain.entity.TimeTable
interface ConfirmPlanDataSource {

suspend fun getRespondUsers(promisingId: Long): NetworkResult<TimeTable>

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.yapp.growth.data.source

import com.yapp.growth.data.internal.response.TimeRequestResponseImpl
import com.yapp.growth.domain.NetworkResult
import com.yapp.growth.domain.entity.CreateTimeTable
import com.yapp.growth.domain.entity.TimeCheckedOfDay

interface CreateTimeTableDataSource {

suspend fun getCreateTimeTable(uuid: String): NetworkResult<CreateTimeTable>

suspend fun sendTimeCheckedOfDay(uuid: String, timeCheckedOfDays: List<TimeCheckedOfDay>): NetworkResult<Long>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.yapp.growth.domain.entity

data class CreateTimeTable(
val totalCount: Int,
val minTime: String,
val maxTime: String,
var availableDates: List<String>,
val hourList: List<String>,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.yapp.growth.domain.entity

data class SendingResponsePlan(
data class TimeCheckedOfDay(
val date: String,
val hours: List<String>,
val timeList: MutableList<Boolean>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.yapp.growth.domain.repository

import com.yapp.growth.domain.NetworkResult
import com.yapp.growth.domain.entity.CreateTimeTable
import com.yapp.growth.domain.entity.TimeCheckedOfDay

interface CreateTimeTableRepository {

suspend fun getCreateTimeTable(uuid: String): NetworkResult<CreateTimeTable>

suspend fun sendTimeCheckedOfDay(uuid: String, timeCheckedOfDays: List<TimeCheckedOfDay>): NetworkResult<Long>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.yapp.growth.domain.usecase

import com.yapp.growth.domain.NetworkResult
import com.yapp.growth.domain.entity.CreateTimeTable
import com.yapp.growth.domain.repository.CreateTimeTableRepository
import javax.inject.Inject

class GetCreateTimeTableUseCase @Inject constructor(
private val repository: CreateTimeTableRepository
) {
suspend operator fun invoke(uuid: String): NetworkResult<CreateTimeTable> {
return repository.getCreateTimeTable(uuid)
}
}
Loading

0 comments on commit eefeba0

Please sign in to comment.