From 791bfc3b02916e4ccc1b52425f4a0dd91ea385eb Mon Sep 17 00:00:00 2001 From: Andrea Brighi Date: Tue, 11 Jul 2023 13:34:04 +0200 Subject: [PATCH] feat(reminder): in ReminderRemoteDataSource add method changeReminderForLesson implemented in ReminderRemoteDataSourceImpl --- .../datasource/ReminderRemoteDataSource.kt | 18 +++++++++++++ .../ReminderRemoteDataSourceImpl.kt | 27 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) 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 96dc46a2..cb8c2fd6 100644 --- a/reminderData/src/main/kotlin/com/intelligentbackpack/reminderdata/datasource/ReminderRemoteDataSource.kt +++ b/reminderData/src/main/kotlin/com/intelligentbackpack/reminderdata/datasource/ReminderRemoteDataSource.kt @@ -2,6 +2,7 @@ package com.intelligentbackpack.reminderdata.datasource import calendar.communication.Lesson import calendar.communication.Subject +import java.time.LocalDate /** * Remote data source for the reminder module. @@ -70,4 +71,21 @@ interface ReminderRemoteDataSource { lesson: Lesson, isbn: String, ) + + /** + * Changes the reminder for the given lesson. + * + * @param email the email of the student. + * @param lesson the lesson. + * @param isbn the isbn of the book. + * @param fromDate the new from date. + * @param toDate the new to date. + */ + suspend fun changeReminderForLesson( + email: String, + lesson: Lesson, + isbn: String, + fromDate: LocalDate, + toDate: LocalDate, + ) } 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 eebd94ef..da472962 100644 --- a/reminderData/src/main/kotlin/com/intelligentbackpack/reminderdata/datasource/ReminderRemoteDataSourceImpl.kt +++ b/reminderData/src/main/kotlin/com/intelligentbackpack/reminderdata/datasource/ReminderRemoteDataSourceImpl.kt @@ -8,6 +8,7 @@ import com.intelligentbackpack.schooldata.api.CalendarApi import com.intelligentbackpack.schooldata.datasource.SchoolRemoteDataSourceImpl import okhttp3.RequestBody import org.json.JSONObject +import java.time.LocalDate /** * Implementation of Remote data source for the reminder module. @@ -42,7 +43,7 @@ class ReminderRemoteDataSourceImpl( private fun createJsonForReminder(email: String, lesson: Lesson, isbn: String): RequestBody { val json = JSONObject() - json.put("email", email) + json.put("email_executor", email) json.put("lesson", schoolRemoteDataSource.createJsonForLesson(lesson)) json.put("isbn", isbn) return RequestBody.create( @@ -66,4 +67,28 @@ class ReminderRemoteDataSourceImpl( throw DownloadException(ErrorHandler.getError(response)) } } + + override suspend fun changeReminderForLesson( + email: String, + lesson: Lesson, + isbn: String, + fromDate: LocalDate, + toDate: LocalDate, + ) { + val json = JSONObject() + json.put("email_executor", email) + json.put("lesson", schoolRemoteDataSource.createJsonForLesson(lesson)) + json.put("isbn", isbn) + json.put("nuovaInizioData", fromDate.toString()) + json.put("nuovaFineData", toDate.toString()) + val response = calendarApi.modifyReminderForLesson( + RequestBody.create( + okhttp3.MediaType.parse("application/json; charset=utf-8"), + json.toString(), + ), + ).execute() + if (!response.isSuccessful) { + throw DownloadException(ErrorHandler.getError(response)) + } + } }