Skip to content

Commit

Permalink
Merge pull request #217 from School-of-Company/feature/216-network-se…
Browse files Browse the repository at this point in the history
…tting-training-part

🔀 :: (#216) - Training 파트 부분의 네트워크 세팅을 합니다.
  • Loading branch information
audgns10 authored Nov 25, 2024
2 parents 26a9611 + 6b6efb3 commit 195b781
Show file tree
Hide file tree
Showing 35 changed files with 548 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,4 +38,9 @@ abstract class RepositoryModule {
abstract fun bindImageRepository(
imageRepositoryImpl: ImageRepositoryImpl
) : ImageRepository

@Binds
abstract fun bindTrainingRepository(
trainingRepositoryImpl: TrainingRepositoryImpl
) : TrainingRepository
}
Original file line number Diff line number Diff line change
@@ -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<Unit>
fun registerTrainingProgramList(expoId: String, body: List<TrainingDtoModel>) : Flow<Unit>
fun modifyTrainingProgram(trainingProId: Long, body: TrainingDtoModel) : Flow<Unit>
fun deleteTrainingProgram(trainingProId: Long) : Flow<Unit>
fun trainingProgramList(expoId: String) : Flow<List<TrainingProgramListResponseEntity>>
fun teacherTrainingProgramList(trainingProId: Long) : Flow<List<TeacherTrainingProgramResponseEntity>>
}
Original file line number Diff line number Diff line change
@@ -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<Unit> {
return dataSource.registerTrainingProgram(
expoId = expoId,
body = body.toDto()
)
}

override fun registerTrainingProgramList(
expoId: String,
body: List<TrainingDtoModel>
): Flow<Unit> {
return dataSource.registerTrainingProgramList(
expoId = expoId,
body = body.map { it.toDto() }
)
}

override fun modifyTrainingProgram(
trainingProId: Long,
body: TrainingDtoModel
): Flow<Unit> {
return dataSource.modifyTrainingProgram(
trainingProId = trainingProId,
body = body.toDto()
)
}

override fun deleteTrainingProgram(trainingProId: Long): Flow<Unit> {
return dataSource.deleteTrainingProgram(trainingProId = trainingProId)
}

override fun trainingProgramList(expoId: String): Flow<List<TrainingProgramListResponseEntity>> {
return dataSource.trainingProgramList(expoId = expoId).transform { list ->
emit(list.map { it.toEntity() })
}
}

override fun teacherTrainingProgramList(trainingProId: Long): Flow<List<TeacherTrainingProgramResponseEntity>> {
return dataSource.teacherTrainingProgramList(trainingProId = trainingProId).transform { list ->
emit(list.map { it.toEntity() })
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
)
}
}
Original file line number Diff line number Diff line change
@@ -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<TrainingDtoModel>
) = runCatching {
repository.registerTrainingProgramList(
expoId = expoId,
body = body
)
}
}
Original file line number Diff line number Diff line change
@@ -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
)
}
}
Original file line number Diff line number Diff line change
@@ -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<List<TeacherTrainingProgramResponseEntity>> =
repository.teacherTrainingProgramList(trainingProId = trainingProId)
}
Original file line number Diff line number Diff line change
@@ -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<List<TrainingProgramListResponseEntity>> =
repository.trainingProgramList(expoId = expoId)
}
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.school_of_company.model.entity.training

data class TrainingProgramListResponseEntity(
val essential: List<Training>,
val choice: List<Training>
) {
data class Training(
val title: String,
val startedAt: String,
val endedAt: String,
)
}
Empty file.
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down
Original file line number Diff line number Diff line change
@@ -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<TrainingDto>
)

@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<TrainingProgramListResponse>

@GET("/training/{trainingPro_id}")
suspend fun teacherTrainingProgramList(
@Path("trainingPro_id") trainingProId: Long
) : List<TeacherTrainingProgramResponse>
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Unit>
fun registerTrainingProgramList(expoId: String, body: List<TrainingDto>) : Flow<Unit>
fun modifyTrainingProgram(trainingProId: Long, body: TrainingDto) : Flow<Unit>
fun deleteTrainingProgram(trainingProId: Long) : Flow<Unit>
fun trainingProgramList(expoId: String) : Flow<List<TrainingProgramListResponse>>
fun teacherTrainingProgramList(trainingProId: Long) : Flow<List<TeacherTrainingProgramResponse>>
}
Original file line number Diff line number Diff line change
@@ -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<Unit> =
performApiRequest { service.registerTrainingProgram(
expoId = expoId,
body = body
) }

override fun registerTrainingProgramList(
expoId: String,
body: List<TrainingDto>
): Flow<Unit> =
performApiRequest { service.registerTrainingProgramList(
expoId = expoId,
body = body
) }

override fun modifyTrainingProgram(trainingProId: Long, body: TrainingDto): Flow<Unit> =
performApiRequest { service.modifyTrainingProgram(
trainingProId = trainingProId,
body = body
) }

override fun deleteTrainingProgram(trainingProId: Long): Flow<Unit> =
performApiRequest { service.deleteTrainingProgram(trainingProId = trainingProId) }

override fun trainingProgramList(expoId: String): Flow<List<TrainingProgramListResponse>> =
performApiRequest { service.trainingProgramList(expoId = expoId) }

override fun teacherTrainingProgramList(trainingProId: Long): Flow<List<TeacherTrainingProgramResponse>> =
performApiRequest { service.teacherTrainingProgramList(trainingProId = trainingProId) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Loading

0 comments on commit 195b781

Please sign in to comment.