-
Notifications
You must be signed in to change notification settings - Fork 9
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
[Feature/#1049] Schedule 화면에 api를 연결합니다. #1050
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9bcb0ef
feat #1049: feat domain
chattymin 2f740e8
feat #1049: feat data
chattymin ec78768
feat #1049: feat domain
chattymin 355c2b4
feat #1049: feat feature
chattymin 4c02d03
feat #1047: feat data
chattymin fbf4e25
feat #1047: fix feature directory and chore
chattymin 4dda19c
feat #1047: feat feature with api
chattymin b9868f7
Merge branch 'feature/app-home' into feature/app-home-#1049
chattymin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
plugins { | ||
sopt("feature") | ||
} | ||
|
||
android { | ||
namespace = "org.sopt.official.data.schedule" | ||
} | ||
|
||
dependencies { | ||
implementation(projects.domain.schedule) | ||
|
||
implementation(projects.core.network) | ||
implementation(projects.core.common) | ||
implementation(platform(libs.okhttp.bom)) | ||
implementation(libs.bundles.okhttp) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
9 changes: 9 additions & 0 deletions
9
data/schedule/src/main/java/org/sopt/official/data/schedule/api/ScheduleApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.sopt.official.data.schedule.api | ||
|
||
import org.sopt.official.data.schedule.dto.ScheduleResponse | ||
import retrofit2.http.GET | ||
|
||
interface ScheduleApi { | ||
@GET("calendar/all") | ||
suspend fun getSchedule(): List<ScheduleResponse> | ||
} |
19 changes: 19 additions & 0 deletions
19
data/schedule/src/main/java/org/sopt/official/data/schedule/di/ApiModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.sopt.official.data.schedule.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.official.common.di.AppRetrofit | ||
import org.sopt.official.data.schedule.api.ScheduleApi | ||
import retrofit2.Retrofit | ||
import retrofit2.create | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ApiModule { | ||
@Provides | ||
@Singleton | ||
internal fun provideScheduleApi(@AppRetrofit(true) retrofit: Retrofit): ScheduleApi = retrofit.create() | ||
} |
17 changes: 17 additions & 0 deletions
17
data/schedule/src/main/java/org/sopt/official/data/schedule/di/RepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.sopt.official.data.schedule.di | ||
|
||
import org.sopt.official.domain.schedule.repository.ScheduleRepository | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.official.data.schedule.repository.DefaultScheduleRepository | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal interface RepositoryModule { | ||
@Binds | ||
@Singleton | ||
fun bindDefaultScheduleRepositoryRepository(defaultScheduleRepository: DefaultScheduleRepository): ScheduleRepository | ||
} |
16 changes: 16 additions & 0 deletions
16
data/schedule/src/main/java/org/sopt/official/data/schedule/dto/ScheduleResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.sopt.official.data.schedule.dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ScheduleResponse( | ||
@SerialName("date") | ||
val date: String, | ||
@SerialName("title") | ||
val title: String, | ||
@SerialName("type") | ||
val type: String, | ||
@SerialName("isRecentSchedule") | ||
val isRecentSchedule: Boolean, | ||
) |
11 changes: 11 additions & 0 deletions
11
data/schedule/src/main/java/org/sopt/official/data/schedule/mapper/ScheduleMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.sopt.official.data.schedule.mapper | ||
|
||
import org.sopt.official.domain.schedule.model.Schedule | ||
import org.sopt.official.data.schedule.dto.ScheduleResponse | ||
|
||
fun ScheduleResponse.toDomain() = Schedule( | ||
date = date, | ||
title = title, | ||
type = type, | ||
isRecentSchedule = isRecentSchedule | ||
) |
15 changes: 15 additions & 0 deletions
15
...ule/src/main/java/org/sopt/official/data/schedule/repository/DefaultScheduleRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.sopt.official.data.schedule.repository | ||
|
||
import org.sopt.official.domain.schedule.model.Schedule | ||
import org.sopt.official.domain.schedule.repository.ScheduleRepository | ||
import org.sopt.official.data.schedule.api.ScheduleApi | ||
import org.sopt.official.data.schedule.mapper.toDomain | ||
import javax.inject.Inject | ||
|
||
class DefaultScheduleRepository @Inject constructor( | ||
private val scheduleApi: ScheduleApi, | ||
) : ScheduleRepository { | ||
override suspend fun getScheduleList(): Result<List<Schedule>> = runCatching { | ||
scheduleApi.getSchedule().map { it.toDomain() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
sopt("kotlin") | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(17) | ||
} |
8 changes: 8 additions & 0 deletions
8
domain/schedule/src/main/java/org/sopt/official/domain/schedule/model/Schedule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.sopt.official.domain.schedule.model | ||
|
||
data class Schedule( | ||
val date: String, | ||
val title: String, | ||
val type: String, | ||
val isRecentSchedule: Boolean, | ||
) |
7 changes: 7 additions & 0 deletions
7
...schedule/src/main/java/org/sopt/official/domain/schedule/repository/ScheduleRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.sopt.official.domain.schedule.repository | ||
|
||
import org.sopt.official.domain.schedule.model.Schedule | ||
|
||
interface ScheduleRepository { | ||
suspend fun getScheduleList(): Result<List<Schedule>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
feature/schedule/src/main/java/org/sopt/official/feature/schedule/ScheduleViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.sopt.official.feature.schedule | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.collections.immutable.ImmutableList | ||
import kotlinx.collections.immutable.persistentListOf | ||
import kotlinx.collections.immutable.toPersistentList | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.coroutines.launch | ||
import org.sopt.official.domain.schedule.model.Schedule | ||
import org.sopt.official.domain.schedule.repository.ScheduleRepository | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class ScheduleViewModel @Inject constructor( | ||
private val scheduleRepository: ScheduleRepository, | ||
) : ViewModel() { | ||
private val _schedule = MutableStateFlow(ScheduleState()) | ||
val schedule: StateFlow<ScheduleState> | ||
get() = _schedule.asStateFlow() | ||
|
||
init { | ||
getScheduleList() | ||
} | ||
|
||
private fun getScheduleList() { | ||
viewModelScope.launch { | ||
_schedule.update { | ||
it.copy(isLoading = true) | ||
} | ||
scheduleRepository.getScheduleList().onSuccess { scheduleList -> | ||
_schedule.update { | ||
it.copy( | ||
scheduleList = scheduleList.toPersistentList(), | ||
isLoading = false, | ||
) | ||
} | ||
}.onFailure { error -> | ||
Timber.e(error) | ||
_schedule.update { | ||
it.copy( | ||
isLoading = false, | ||
isError = true, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
data class ScheduleState( | ||
val scheduleList: ImmutableList<Schedule> = persistentListOf(), | ||
val isLoading: Boolean = false, | ||
val isError: Boolean = false, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이걸 추가한 이유가 있을까요?