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

Commit

Permalink
feat(reminder): in ReminderRemoteDataSource add method changeReminder…
Browse files Browse the repository at this point in the history
…ForLesson implemented in ReminderRemoteDataSourceImpl
  • Loading branch information
AndreaBrighi committed Jul 11, 2023
1 parent b1be506 commit 791bfc3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand All @@ -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))
}
}
}

0 comments on commit 791bfc3

Please sign in to comment.