Skip to content

Commit

Permalink
✨ feat: fetch classroom data 추가 #13
Browse files Browse the repository at this point in the history
  • Loading branch information
easyhz committed Aug 15, 2024
1 parent fdc5d4b commit 8fb125e
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package com.afs.tutrd.data.constant.firestore

object Collection {
const val CLASSROOM = "classroom"
const val USER = "user"
}
18 changes: 0 additions & 18 deletions app/src/main/java/com/afs/tutrd/data/model/classroom/Classroom.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.afs.tutrd.data.model.classroom

import com.google.firebase.firestore.PropertyName

// TODO 이름 바꾸기 (사유: 겹침)
data class ClassroomData(
@PropertyName("classroomName")
val classroomName: String = "",
@PropertyName("classroomProfileColor")
val classroomProfileColor: String = "",
@PropertyName("classroomProfileImage")
val classroomProfileImage: String = "",
@PropertyName("fixedCount")
val fixedCount: Int = 0,
@PropertyName("payMethod")
val payMethod: String = "",
@PropertyName("repetition")
val repetition: RepetitionData = RepetitionData(),
@PropertyName("timetable")
val timetable: List<TimetableData> = emptyList(),
@PropertyName("tuitionFee")
val tuitionFee: Int = 0,
@PropertyName("tuitionFeeUnit")
val tuitionFeeUnit: String = "",
@PropertyName("tutees")
val tutees: List<String> = emptyList(),
@PropertyName("tutorId")
val tutorId: String = "",
@PropertyName("tutoring")
val tutoring: List<TutoringData> = emptyList(),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.afs.tutrd.data.model.classroom

import com.google.firebase.firestore.PropertyName

data class HomeworkData(
@PropertyName("content")
val content: String = "",
@get:PropertyName("isDone")
@set:PropertyName("isDone")
var isDone: Boolean = false
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.afs.tutrd.data.model.classroom

import com.google.firebase.firestore.PropertyName

data class HomeworkImageData(
@PropertyName("description")
val description: String = "",
@PropertyName("image")
val image: String = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.afs.tutrd.data.model.classroom

import com.google.firebase.firestore.PropertyName

data class ProgressImagesData(
@PropertyName("description")
val description: String = "",
@PropertyName("image")
val image: String = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.afs.tutrd.data.model.classroom

import com.google.firebase.firestore.PropertyName

data class RepetitionData(
@PropertyName("date")
val date: Int = 0,
@PropertyName("day")
val day: String = "",
@PropertyName("interval")
val interval: Int = 0,
@PropertyName("month")
val month: Int = 0,
@PropertyName("type")
val type: Int = 0,
@PropertyName("week")
val week: Int = 0,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.afs.tutrd.data.model.classroom

import com.google.firebase.Timestamp
import com.google.firebase.firestore.PropertyName

data class TimetableData(
@PropertyName("classHours")
val classHours: Int = 0,
@PropertyName("endDate")
val endDate: Timestamp = Timestamp.now(),
@PropertyName("repetition")
val repetition: RepetitionData = RepetitionData(),
@PropertyName("startDate")
val startDate: Timestamp = Timestamp.now()

)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.afs.tutrd.data.model.classroom

import com.google.firebase.Timestamp
import com.google.firebase.firestore.PropertyName

data class TutoringData(
@PropertyName("attendance")
val attendance: List<String> = emptyList(),
@PropertyName("dateTime")
val dateTime: Timestamp = Timestamp.now(),
@PropertyName("elapsedTime")
val elapsedTime: Int = 0,
@PropertyName("homework")
val homework: List<HomeworkData> = emptyList(),
@PropertyName("homeworkImages")
val homeworkImages: List<HomeworkImageData> = emptyList(),
@get:PropertyName("isComplete")
@set:PropertyName("isComplete")
var isComplete: Boolean = false,
@PropertyName("progress")
val progress: List<String> = emptyList(),
@PropertyName("progressImages")
val progressImages: List<ProgressImagesData> = emptyList(),
@PropertyName("status")
val status: Int = 0,
@PropertyName("tutoringId")
val tutoringId: String = "",
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.afs.tutrd.data.repository.classroom

import com.afs.tutrd.data.constant.firestore.Collection
import com.afs.tutrd.data.constant.firestore.Field
import com.afs.tutrd.data.model.classroom.Classroom
import com.afs.tutrd.data.model.classroom.ClassroomData
import com.afs.tutrd.di.qualifier.IoDispatcher
import com.afs.tutrd.domain.repository.classroom.ClassroomRepository
import com.google.firebase.firestore.FirebaseFirestore
Expand All @@ -15,12 +15,12 @@ class ClassroomRepositoryImpl @Inject constructor(
private val firestore: FirebaseFirestore,
@IoDispatcher private val dispatcher: CoroutineDispatcher
) : ClassroomRepository {
override suspend fun fetchClassroomList(tutorId: String): Result<List<Classroom>> =
override suspend fun fetchClassroomList(tutorId: String): Result<List<ClassroomData>> =
withContext(dispatcher) {
runCatching {
firestore.collection(Collection.CLASSROOM)
.whereEqualTo(Field.TUTOR_ID, tutorId)
.get().await().toObjects(Classroom::class.java)
.get().await().toObjects(ClassroomData::class.java)
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/afs/tutrd/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import dagger.hilt.components.SingletonComponent
interface RepositoryModule {

@Binds
fun bindHealthCheckRepository(
fun bindClassroomRepository(
classroomRepositoryImpl: ClassroomRepositoryImpl
): ClassroomRepository
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.afs.tutrd.domain.repository.classroom

import com.afs.tutrd.data.model.classroom.Classroom
import com.afs.tutrd.data.model.classroom.ClassroomData

interface ClassroomRepository {
suspend fun fetchClassroomList(tutorId: String): Result<List<Classroom>>
suspend fun fetchClassroomList(tutorId: String): Result<List<ClassroomData>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import javax.inject.Inject

@HiltViewModel
class ClassroomViewModel @Inject constructor(
private val classroomRepository: ClassroomRepository
private val classroomRepository: ClassroomRepository,
):BaseViewModel<ClassroomState, ClassroomIntent, ClassroomSideEffect>(
initialState = ClassroomState.init()
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.afs.tutrd.presentation.classroom.contract

import com.afs.tutrd.common.base.UiState
import com.afs.tutrd.data.model.classroom.Classroom
import com.afs.tutrd.data.model.classroom.ClassroomData

data class ClassroomState(
val classroomList: List<Classroom>
val classroomList: List<ClassroomData>
): UiState() {
companion object {
fun init() = ClassroomState(
Expand Down

0 comments on commit 8fb125e

Please sign in to comment.