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

Commit

Permalink
feat(reminder): add method createNewReminderForLesson in ReminderRemo…
Browse files Browse the repository at this point in the history
…teDataSource and its implementation in ReminderRemoteDataSourceImpl
  • Loading branch information
AndreaBrighi committed Jun 19, 2023
1 parent 656afa0 commit 52fcb23
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Subject>

/**
* 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<Lesson>

/**
* 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<Lesson>

/**
* Downloads the books for the given lesson.
*
* @param lesson the lesson.
* @return the books.
*/
suspend fun downloadBooksForLesson(lesson: Lesson): List<String>

/**
* 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,39 @@ class ReminderRemoteDataSourceImpl(
override suspend fun downloadBooksForLesson(lesson: Lesson): List<String> {
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))
}
Expand Down

0 comments on commit 52fcb23

Please sign in to comment.