diff --git a/core/data/src/main/java/com/school_of_company/data/di/RepositoryModule.kt b/core/data/src/main/java/com/school_of_company/data/di/RepositoryModule.kt index 0433cd28..2c795eb5 100644 --- a/core/data/src/main/java/com/school_of_company/data/di/RepositoryModule.kt +++ b/core/data/src/main/java/com/school_of_company/data/di/RepositoryModule.kt @@ -8,6 +8,8 @@ import com.school_of_company.data.repository.image.ImageRepository import com.school_of_company.data.repository.image.ImageRepositoryImpl import com.school_of_company.data.repository.sms.SmsRepository import com.school_of_company.data.repository.sms.SmsRepositoryImpl +import com.school_of_company.data.repository.training.TrainingRepository +import com.school_of_company.data.repository.training.TrainingRepositoryImpl import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -36,4 +38,9 @@ abstract class RepositoryModule { abstract fun bindImageRepository( imageRepositoryImpl: ImageRepositoryImpl ) : ImageRepository + + @Binds + abstract fun bindTrainingRepository( + trainingRepositoryImpl: TrainingRepositoryImpl + ) : TrainingRepository } \ No newline at end of file diff --git a/core/data/src/main/java/com/school_of_company/data/repository/training/TrainingRepository.kt b/core/data/src/main/java/com/school_of_company/data/repository/training/TrainingRepository.kt new file mode 100644 index 00000000..d1f972c9 --- /dev/null +++ b/core/data/src/main/java/com/school_of_company/data/repository/training/TrainingRepository.kt @@ -0,0 +1,15 @@ +package com.school_of_company.data.repository.training + +import com.school_of_company.model.entity.training.TeacherTrainingProgramResponseEntity +import com.school_of_company.model.entity.training.TrainingProgramListResponseEntity +import com.school_of_company.model.model.training.TrainingDtoModel +import kotlinx.coroutines.flow.Flow + +interface TrainingRepository { + fun registerTrainingProgram(expoId: String, body: TrainingDtoModel) : Flow + fun registerTrainingProgramList(expoId: String, body: List) : Flow + fun modifyTrainingProgram(trainingProId: Long, body: TrainingDtoModel) : Flow + fun deleteTrainingProgram(trainingProId: Long) : Flow + fun trainingProgramList(expoId: String) : Flow> + fun teacherTrainingProgramList(trainingProId: Long) : Flow> +} \ No newline at end of file diff --git a/core/data/src/main/java/com/school_of_company/data/repository/training/TrainingRepositoryImpl.kt b/core/data/src/main/java/com/school_of_company/data/repository/training/TrainingRepositoryImpl.kt new file mode 100644 index 00000000..c505ca70 --- /dev/null +++ b/core/data/src/main/java/com/school_of_company/data/repository/training/TrainingRepositoryImpl.kt @@ -0,0 +1,59 @@ +package com.school_of_company.data.repository.training + +import com.school_of_company.model.entity.training.TeacherTrainingProgramResponseEntity +import com.school_of_company.model.entity.training.TrainingProgramListResponseEntity +import com.school_of_company.model.model.training.TrainingDtoModel +import com.school_of_company.network.datasource.training.TrainingDataSource +import com.school_of_company.network.mapper.expo.response.toEntity +import com.school_of_company.network.mapper.training.request.toDto +import com.school_of_company.network.mapper.training.response.toEntity +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.transform +import javax.inject.Inject + +class TrainingRepositoryImpl @Inject constructor( + private val dataSource: TrainingDataSource +) : TrainingRepository { + override fun registerTrainingProgram(expoId: String, body: TrainingDtoModel): Flow { + return dataSource.registerTrainingProgram( + expoId = expoId, + body = body.toDto() + ) + } + + override fun registerTrainingProgramList( + expoId: String, + body: List + ): Flow { + return dataSource.registerTrainingProgramList( + expoId = expoId, + body = body.map { it.toDto() } + ) + } + + override fun modifyTrainingProgram( + trainingProId: Long, + body: TrainingDtoModel + ): Flow { + return dataSource.modifyTrainingProgram( + trainingProId = trainingProId, + body = body.toDto() + ) + } + + override fun deleteTrainingProgram(trainingProId: Long): Flow { + return dataSource.deleteTrainingProgram(trainingProId = trainingProId) + } + + override fun trainingProgramList(expoId: String): Flow> { + return dataSource.trainingProgramList(expoId = expoId).transform { list -> + emit(list.map { it.toEntity() }) + } + } + + override fun teacherTrainingProgramList(trainingProId: Long): Flow> { + return dataSource.teacherTrainingProgramList(trainingProId = trainingProId).transform { list -> + emit(list.map { it.toEntity() }) + } + } +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/school_of_company/domain/usecase/training/DeleteTrainingProgramUseCase.kt b/core/domain/src/main/java/com/school_of_company/domain/usecase/training/DeleteTrainingProgramUseCase.kt new file mode 100644 index 00000000..8595f216 --- /dev/null +++ b/core/domain/src/main/java/com/school_of_company/domain/usecase/training/DeleteTrainingProgramUseCase.kt @@ -0,0 +1,12 @@ +package com.school_of_company.domain.usecase.training + +import com.school_of_company.data.repository.training.TrainingRepository +import javax.inject.Inject + +class DeleteTrainingProgramUseCase @Inject constructor( + private val repository: TrainingRepository +) { + operator fun invoke(trainingProId: Long) = runCatching { + repository.deleteTrainingProgram(trainingProId = trainingProId) + } +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/school_of_company/domain/usecase/training/ModifyTrainingProgramUseCase.kt b/core/domain/src/main/java/com/school_of_company/domain/usecase/training/ModifyTrainingProgramUseCase.kt new file mode 100644 index 00000000..7917f8cc --- /dev/null +++ b/core/domain/src/main/java/com/school_of_company/domain/usecase/training/ModifyTrainingProgramUseCase.kt @@ -0,0 +1,19 @@ +package com.school_of_company.domain.usecase.training + +import com.school_of_company.data.repository.training.TrainingRepository +import com.school_of_company.model.model.training.TrainingDtoModel +import javax.inject.Inject + +class ModifyTrainingProgramUseCase @Inject constructor( + private val repository: TrainingRepository +) { + operator fun invoke( + trainingProId: Long, + body: TrainingDtoModel + ) = runCatching { + repository.modifyTrainingProgram( + trainingProId = trainingProId, + body = body + ) + } +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/school_of_company/domain/usecase/training/RegisterTrainingProgramListUseCase.kt b/core/domain/src/main/java/com/school_of_company/domain/usecase/training/RegisterTrainingProgramListUseCase.kt new file mode 100644 index 00000000..cc7c1277 --- /dev/null +++ b/core/domain/src/main/java/com/school_of_company/domain/usecase/training/RegisterTrainingProgramListUseCase.kt @@ -0,0 +1,19 @@ +package com.school_of_company.domain.usecase.training + +import com.school_of_company.data.repository.training.TrainingRepository +import com.school_of_company.model.model.training.TrainingDtoModel +import javax.inject.Inject + +class RegisterTrainingProgramListUseCase @Inject constructor( + private val repository: TrainingRepository +) { + operator fun invoke( + expoId: String, + body: List + ) = runCatching { + repository.registerTrainingProgramList( + expoId = expoId, + body = body + ) + } +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/school_of_company/domain/usecase/training/RegisterTrainingProgramUseCase.kt b/core/domain/src/main/java/com/school_of_company/domain/usecase/training/RegisterTrainingProgramUseCase.kt new file mode 100644 index 00000000..be89325c --- /dev/null +++ b/core/domain/src/main/java/com/school_of_company/domain/usecase/training/RegisterTrainingProgramUseCase.kt @@ -0,0 +1,19 @@ +package com.school_of_company.domain.usecase.training + +import com.school_of_company.data.repository.training.TrainingRepository +import com.school_of_company.model.model.training.TrainingDtoModel +import javax.inject.Inject + +class RegisterTrainingProgramUseCase @Inject constructor( + private val repository: TrainingRepository +) { + operator fun invoke( + expoId: String, + body: TrainingDtoModel + ) = runCatching { + repository.registerTrainingProgram( + expoId = expoId, + body = body + ) + } +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/school_of_company/domain/usecase/training/TeacherTrainingProgramListUseCase.kt b/core/domain/src/main/java/com/school_of_company/domain/usecase/training/TeacherTrainingProgramListUseCase.kt new file mode 100644 index 00000000..db9b3612 --- /dev/null +++ b/core/domain/src/main/java/com/school_of_company/domain/usecase/training/TeacherTrainingProgramListUseCase.kt @@ -0,0 +1,13 @@ +package com.school_of_company.domain.usecase.training + +import com.school_of_company.data.repository.training.TrainingRepository +import com.school_of_company.model.entity.training.TeacherTrainingProgramResponseEntity +import kotlinx.coroutines.flow.Flow +import javax.inject.Inject + +class TeacherTrainingProgramListUseCase @Inject constructor( + private val repository: TrainingRepository +) { + operator fun invoke(trainingProId: Long): Flow> = + repository.teacherTrainingProgramList(trainingProId = trainingProId) +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/school_of_company/domain/usecase/training/TrainingProgramListUseCase.kt b/core/domain/src/main/java/com/school_of_company/domain/usecase/training/TrainingProgramListUseCase.kt new file mode 100644 index 00000000..a84c81e9 --- /dev/null +++ b/core/domain/src/main/java/com/school_of_company/domain/usecase/training/TrainingProgramListUseCase.kt @@ -0,0 +1,13 @@ +package com.school_of_company.domain.usecase.training + +import com.school_of_company.data.repository.training.TrainingRepository +import com.school_of_company.model.entity.training.TrainingProgramListResponseEntity +import kotlinx.coroutines.flow.Flow +import javax.inject.Inject + +class TrainingProgramListUseCase @Inject constructor( + private val repository: TrainingRepository +) { + operator fun invoke(expoId: String): Flow> = + repository.trainingProgramList(expoId = expoId) +} \ No newline at end of file diff --git a/core/model/src/main/java/com/school_of_company/model/entity/training/TeacherTrainingProgramResponseEntity.kt b/core/model/src/main/java/com/school_of_company/model/entity/training/TeacherTrainingProgramResponseEntity.kt new file mode 100644 index 00000000..56e8ef7d --- /dev/null +++ b/core/model/src/main/java/com/school_of_company/model/entity/training/TeacherTrainingProgramResponseEntity.kt @@ -0,0 +1,11 @@ +package com.school_of_company.model.entity.training + +data class TeacherTrainingProgramResponseEntity( + val name: String, + val organization: String, + val position: String, + val programName: String, + val status: Boolean, + val entryTime: String, + val leaveTime: String +) \ No newline at end of file diff --git a/core/model/src/main/java/com/school_of_company/model/entity/training/TrainingProgramListResponseEntity.kt b/core/model/src/main/java/com/school_of_company/model/entity/training/TrainingProgramListResponseEntity.kt new file mode 100644 index 00000000..af980f07 --- /dev/null +++ b/core/model/src/main/java/com/school_of_company/model/entity/training/TrainingProgramListResponseEntity.kt @@ -0,0 +1,12 @@ +package com.school_of_company.model.entity.training + +data class TrainingProgramListResponseEntity( + val essential: List, + val choice: List +) { + data class Training( + val title: String, + val startedAt: String, + val endedAt: String, + ) +} diff --git a/core/model/src/main/java/com/school_of_company/model/model/.gitkeep b/core/model/src/main/java/com/school_of_company/model/model/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/core/model/src/main/java/com/school_of_company/model/model/training/TrainingDtoModel.kt b/core/model/src/main/java/com/school_of_company/model/model/training/TrainingDtoModel.kt new file mode 100644 index 00000000..4d328d5f --- /dev/null +++ b/core/model/src/main/java/com/school_of_company/model/model/training/TrainingDtoModel.kt @@ -0,0 +1,8 @@ +package com.school_of_company.model.model.training + +data class TrainingDtoModel( + val title: String, + val startedAt: String, + val finishedAt: String, + val category: String, +) diff --git a/core/network/src/main/java/com/school_of_company/network/api/ExpoAPI.kt b/core/network/src/main/java/com/school_of_company/network/api/ExpoAPI.kt index 66470e9b..ae7d5be8 100644 --- a/core/network/src/main/java/com/school_of_company/network/api/ExpoAPI.kt +++ b/core/network/src/main/java/com/school_of_company/network/api/ExpoAPI.kt @@ -1,6 +1,6 @@ package com.school_of_company.network.api -import com.school_of_company.network.dto.expo.request_response.ExpoRequestAndResponse +import com.school_of_company.network.dto.expo.all.ExpoRequestAndResponse import com.school_of_company.network.dto.expo.response.ExpoIdResponse import com.school_of_company.network.dto.expo.response.ExpoListResponse import retrofit2.http.* diff --git a/core/network/src/main/java/com/school_of_company/network/api/TrainingAPI.kt b/core/network/src/main/java/com/school_of_company/network/api/TrainingAPI.kt new file mode 100644 index 00000000..70a326f5 --- /dev/null +++ b/core/network/src/main/java/com/school_of_company/network/api/TrainingAPI.kt @@ -0,0 +1,47 @@ +package com.school_of_company.network.api + +import com.school_of_company.network.dto.training.response.TeacherTrainingProgramResponse +import com.school_of_company.network.dto.training.all.TrainingDto +import com.school_of_company.network.dto.training.response.TrainingProgramListResponse +import retrofit2.http.Body +import retrofit2.http.DELETE +import retrofit2.http.GET +import retrofit2.http.PATCH +import retrofit2.http.POST +import retrofit2.http.Path + +interface TrainingAPI { + + @POST("/training/{expo_id}") + suspend fun registerTrainingProgram( + @Path("expo_id") expoId: String, + @Body body: TrainingDto + ) + + @POST("/training/list/{expo_id}") + suspend fun registerTrainingProgramList( + @Path("expo_id") expoId: String, + @Body body: List + ) + + @PATCH("/training/{trainingPro_id}") + suspend fun modifyTrainingProgram( + @Path("trainingPro_id") trainingProId: Long, + @Body body: TrainingDto + ) + + @DELETE("/training/{trainingPro_id}") + suspend fun deleteTrainingProgram( + @Path("trainingPro_id") trainingProId: Long + ) + + @GET("/training/program/{expo_id}") + suspend fun trainingProgramList( + @Path("expo_id") expoId: String + ) : List + + @GET("/training/{trainingPro_id}") + suspend fun teacherTrainingProgramList( + @Path("trainingPro_id") trainingProId: Long + ) : List +} \ No newline at end of file diff --git a/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSource.kt b/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSource.kt index a5b580ac..656aadb7 100644 --- a/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSource.kt +++ b/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSource.kt @@ -1,6 +1,6 @@ package com.school_of_company.network.datasource.expo -import com.school_of_company.network.dto.expo.request_response.ExpoRequestAndResponse +import com.school_of_company.network.dto.expo.all.ExpoRequestAndResponse import com.school_of_company.network.dto.expo.response.ExpoIdResponse import com.school_of_company.network.dto.expo.response.ExpoListResponse import kotlinx.coroutines.flow.Flow diff --git a/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSourceImpl.kt b/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSourceImpl.kt index 255a599f..3f5589f5 100644 --- a/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSourceImpl.kt +++ b/core/network/src/main/java/com/school_of_company/network/datasource/expo/ExpoDataSourceImpl.kt @@ -1,7 +1,7 @@ package com.school_of_company.network.datasource.expo import com.school_of_company.network.api.ExpoAPI -import com.school_of_company.network.dto.expo.request_response.ExpoRequestAndResponse +import com.school_of_company.network.dto.expo.all.ExpoRequestAndResponse import com.school_of_company.network.dto.expo.response.ExpoIdResponse import com.school_of_company.network.dto.expo.response.ExpoListResponse import com.school_of_company.network.util.performApiRequest diff --git a/core/network/src/main/java/com/school_of_company/network/datasource/training/TrainingDataSource.kt b/core/network/src/main/java/com/school_of_company/network/datasource/training/TrainingDataSource.kt new file mode 100644 index 00000000..c291c0a4 --- /dev/null +++ b/core/network/src/main/java/com/school_of_company/network/datasource/training/TrainingDataSource.kt @@ -0,0 +1,15 @@ +package com.school_of_company.network.datasource.training + +import com.school_of_company.network.dto.training.response.TeacherTrainingProgramResponse +import com.school_of_company.network.dto.training.all.TrainingDto +import com.school_of_company.network.dto.training.response.TrainingProgramListResponse +import kotlinx.coroutines.flow.Flow + +interface TrainingDataSource { + fun registerTrainingProgram(expoId: String, body: TrainingDto) : Flow + fun registerTrainingProgramList(expoId: String, body: List) : Flow + fun modifyTrainingProgram(trainingProId: Long, body: TrainingDto) : Flow + fun deleteTrainingProgram(trainingProId: Long) : Flow + fun trainingProgramList(expoId: String) : Flow> + fun teacherTrainingProgramList(trainingProId: Long) : Flow> +} \ No newline at end of file diff --git a/core/network/src/main/java/com/school_of_company/network/datasource/training/TrainingDataSourceImpl.kt b/core/network/src/main/java/com/school_of_company/network/datasource/training/TrainingDataSourceImpl.kt new file mode 100644 index 00000000..d1e531bf --- /dev/null +++ b/core/network/src/main/java/com/school_of_company/network/datasource/training/TrainingDataSourceImpl.kt @@ -0,0 +1,46 @@ +package com.school_of_company.network.datasource.training + +import com.school_of_company.network.api.TrainingAPI +import com.school_of_company.network.dto.training.response.TeacherTrainingProgramResponse +import com.school_of_company.network.dto.training.all.TrainingDto +import com.school_of_company.network.dto.training.response.TrainingProgramListResponse +import com.school_of_company.network.util.performApiRequest +import kotlinx.coroutines.flow.Flow +import javax.inject.Inject + +class TrainingDataSourceImpl @Inject constructor( + private val service: TrainingAPI +) : TrainingDataSource { + override fun registerTrainingProgram( + expoId: String, + body: TrainingDto + ): Flow = + performApiRequest { service.registerTrainingProgram( + expoId = expoId, + body = body + ) } + + override fun registerTrainingProgramList( + expoId: String, + body: List + ): Flow = + performApiRequest { service.registerTrainingProgramList( + expoId = expoId, + body = body + ) } + + override fun modifyTrainingProgram(trainingProId: Long, body: TrainingDto): Flow = + performApiRequest { service.modifyTrainingProgram( + trainingProId = trainingProId, + body = body + ) } + + override fun deleteTrainingProgram(trainingProId: Long): Flow = + performApiRequest { service.deleteTrainingProgram(trainingProId = trainingProId) } + + override fun trainingProgramList(expoId: String): Flow> = + performApiRequest { service.trainingProgramList(expoId = expoId) } + + override fun teacherTrainingProgramList(trainingProId: Long): Flow> = + performApiRequest { service.teacherTrainingProgramList(trainingProId = trainingProId) } +} \ No newline at end of file diff --git a/core/network/src/main/java/com/school_of_company/network/di/NetworkModule.kt b/core/network/src/main/java/com/school_of_company/network/di/NetworkModule.kt index 9cdfed3a..4ef3d3db 100644 --- a/core/network/src/main/java/com/school_of_company/network/di/NetworkModule.kt +++ b/core/network/src/main/java/com/school_of_company/network/di/NetworkModule.kt @@ -8,6 +8,7 @@ import com.school_of_company.network.api.AuthAPI import com.school_of_company.network.api.ExpoAPI import com.school_of_company.network.api.ImageAPI import com.school_of_company.network.api.SmsAPI +import com.school_of_company.network.api.TrainingAPI import com.school_of_company.network.util.AuthInterceptor import com.school_of_company.network.util.TokenAuthenticator import com.squareup.moshi.Moshi @@ -104,4 +105,7 @@ object NetworkModule { fun provideImageAPI(retrofit: Retrofit) : ImageAPI = retrofit.create(ImageAPI::class.java) + @Provides + fun provideTrainingAPI(retrofit: Retrofit) : TrainingAPI = + retrofit.create(TrainingAPI::class.java) } \ No newline at end of file diff --git a/core/network/src/main/java/com/school_of_company/network/di/RemoteDataSourceModule.kt b/core/network/src/main/java/com/school_of_company/network/di/RemoteDataSourceModule.kt index b875ccee..c85d5afe 100644 --- a/core/network/src/main/java/com/school_of_company/network/di/RemoteDataSourceModule.kt +++ b/core/network/src/main/java/com/school_of_company/network/di/RemoteDataSourceModule.kt @@ -8,6 +8,8 @@ import com.school_of_company.network.datasource.image.ImageDataSource import com.school_of_company.network.datasource.image.ImageDataSourceImpl import com.school_of_company.network.datasource.sms.SmsDataSource import com.school_of_company.network.datasource.sms.SmsDataSourceImpl +import com.school_of_company.network.datasource.training.TrainingDataSource +import com.school_of_company.network.datasource.training.TrainingDataSourceImpl import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -36,4 +38,9 @@ abstract class RemoteDataSourceModule { abstract fun bindImageRemoteDataSource( imageDataSourceImpl: ImageDataSourceImpl ) : ImageDataSource + + @Binds + abstract fun bindTrainingRemoteDataSource( + trainingDataSourceImpl: TrainingDataSourceImpl + ) : TrainingDataSource } \ No newline at end of file diff --git a/core/network/src/main/java/com/school_of_company/network/dto/expo/request_response/ExpoRequestAndResponse.kt b/core/network/src/main/java/com/school_of_company/network/dto/expo/all/ExpoRequestAndResponse.kt similarity index 89% rename from core/network/src/main/java/com/school_of_company/network/dto/expo/request_response/ExpoRequestAndResponse.kt rename to core/network/src/main/java/com/school_of_company/network/dto/expo/all/ExpoRequestAndResponse.kt index 3dbb62c6..f51427f6 100644 --- a/core/network/src/main/java/com/school_of_company/network/dto/expo/request_response/ExpoRequestAndResponse.kt +++ b/core/network/src/main/java/com/school_of_company/network/dto/expo/all/ExpoRequestAndResponse.kt @@ -1,4 +1,4 @@ -package com.school_of_company.network.dto.expo.request_response +package com.school_of_company.network.dto.expo.all import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/core/network/src/main/java/com/school_of_company/network/dto/training/all/TrainingDto.kt b/core/network/src/main/java/com/school_of_company/network/dto/training/all/TrainingDto.kt new file mode 100644 index 00000000..d61cb3dc --- /dev/null +++ b/core/network/src/main/java/com/school_of_company/network/dto/training/all/TrainingDto.kt @@ -0,0 +1,12 @@ +package com.school_of_company.network.dto.training.all + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class TrainingDto( + @Json(name = "title") val title: String, + @Json(name = "startedAt") val startedAt: String, + @Json(name = "finishedAt") val finishedAt: String, + @Json(name = "category") val category: String, +) diff --git a/core/network/src/main/java/com/school_of_company/network/dto/training/response/TeacherTrainingProgramResponse.kt b/core/network/src/main/java/com/school_of_company/network/dto/training/response/TeacherTrainingProgramResponse.kt new file mode 100644 index 00000000..d7535e53 --- /dev/null +++ b/core/network/src/main/java/com/school_of_company/network/dto/training/response/TeacherTrainingProgramResponse.kt @@ -0,0 +1,15 @@ +package com.school_of_company.network.dto.training.response + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class TeacherTrainingProgramResponse( + @Json(name = "name") val name: String, + @Json(name = "organization") val organization: String, + @Json(name = "position") val position: String, + @Json(name = "programName") val programName: String, + @Json(name = "status") val status: Boolean, + @Json(name = "entryTime") val entryTime: String, + @Json(name = "leaveTime") val leaveTime: String +) diff --git a/core/network/src/main/java/com/school_of_company/network/dto/training/response/TrainingProgramListResponse.kt b/core/network/src/main/java/com/school_of_company/network/dto/training/response/TrainingProgramListResponse.kt new file mode 100644 index 00000000..33330677 --- /dev/null +++ b/core/network/src/main/java/com/school_of_company/network/dto/training/response/TrainingProgramListResponse.kt @@ -0,0 +1,16 @@ +package com.school_of_company.network.dto.training.response + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class TrainingProgramListResponse( + @Json(name = "essential") val essential: List, + @Json(name = "choice") val choice: List +) { + data class Training( + @Json(name = "title") val title: String, + @Json(name = "startedAt") val startedAt: String, + @Json(name = "endedAt") val endedAt: String + ) +} \ No newline at end of file diff --git a/core/network/src/main/java/com/school_of_company/network/mapper/expo/request/ExpoRequestMapper.kt b/core/network/src/main/java/com/school_of_company/network/mapper/expo/request/ExpoRequestMapper.kt index 883d2cb6..4c30170d 100644 --- a/core/network/src/main/java/com/school_of_company/network/mapper/expo/request/ExpoRequestMapper.kt +++ b/core/network/src/main/java/com/school_of_company/network/mapper/expo/request/ExpoRequestMapper.kt @@ -1,7 +1,7 @@ package com.school_of_company.network.mapper.expo.request import com.school_of_company.model.model.expo.ExpoRequestAndResponseModel -import com.school_of_company.network.dto.expo.request_response.ExpoRequestAndResponse +import com.school_of_company.network.dto.expo.all.ExpoRequestAndResponse fun ExpoRequestAndResponseModel.toDto(): ExpoRequestAndResponse = ExpoRequestAndResponse( diff --git a/core/network/src/main/java/com/school_of_company/network/mapper/expo/response/ExpoResponseMapper.kt b/core/network/src/main/java/com/school_of_company/network/mapper/expo/response/ExpoResponseMapper.kt index c6c3e53a..98508bb9 100644 --- a/core/network/src/main/java/com/school_of_company/network/mapper/expo/response/ExpoResponseMapper.kt +++ b/core/network/src/main/java/com/school_of_company/network/mapper/expo/response/ExpoResponseMapper.kt @@ -1,7 +1,7 @@ package com.school_of_company.network.mapper.expo.response import com.school_of_company.model.model.expo.ExpoRequestAndResponseModel -import com.school_of_company.network.dto.expo.request_response.ExpoRequestAndResponse +import com.school_of_company.network.dto.expo.all.ExpoRequestAndResponse fun ExpoRequestAndResponse.toModel(): ExpoRequestAndResponseModel = ExpoRequestAndResponseModel( diff --git a/core/network/src/main/java/com/school_of_company/network/mapper/training/request/TrainingDtoRequestMapper.kt b/core/network/src/main/java/com/school_of_company/network/mapper/training/request/TrainingDtoRequestMapper.kt new file mode 100644 index 00000000..3244adb5 --- /dev/null +++ b/core/network/src/main/java/com/school_of_company/network/mapper/training/request/TrainingDtoRequestMapper.kt @@ -0,0 +1,12 @@ +package com.school_of_company.network.mapper.training.request + +import com.school_of_company.model.model.training.TrainingDtoModel +import com.school_of_company.network.dto.training.all.TrainingDto + +fun TrainingDtoModel.toDto(): TrainingDto = + TrainingDto( + title = this.title, + startedAt = this.startedAt, + finishedAt = this.finishedAt, + category = this.category, + ) \ No newline at end of file diff --git a/core/network/src/main/java/com/school_of_company/network/mapper/training/response/TeacherTrainingProgramResponseMapper.kt b/core/network/src/main/java/com/school_of_company/network/mapper/training/response/TeacherTrainingProgramResponseMapper.kt new file mode 100644 index 00000000..94a54d09 --- /dev/null +++ b/core/network/src/main/java/com/school_of_company/network/mapper/training/response/TeacherTrainingProgramResponseMapper.kt @@ -0,0 +1,15 @@ +package com.school_of_company.network.mapper.training.response + +import com.school_of_company.model.entity.training.TeacherTrainingProgramResponseEntity +import com.school_of_company.network.dto.training.response.TeacherTrainingProgramResponse + +fun TeacherTrainingProgramResponse.toEntity(): TeacherTrainingProgramResponseEntity = + TeacherTrainingProgramResponseEntity( + name = this.name, + organization = this.organization, + position = this.position, + programName = this.programName, + status = this.status, + entryTime = this.entryTime, + leaveTime = this.leaveTime + ) \ No newline at end of file diff --git a/core/network/src/main/java/com/school_of_company/network/mapper/training/response/TrainingDtoResponseMapper.kt b/core/network/src/main/java/com/school_of_company/network/mapper/training/response/TrainingDtoResponseMapper.kt new file mode 100644 index 00000000..7183a40e --- /dev/null +++ b/core/network/src/main/java/com/school_of_company/network/mapper/training/response/TrainingDtoResponseMapper.kt @@ -0,0 +1,12 @@ +package com.school_of_company.network.mapper.training.response + +import com.school_of_company.model.model.training.TrainingDtoModel +import com.school_of_company.network.dto.training.all.TrainingDto + +fun TrainingDto.toModel(): TrainingDtoModel = + TrainingDtoModel( + title = this.title, + startedAt = this.startedAt, + finishedAt = this.finishedAt, + category = this.category + ) \ No newline at end of file diff --git a/core/network/src/main/java/com/school_of_company/network/mapper/training/response/TrainingProgramListResponseMapper.kt b/core/network/src/main/java/com/school_of_company/network/mapper/training/response/TrainingProgramListResponseMapper.kt new file mode 100644 index 00000000..abeb5b3d --- /dev/null +++ b/core/network/src/main/java/com/school_of_company/network/mapper/training/response/TrainingProgramListResponseMapper.kt @@ -0,0 +1,18 @@ +package com.school_of_company.network.mapper.training.response + +import com.school_of_company.model.entity.training.TrainingProgramListResponseEntity +import com.school_of_company.network.dto.training.response.TrainingProgramListResponse +import com.squareup.moshi.Json + +fun TrainingProgramListResponse.toEntity(): TrainingProgramListResponseEntity = + TrainingProgramListResponseEntity( + essential = this.essential.map { it.toEntity() }, + choice = this.choice.map { it.toEntity() } + ) + +fun TrainingProgramListResponse.Training.toEntity(): TrainingProgramListResponseEntity.Training = + TrainingProgramListResponseEntity.Training( + title = this.title, + startedAt = this.startedAt, + endedAt = this.endedAt + ) \ No newline at end of file diff --git a/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/ExpoViewModel.kt b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/ExpoViewModel.kt index 5b94c93e..211c7607 100644 --- a/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/ExpoViewModel.kt +++ b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/ExpoViewModel.kt @@ -14,15 +14,22 @@ import com.school_of_company.domain.usecase.expo.GetExpoListUseCase import com.school_of_company.domain.usecase.expo.ModifyExpoInformationUseCase import com.school_of_company.domain.usecase.expo.ModifyExpoInformationUseCase_Factory import com.school_of_company.domain.usecase.expo.RegisterExpoInformationUseCase +import com.school_of_company.domain.usecase.training.ModifyTrainingProgramUseCase +import com.school_of_company.domain.usecase.training.RegisterTrainingProgramListUseCase +import com.school_of_company.domain.usecase.training.RegisterTrainingProgramUseCase import com.school_of_company.expo.util.getMultipartFile import com.school_of_company.expo.viewmodel.uistate.DeleteExpoInformationUiState import com.school_of_company.expo.viewmodel.uistate.GetExpoInformationUiState import com.school_of_company.expo.viewmodel.uistate.GetExpoListUiState import com.school_of_company.expo.viewmodel.uistate.ImageUpLoadUiState import com.school_of_company.expo.viewmodel.uistate.ModifyExpoInformationUiState +import com.school_of_company.expo.viewmodel.uistate.ModifyTrainingProgramUiState import com.school_of_company.expo.viewmodel.uistate.RegisterExpoInformationUiState +import com.school_of_company.expo.viewmodel.uistate.RegisterTrainingProgramListUiState +import com.school_of_company.expo.viewmodel.uistate.RegisterTrainingProgramUiState import com.school_of_company.model.entity.expo.ExpoListResponseEntity import com.school_of_company.model.model.expo.ExpoRequestAndResponseModel +import com.school_of_company.model.model.training.TrainingDtoModel import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow @@ -40,6 +47,9 @@ class ExpoViewModel @Inject constructor( private val deleteExpoInformationUseCase: DeleteExpoInformationUseCase, private val getExpoListUseCase: GetExpoListUseCase, private val imageUpLoadUseCase: ImageUpLoadUseCase, + private val registerTrainingProgramUseCase: RegisterTrainingProgramUseCase, + private val registerTrainingProgramListUseCase: RegisterTrainingProgramListUseCase, + private val modifyTrainingProgramUseCase: ModifyTrainingProgramUseCase, private val savedStateHandle: SavedStateHandle ) : ViewModel() { companion object { @@ -51,6 +61,7 @@ class ExpoViewModel @Inject constructor( private const val LOCATION = "location" private const val COVER_IMAGE = "cover_image" } + private val _swipeRefreshLoading = MutableStateFlow(false) val swipeRefreshLoading = _swipeRefreshLoading.asStateFlow() @@ -72,6 +83,15 @@ class ExpoViewModel @Inject constructor( private val _imageUpLoadUiState = MutableStateFlow(ImageUpLoadUiState.Loading) internal val imageUpLoadUiState = _imageUpLoadUiState.asStateFlow() + private val _registerTrainingProgramUiState = MutableStateFlow(RegisterTrainingProgramUiState.Loading) + internal val registerTrainingProgramUiState = _registerTrainingProgramUiState.asStateFlow() + + private val _registerTrainingProgramListUiState = MutableStateFlow(RegisterTrainingProgramListUiState.Loading) + internal val registerTrainingProgramListUiState = _registerTrainingProgramListUiState.asStateFlow() + + private val _modifyTrainingProgramUiState = MutableStateFlow(ModifyTrainingProgramUiState.Loading) + internal val modifyTrainingProgramUiState = _modifyTrainingProgramUiState.asStateFlow() + internal var modify_title = savedStateHandle.getStateFlow(key = MODIFY_TITLE, initialValue = "") internal var started_date = savedStateHandle.getStateFlow(key = STARTED_DATE, initialValue = "") @@ -109,18 +129,19 @@ class ExpoViewModel @Inject constructor( } } - internal fun registerExpoInformation(body: ExpoRequestAndResponseModel) = viewModelScope.launch { - _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Loading - registerExpoInformationUseCase(body = body) - .asResult() - .collectLatest { result -> - when (result) { - Result.Loading -> _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Loading - is Result.Success -> _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Success(result.data) - is Result.Error -> _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Error(result.exception) + internal fun registerExpoInformation(body: ExpoRequestAndResponseModel) = + viewModelScope.launch { + _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Loading + registerExpoInformationUseCase(body = body) + .asResult() + .collectLatest { result -> + when (result) { + Result.Loading -> _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Loading + is Result.Success -> _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Success(result.data) + is Result.Error -> _registerExpoInformationUiState.value = RegisterExpoInformationUiState.Error(result.exception) + } } - } - } + } internal fun initRegisterExpo() { _imageUpLoadUiState.value = ImageUpLoadUiState.Loading @@ -172,7 +193,6 @@ class ExpoViewModel @Inject constructor( _deleteExpoInformationUiState.value = DeleteExpoInformationUiState.Error(remoteError) }.collect { _deleteExpoInformationUiState.value = DeleteExpoInformationUiState.Success - } } .onFailure { error -> @@ -226,6 +246,69 @@ class ExpoViewModel @Inject constructor( } } + internal fun registerTrainingProgram( + expoId: String, + body: TrainingDtoModel + ) = viewModelScope.launch { + _registerTrainingProgramUiState.value = RegisterTrainingProgramUiState.Loading + registerTrainingProgramUseCase( + expoId = expoId, + body = body + ) + .onSuccess { + it.catch { remoteError -> + _registerTrainingProgramUiState.value = RegisterTrainingProgramUiState.Error(remoteError) + }.collect { + _registerTrainingProgramUiState.value = RegisterTrainingProgramUiState.Success + } + } + .onFailure { error -> + _registerTrainingProgramUiState.value = RegisterTrainingProgramUiState.Error(error) + } + } + + internal fun registerTrainingProgramList( + expoId: String, + body: List + ) = viewModelScope.launch { + _registerTrainingProgramListUiState.value = RegisterTrainingProgramListUiState.Loading + registerTrainingProgramListUseCase( + expoId = expoId, + body = body + ) + .onSuccess { + it.catch { remoteError -> + _registerTrainingProgramListUiState.value = RegisterTrainingProgramListUiState.Error(remoteError) + }.collect { + _registerTrainingProgramListUiState.value = RegisterTrainingProgramListUiState.Success + } + } + .onFailure { error -> + _registerTrainingProgramListUiState.value = RegisterTrainingProgramListUiState.Error(error) + } + } + + internal fun modifyTrainingProgram( + trainingProId: Long, + body: TrainingDtoModel + ) = viewModelScope.launch { + _modifyTrainingProgramUiState.value = ModifyTrainingProgramUiState.Loading + modifyTrainingProgramUseCase( + trainingProId = trainingProId, + body = body + ) + .onSuccess { + it.catch { remoteError -> + _modifyTrainingProgramUiState.value = ModifyTrainingProgramUiState.Error(remoteError) + }.collect { + _modifyTrainingProgramUiState.value = ModifyTrainingProgramUiState.Success + } + } + .onFailure { error -> + _modifyTrainingProgramUiState.value = ModifyTrainingProgramUiState.Error(error) + } + } + internal fun onModifyTitleChange(value: String) { savedStateHandle[MODIFY_TITLE] = value } diff --git a/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/ModifyTrainingProgramUiState.kt b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/ModifyTrainingProgramUiState.kt new file mode 100644 index 00000000..8234ac31 --- /dev/null +++ b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/ModifyTrainingProgramUiState.kt @@ -0,0 +1,7 @@ +package com.school_of_company.expo.viewmodel.uistate + +sealed interface ModifyTrainingProgramUiState { + object Loading : ModifyTrainingProgramUiState + object Success : ModifyTrainingProgramUiState + data class Error(val exception: Throwable) : ModifyTrainingProgramUiState +} \ No newline at end of file diff --git a/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/RegisterTrainingProgramListUiState.kt b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/RegisterTrainingProgramListUiState.kt new file mode 100644 index 00000000..c5ae3465 --- /dev/null +++ b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/RegisterTrainingProgramListUiState.kt @@ -0,0 +1,7 @@ +package com.school_of_company.expo.viewmodel.uistate + +sealed interface RegisterTrainingProgramListUiState { + object Loading : RegisterTrainingProgramListUiState + object Success : RegisterTrainingProgramListUiState + data class Error(val exception: Throwable) : RegisterTrainingProgramListUiState +} \ No newline at end of file diff --git a/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/RegisterTrainingProgramUiState.kt b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/RegisterTrainingProgramUiState.kt new file mode 100644 index 00000000..8d74d749 --- /dev/null +++ b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/uistate/RegisterTrainingProgramUiState.kt @@ -0,0 +1,7 @@ +package com.school_of_company.expo.viewmodel.uistate + +sealed interface RegisterTrainingProgramUiState { + object Loading : RegisterTrainingProgramUiState + object Success : RegisterTrainingProgramUiState + data class Error(val exception: Throwable) : RegisterTrainingProgramUiState +} \ No newline at end of file