diff --git a/reminderData/src/main/kotlin/com/intelligentbackpack/reminderdata/datasource/ReminderRemoteDataSource.kt b/reminderData/src/main/kotlin/com/intelligentbackpack/reminderdata/datasource/ReminderRemoteDataSource.kt index 0b485e4a..28016dae 100644 --- a/reminderData/src/main/kotlin/com/intelligentbackpack/reminderdata/datasource/ReminderRemoteDataSource.kt +++ b/reminderData/src/main/kotlin/com/intelligentbackpack/reminderdata/datasource/ReminderRemoteDataSource.kt @@ -3,14 +3,58 @@ package com.intelligentbackpack.reminderdata.datasource import calendar.communication.Lesson import calendar.communication.Subject +/** + * Remote data source for the reminder module. + */ interface ReminderRemoteDataSource { + /** + * Downloads the current year. + * + * @return the current year. + */ suspend fun downloadYear(): String + + /** + * Downloads the subjects. + * + * @return the subjects. + */ suspend fun downloadSubjects(): List + /** + * Downloads the lessons for the student in the given year. + * + * @param email the email of the student. + * @param year the year. + * @return the lessons. + */ suspend fun downloadLessonsForStudent(email: String, year: String): List + /** + * Downloads the lessons for the professor in the given year. + * + * @param email the email of the professor. + * @param year the year. + * @return the lessons. + */ suspend fun downloadLessonsForProfessor(email: String, year: String): List + /** + * Downloads the books for the given lesson. + * + * @param lesson the lesson. + * @return the books. + */ suspend fun downloadBooksForLesson(lesson: Lesson): List + + /** + * Creates a new reminder for the given lesson. + * + * @param email the email of the student. + * @param lesson the lesson. + * @param isbn the isbn of the book. + * @return the id of the reminder. + */ + suspend fun createNewReminderForLesson(email: String, lesson: Lesson, isbn: String): String } diff --git a/reminderData/src/main/kotlin/com/intelligentbackpack/reminderdata/datasource/ReminderRemoteDataSourceImpl.kt b/reminderData/src/main/kotlin/com/intelligentbackpack/reminderdata/datasource/ReminderRemoteDataSourceImpl.kt index fc989999..d109ac00 100644 --- a/reminderData/src/main/kotlin/com/intelligentbackpack/reminderdata/datasource/ReminderRemoteDataSourceImpl.kt +++ b/reminderData/src/main/kotlin/com/intelligentbackpack/reminderdata/datasource/ReminderRemoteDataSourceImpl.kt @@ -50,7 +50,39 @@ class ReminderRemoteDataSourceImpl( override suspend fun downloadBooksForLesson(lesson: Lesson): List { val response = calendarApi.getBooksForLesson(lesson).execute() if (response.isSuccessful) { - return response.body()?.isbNsList ?: emptyList() + return response.body()?.message2List ?: emptyList() + } else { + throw DownloadException(ErrorHandler.getError(response)) + } + } + + override suspend fun createNewReminderForLesson(email: String, lesson: Lesson, isbn: String): String { + val jsonParam = mapOf( + ("Email" to email), + ("Nome_lezione" to lesson.nomeLezione), + ("Materia" to lesson.materia), + ("Giorno" to lesson.giorno), + ("Ora_inizio" to lesson.oraInizio), + ("Ora_fine" to lesson.oraFine), + ("Professore" to lesson.professore), + ("Data_Inizio" to lesson.dataInizio), + ("Data_Fine" to lesson.dataFine), + ("ID_Calendario" to lesson.idCalendario), + ) + val lessonjson = JSONObject(jsonParam) + val isbnjson = JSONArray(listOf(isbn)) + val jsonParamReminder = mapOf( + ("lesson" to lessonjson), + ("ISBNs" to isbnjson), + ("email_executor" to email), + ) + val request = RequestBody.create( + okhttp3.MediaType.parse("application/json; charset=utf-8"), + (JSONObject(jsonParamReminder)).toString(), + ) + val response = calendarApi.createReminderForLesson(request).execute() + if (response.isSuccessful) { + return response.body()?.message ?: "" } else { throw DownloadException(ErrorHandler.getError(response)) }