Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
fix(reminder): in ReminderDomainRepositoryImpl implement addBookForLe…
Browse files Browse the repository at this point in the history
…sson
  • Loading branch information
AndreaBrighi committed Jun 20, 2023
1 parent 722c80e commit f228921
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.intelligentbackpack.reminderdata.datasource

import com.intelligentbackpack.accessdomain.entities.User
import com.intelligentbackpack.reminderdata.adapter.LessonAdapter.fromDBToRemote
import com.intelligentbackpack.reminderdata.adapter.LessonAdapter.fromDomainToDB
import com.intelligentbackpack.reminderdata.adapter.LessonAdapter.fromRemoteToDB
import com.intelligentbackpack.reminderdata.adapter.ReminderAdapter.fromDBToDomain
import com.intelligentbackpack.reminderdata.adapter.ReminderAdapter.fromDomainToDB
import com.intelligentbackpack.reminderdata.adapter.ReminderAdapter.fromRemoteToDB
import com.intelligentbackpack.reminderdata.adapter.SubjectAdapter.fromRemoteToDB
import com.intelligentbackpack.reminderdomain.entitites.Reminder
Expand Down Expand Up @@ -65,9 +68,28 @@ class ReminderDomainRepositoryImpl(
)
}

override suspend fun addBookForLesson(reminderForLesson: ReminderForLesson, user: User) {
TODO("Not yet implemented")
}
override suspend fun addBookForLesson(reminderForLesson: ReminderForLesson, user: User) =
withContext(Dispatchers.IO) {
val subjects = localDataSource.getSubjects()
val abstractLessonDB = reminderForLesson.lesson.fromDomainToDB(subjects)
val lesson = localDataSource.getLesson(
abstractLessonDB.day,
abstractLessonDB.startTime,
abstractLessonDB.endTime,
abstractLessonDB.fromDate,
abstractLessonDB.toDate,
)
if (lesson != null) {
localDataSource.saveReminder(
reminderForLesson.fromDomainToDB(lesson),
)
remoteDataSource.createNewReminderForLesson(
user.email,
lesson.fromDBToRemote(),
reminderForLesson.isbn,
)
}
}

override suspend fun removeBookForLesson(reminderForLesson: ReminderForLesson, user: User) {
TODO("Not yet implemented")
Expand Down

0 comments on commit f228921

Please sign in to comment.