Skip to content
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

๐Ÿ”€ :: (#54) write student info domain logic #55

Merged
merged 6 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/src/main/java/com/msg/dotori/module/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package com.msg.dotori.module

import com.msg.data.repository.AuthRepositoryImpl
import com.msg.data.repository.MusicRepositoryImpl
import com.msg.data.repository.SelfStudyRepositoryImpl
import com.msg.data.repository.StudentInfoRepositoryImpl
import com.msg.domain.repository.AuthRepository
import com.msg.domain.repository.MusicRepository
import com.msg.domain.repository.SelfStudyRepository
import com.msg.domain.repository.StudentInfoRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -17,4 +21,10 @@ interface RepositoryModule {

@Binds
fun bindsMusicRepository(musicRepositoryImpl: MusicRepositoryImpl): MusicRepository

@Binds
fun bindsSelfStudyRepository(selfStudyRepositoryImpl: SelfStudyRepositoryImpl): SelfStudyRepository

@Binds
fun bindsStudentInfoRepository(studentInfoRepositoryImpl: StudentInfoRepositoryImpl): StudentInfoRepository
}
12 changes: 5 additions & 7 deletions data/src/main/java/com/msg/data/remote/dto/auth/Role.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ enum class Role {
ROLE_DEVELOPER
}

fun Role.asRoleModel(): RoleModel {
return when (this) {
Role.ROLE_ADMIN -> RoleModel.ROLE_ADMIN
Role.ROLE_MEMBER -> RoleModel.ROLE_MEMBER
Role.ROLE_COUNCILLOR -> RoleModel.ROLE_COUNCILLOR
Role.ROLE_DEVELOPER -> RoleModel.ROLE_DEVELOPER
}
fun Role.asRoleModel() = when (this) {
Role.ROLE_ADMIN -> RoleModel.ROLE_ADMIN
Role.ROLE_MEMBER -> RoleModel.ROLE_MEMBER
Role.ROLE_COUNCILLOR -> RoleModel.ROLE_COUNCILLOR
Role.ROLE_DEVELOPER -> RoleModel.ROLE_DEVELOPER
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.msg.data.remote.dto.student_info

import com.msg.domain.model.student_info.SearchStudentInfoResponseModel

data class SearchStudentInfoResponse(
val email: String,
val memberName: String,
Expand All @@ -8,3 +10,12 @@ data class SearchStudentInfoResponse(
val role: String,
val selfStudyCheck: Boolean
)

fun SearchStudentInfoResponse.asSearchStudentInfoResponseModel() = SearchStudentInfoResponseModel(
email = email,
memberName = memberName,
stuName = stuName,
gender = gender,
role = role,
selfStudyCheck = selfStudyCheck
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package com.msg.data.remote.dto.student_info

import com.msg.domain.model.student_info.SelfStudyStatusModel

enum class SelfStudyStatus {
CAN,
APPLIED,
CANT,
IMPOSSIBLE
}

fun SelfStudyStatus.asSelfStudyStatusModel() = when (this) {
SelfStudyStatus.CAN -> SelfStudyStatusModel.CAN
SelfStudyStatus.APPLIED -> SelfStudyStatusModel.APPLIED
SelfStudyStatus.CANT -> SelfStudyStatusModel.CANT
SelfStudyStatus.IMPOSSIBLE -> SelfStudyStatusModel.IMPOSSIBLE
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package com.msg.data.remote.dto.student_info

import com.msg.domain.model.student_info.StudentInfoRequestModel

data class StudentInfoRequest(
val userId: Long,
val memberName: String,
val stuNum: String,
val gender: String,
val role: String
)

fun StudentInfoRequestModel.asStudentInfoRequest() = StudentInfoRequest(
userId = userId,
memberName = memberName,
stuNum = stuNum,
gender = gender,
role = role
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.msg.data.remote.dto.student_info

import com.msg.domain.model.student_info.StudentInfoResponseModel

data class StudentInfoResponse(
val id: Long,
val gender: String,
Expand All @@ -8,3 +10,12 @@ data class StudentInfoResponse(
val role: String,
val selfStudyStatus: SelfStudyStatus
)

fun StudentInfoResponse.asStudentInfoResponseModel() = StudentInfoResponseModel(
id = id,
gender = gender,
memberName = memberName,
stuNum = stuNum,
role = role,
selfStudyStatus = selfStudyStatus.asSelfStudyStatusModel()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.msg.data.repository

import com.msg.data.remote.datasource.self_study.SelfStudyDataSource
import com.msg.domain.repository.SelfStudyRepository
import javax.inject.Inject

class SelfStudyRepositoryImpl @Inject constructor(
private val selfStudyDataSource: SelfStudyDataSource
): SelfStudyRepository {
override suspend fun banSelfStudy(role: String, userId: Long) =
selfStudyDataSource.banSelfStudy(
role = role,
userId = userId
)

override suspend fun banCancelSelfStudy(role: String, userId: Long) =
selfStudyDataSource.banCancelSelfStudy(
role = role,
userId = userId
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.msg.data.repository

import com.msg.data.remote.datasource.student_info.StudentInfoDataSource
import com.msg.data.remote.dto.student_info.asSearchStudentInfoResponseModel
import com.msg.data.remote.dto.student_info.asStudentInfoRequest
import com.msg.data.remote.dto.student_info.asStudentInfoResponseModel
import com.msg.domain.model.student_info.SearchStudentInfoResponseModel
import com.msg.domain.model.student_info.StudentInfoRequestModel
import com.msg.domain.model.student_info.StudentInfoResponseModel
import com.msg.domain.repository.StudentInfoRepository
import javax.inject.Inject

class StudentInfoRepositoryImpl @Inject constructor(
private val studentInfoDataSource: StudentInfoDataSource
): StudentInfoRepository {
override suspend fun getAllStudentInfo(): List<StudentInfoResponseModel> =
studentInfoDataSource.getAllStudentInfo().map { it.asStudentInfoResponseModel() }

override suspend fun getSearchStudentInfo(
name: String?,
gender: String?,
classNum: String?,
grade: String?,
role: String?,
selfStudy: Boolean?
): List<SearchStudentInfoResponseModel> = studentInfoDataSource.getSearchStudentInfo(
name = name,
gender = gender,
classNum = classNum,
grade = grade,
role = role,
selfStudy = selfStudy
).map { it.asSearchStudentInfoResponseModel() }

override suspend fun modifyStudentInfo(body: StudentInfoRequestModel) =
studentInfoDataSource.modifyStudentInfo(body.asStudentInfoRequest())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.msg.domain.model.student_info

data class SearchStudentInfoResponseModel(
val email: String,
val memberName: String,
val stuName: String,
val gender: String,
val role: String,
val selfStudyCheck: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.msg.domain.model.student_info

enum class SelfStudyStatusModel {
CAN,
APPLIED,
CANT,
IMPOSSIBLE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.msg.domain.model.student_info

data class StudentInfoRequestModel(
val userId: Long,
val memberName: String,
val stuNum: String,
val gender: String,
val role: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.msg.domain.model.student_info

data class StudentInfoResponseModel(
val id: Long,
val gender: String,
val memberName: String,
val stuNum: String,
val role: String,
val selfStudyStatus: SelfStudyStatusModel
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.msg.domain.repository

interface SelfStudyRepository {
suspend fun banSelfStudy(
role: String,
userId: Long
)

suspend fun banCancelSelfStudy(
role: String,
userId: Long
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.msg.domain.repository

import com.msg.domain.model.student_info.SearchStudentInfoResponseModel
import com.msg.domain.model.student_info.StudentInfoRequestModel
import com.msg.domain.model.student_info.StudentInfoResponseModel

interface StudentInfoRepository {
suspend fun getAllStudentInfo(): List<StudentInfoResponseModel>

suspend fun getSearchStudentInfo(
name: String?,
gender: String?,
classNum: String?,
grade: String?,
role: String?,
selfStudy: Boolean?,
): List<SearchStudentInfoResponseModel>

suspend fun modifyStudentInfo(body: StudentInfoRequestModel)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.msg.domain.usecase.self_study

import com.msg.domain.repository.SelfStudyRepository
import javax.inject.Inject

class BanCancelSelfStudyUseCase @Inject constructor(
private val selfStudyRepository: SelfStudyRepository
) {
suspend operator fun invoke(
role: String,
userId: Long
) = kotlin.runCatching {
selfStudyRepository.banCancelSelfStudy(
role = role,
userId = userId
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.msg.domain.usecase.self_study

import com.msg.domain.repository.SelfStudyRepository
import javax.inject.Inject

class BanSelfStudyUseCase @Inject constructor(
private val selfStudyRepository: SelfStudyRepository
) {
suspend operator fun invoke(
role: String,
userId: Long
) = kotlin.runCatching {
selfStudyRepository.banSelfStudy(
role = role,
userId = userId
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.msg.domain.usecase.student_info

import com.msg.domain.repository.StudentInfoRepository
import javax.inject.Inject

class GetAllStudentInfoUseCase @Inject constructor(
private val studentInfoRepository: StudentInfoRepository
) {
suspend operator fun invoke() = kotlin.runCatching { studentInfoRepository.getAllStudentInfo() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.msg.domain.usecase.student_info

import com.msg.domain.repository.StudentInfoRepository
import javax.inject.Inject

class GetSearchStudentInfoUseCase @Inject constructor(
private val studentInfoRepository: StudentInfoRepository
) {
suspend operator fun invoke(
name: String?,
gender: String?,
classNum: String?,
grade: String?,
role: String?,
selfStudy: Boolean?,
) = kotlin.runCatching { studentInfoRepository.getSearchStudentInfo(
name = name,
gender = gender,
classNum = classNum,
grade = grade,
role = role,
selfStudy = selfStudy
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.msg.domain.usecase.student_info

import com.msg.domain.model.student_info.StudentInfoRequestModel
import com.msg.domain.repository.StudentInfoRepository
import javax.inject.Inject

class ModifyStudentInfoUseCase @Inject constructor(
private val studentInfoRepository: StudentInfoRepository
) {
suspend operator fun invoke(body: StudentInfoRequestModel) = kotlin.runCatching { studentInfoRepository.modifyStudentInfo(body) }
}
Loading