Skip to content

Commit

Permalink
Merge pull request #363 from apeun-gidaechi/feature/362-rename-task-t…
Browse files Browse the repository at this point in the history
…o-assignment

Refactor/Rename task to assignment
  • Loading branch information
8954sood authored Nov 12, 2024
2 parents bb2b593 + afa196b commit a62cc5a
Show file tree
Hide file tree
Showing 39 changed files with 200 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ dependencies {

implementation(projects.common)
implementation(projects.network.core)
implementation(projects.network.task)
implementation(projects.network.assignment)
api(projects.data.core)
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.seugi.data.task
package com.seugi.data.assignment

import com.seugi.common.model.Result
import com.seugi.data.task.model.TaskModel
import com.seugi.data.assignment.model.AssignmentModel
import java.time.LocalDateTime
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.flow.Flow

interface TaskRepository {
interface AssignmentRepository {

suspend fun getWorkspaceTaskAll(workspaceId: String): Flow<Result<ImmutableList<TaskModel>>>
suspend fun getWorkspaceTaskAll(workspaceId: String): Flow<Result<ImmutableList<AssignmentModel>>>

suspend fun getGoogleTaskAll(): Flow<Result<ImmutableList<TaskModel>>>
suspend fun getGoogleTaskAll(): Flow<Result<ImmutableList<AssignmentModel>>>

suspend fun createTask(workspaceId: String, title: String, description: String, dueDate: LocalDateTime): Flow<Result<Boolean>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.seugi.data.assignment.di

import com.seugi.data.assignment.AssignmentRepository
import com.seugi.data.assignment.repository.AssignmentRepositoryImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface RepositoryModule {

@Singleton
@Binds
fun bindsAssignmentRepository(taskRepositoryImpl: AssignmentRepositoryImpl): AssignmentRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.seugi.data.assignment.mapper

import com.seugi.data.assignment.model.AssignmentModel
import com.seugi.data.assignment.model.AssignmentType
import com.seugi.network.assignment.response.AssignmentGoogleResponse
import com.seugi.network.assignment.response.AssignmentResponse
import kotlinx.datetime.toKotlinLocalDateTime

internal fun AssignmentResponse.toModel() = AssignmentModel(
id = id,
workspaceId = workspaceId,
title = title,
description = description,
dueDate = dueDate?.toKotlinLocalDateTime(),
type = AssignmentType.WORKSPACE,
link = null,
)

internal fun AssignmentGoogleResponse.toModel() = AssignmentModel(
id = id,
workspaceId = null,
title = title,
description = description,
dueDate = dueDate?.toKotlinLocalDateTime(),
type = AssignmentType.GOOGLE,
link = link,
)

@JvmName("ListTaskResponseToModels")
internal fun List<AssignmentResponse>.toModels() = this.map {
it.toModel()
}

@JvmName("ListTaskGoogleResponseToModels")
internal fun List<AssignmentGoogleResponse>.toModels() = this.map {
it.toModel()
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.seugi.data.task.model
package com.seugi.data.assignment.model

import kotlinx.datetime.LocalDateTime

data class TaskModel(
data class AssignmentModel(
val id: Long,
val workspaceId: String?,
val title: String,
val type: TaskType,
val type: AssignmentType,
val link: String?,
val description: String?,
val dueDate: LocalDateTime?,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.seugi.data.assignment.model

enum class AssignmentType {
GOOGLE,
WORKSPACE,
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.seugi.data.task.repository
package com.seugi.data.assignment.repository

import com.seugi.common.model.Result
import com.seugi.common.model.asResult
import com.seugi.common.utiles.DispatcherType
import com.seugi.common.utiles.SeugiDispatcher
import com.seugi.data.task.TaskRepository
import com.seugi.data.task.mapper.toModels
import com.seugi.data.task.model.TaskModel
import com.seugi.data.assignment.AssignmentRepository
import com.seugi.data.assignment.mapper.toModels
import com.seugi.data.assignment.model.AssignmentModel
import com.seugi.network.assignment.AssignmentDataSource
import com.seugi.network.core.response.safeResponse
import com.seugi.network.task.TaskDataSource
import java.time.LocalDateTime
import javax.inject.Inject
import kotlinx.collections.immutable.ImmutableList
Expand All @@ -18,12 +18,12 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn

class TaskRepositoryImpl @Inject constructor(
private val taskDataSource: TaskDataSource,
class AssignmentRepositoryImpl @Inject constructor(
private val assignmentDataSource: AssignmentDataSource,
@SeugiDispatcher(DispatcherType.IO) private val dispatcher: CoroutineDispatcher,
) : TaskRepository {
) : AssignmentRepository {
override suspend fun getWorkspaceTaskAll(workspaceId: String) = flow {
val response = taskDataSource.getWorkspaceTaskAll(
val response = assignmentDataSource.getWorkspaceTaskAll(
workspaceId = workspaceId,
).safeResponse()

Expand All @@ -32,16 +32,16 @@ class TaskRepositoryImpl @Inject constructor(
.flowOn(dispatcher)
.asResult()

override suspend fun getGoogleTaskAll(): Flow<Result<ImmutableList<TaskModel>>> = flow {
val response = taskDataSource.getClassroomAll().safeResponse()
override suspend fun getGoogleTaskAll(): Flow<Result<ImmutableList<AssignmentModel>>> = flow {
val response = assignmentDataSource.getClassroomAll().safeResponse()

emit(response.toModels().toImmutableList())
}
.flowOn(dispatcher)
.asResult()

override suspend fun createTask(workspaceId: String, title: String, description: String, dueDate: LocalDateTime) = flow {
val response = taskDataSource.createTask(
val response = assignmentDataSource.createTask(
workspaceId = workspaceId,
title = title,
description = description,
Expand Down
18 changes: 0 additions & 18 deletions data/task/src/main/java/com/seugi/data/task/di/RepositoryModule.kt

This file was deleted.

37 changes: 0 additions & 37 deletions data/task/src/main/java/com/seugi/data/task/mapper/TaskMapper.kt

This file was deleted.

6 changes: 0 additions & 6 deletions data/task/src/main/java/com/seugi/data/task/model/TaskType.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ dependencies {
implementation(projects.designsystem)
implementation(projects.common)
implementation(projects.ui)
implementation(projects.data.task)
implementation(projects.data.assignment)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.seugi.task.create
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.seugi.common.model.Result
import com.seugi.data.task.TaskRepository
import com.seugi.data.assignment.AssignmentRepository
import com.seugi.task.create.model.TaskCreateSideEffect
import dagger.hilt.android.lifecycle.HiltViewModel
import java.time.LocalDateTime
Expand All @@ -14,14 +14,14 @@ import kotlinx.coroutines.launch

@HiltViewModel
class TaskCreateViewModel @Inject constructor(
private val taskRepository: TaskRepository,
private val assignmentRepository: AssignmentRepository,
) : ViewModel() {

private val _sideEffect = Channel<TaskCreateSideEffect>()
val sideEffect = _sideEffect.receiveAsFlow()

fun createTask(workspaceId: String, title: String, description: String, dueDate: LocalDateTime) = viewModelScope.launch {
taskRepository.createTask(
assignmentRepository.createTask(
workspaceId = workspaceId,
title = title,
description = description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ dependencies {
implementation(projects.designsystem)
implementation(projects.common)
implementation(projects.ui)
implementation(projects.data.task)
implementation(projects.data.assignment)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.seugi.task
package com.seugi.assignment

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -28,20 +28,20 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.seugi.assignment.model.CommonUiState
import com.seugi.data.core.model.ProfileModel
import com.seugi.data.core.model.isTeacher
import com.seugi.designsystem.R
import com.seugi.designsystem.component.SeugiTopBar
import com.seugi.designsystem.component.modifier.DropShadowType
import com.seugi.designsystem.component.modifier.dropShadow
import com.seugi.designsystem.theme.SeugiTheme
import com.seugi.task.model.CommonUiState
import java.time.LocalDate
import kotlinx.datetime.daysUntil
import kotlinx.datetime.toKotlinLocalDate

@Composable
internal fun TaskScreen(viewModel: TaskViewModel = hiltViewModel(), popBackStack: () -> Unit, workspaceId: String, profile: ProfileModel, navigateToTaskCreate: () -> Unit) {
internal fun AssignmentScreen(viewModel: AssignmentViewModel = hiltViewModel(), popBackStack: () -> Unit, workspaceId: String, profile: ProfileModel, navigateToTaskCreate: () -> Unit) {
val uiState by viewModel.state.collectAsStateWithLifecycle()

LaunchedEffect(workspaceId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.seugi.task
package com.seugi.assignment

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.seugi.assignment.model.AssignmentUiState
import com.seugi.assignment.model.CommonUiState
import com.seugi.common.model.Result
import com.seugi.data.task.TaskRepository
import com.seugi.task.model.CommonUiState
import com.seugi.task.model.TaskUiState
import com.seugi.data.assignment.AssignmentRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.collections.immutable.toImmutableList
Expand All @@ -15,15 +15,15 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch

@HiltViewModel
class TaskViewModel @Inject constructor(
private val taskRepository: TaskRepository,
class AssignmentViewModel @Inject constructor(
private val assignmentRepository: AssignmentRepository,
) : ViewModel() {

private val _state = MutableStateFlow(TaskUiState())
private val _state = MutableStateFlow(AssignmentUiState())
val state = _state.asStateFlow()

fun getClassroomTask() = viewModelScope.launch {
taskRepository.getGoogleTaskAll().collect {
assignmentRepository.getGoogleTaskAll().collect {
when (it) {
is Result.Success -> {
_state.update { state ->
Expand All @@ -49,7 +49,7 @@ class TaskViewModel @Inject constructor(
}

fun getWorkspaceTask(workspaceId: String) = viewModelScope.launch {
taskRepository.getWorkspaceTaskAll(workspaceId).collect {
assignmentRepository.getWorkspaceTaskAll(workspaceId).collect {
when (it) {
is Result.Success -> {
_state.update { state ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.seugi.assignment.model

import com.seugi.data.assignment.model.AssignmentModel
import kotlinx.collections.immutable.ImmutableList

data class AssignmentUiState(
val classroomTaskState: CommonUiState<ImmutableList<AssignmentModel>> = CommonUiState.Loading,
val workspaceTaskState: CommonUiState<ImmutableList<AssignmentModel>> = CommonUiState.Loading,
)

sealed interface CommonUiState<out T> {
data class Success<out T>(val data: T) : CommonUiState<T>
data object Loading : CommonUiState<Nothing>
data object Error : CommonUiState<Nothing>
data object NotFound : CommonUiState<Nothing>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.seugi.assignment.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.seugi.assignment.AssignmentScreen
import com.seugi.data.core.model.ProfileModel

const val ASSIGNMENT_ROUTE = "task"

fun NavController.navigateToAssignment(navOptions: NavOptions? = null) = this.navigate(ASSIGNMENT_ROUTE, navOptions)

fun NavGraphBuilder.assignmentScreen(popBackStack: () -> Unit, workspaceId: String, profile: ProfileModel, navigateToTaskCreate: () -> Unit) {
composable(ASSIGNMENT_ROUTE) {
AssignmentScreen(
popBackStack = popBackStack,
workspaceId = workspaceId,
profile = profile,
navigateToTaskCreate = navigateToTaskCreate,
)
}
}
2 changes: 1 addition & 1 deletion feature-main/home/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ dependencies {
implementation(projects.data.meal)
implementation(projects.data.timetable)
implementation(projects.data.schedule)
implementation(projects.data.task)
implementation(projects.data.assignment)
implementation(projects.common)
}
Loading

0 comments on commit a62cc5a

Please sign in to comment.