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

Commit

Permalink
feat(desktop): update use case and repository (add dependency for cor…
Browse files Browse the repository at this point in the history
…outines)
  • Loading branch information
AndreaBrighi committed May 12, 2023
1 parent cf5b911 commit f628d3a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.intelligentbackpack.desktopdomain.repository
import com.intelligentbackpack.desktopdomain.entities.Book
import com.intelligentbackpack.desktopdomain.entities.Desktop
import com.intelligentbackpack.desktopdomain.entities.SchoolSupply
import kotlinx.coroutines.flow.Flow

/**
* Interface for the desktop domain repository.
Expand Down Expand Up @@ -44,11 +45,37 @@ interface DesktopDomainRepository {
*/
fun getSchoolSupply(rfid: String, success: (SchoolSupply) -> Unit, error: (Exception) -> Unit)

/**
* Puts a school supply in the backpack.
*
* @param rfid The RFID of the school supply.
* @param success The success callback with the new desktop.
* @param error The error callback.
*/
fun putSchoolSupplyInBackpack(rfid: String, success: (Desktop) -> Unit, error: (Exception) -> Unit)

/**
* Takes a school supply from the backpack.
*
* @param rfid The RFID of the school supply.
* @param success The success callback with the new desktop.
* @param error The error callback.
*/
fun takeSchoolSupplyFromBackpack(rfid: String, success: (Desktop) -> Unit, error: (Exception) -> Unit)

/**
* Deletes the desktop and all its school supplies.
*
* @param success The success callback.
* @param error The error callback.
*/
fun deleteDesktop(success: () -> Unit, error: (Exception) -> Unit)

/**
* Subscribes to the backpack.
*
* @param success The success callback with a [Flow] of the school supplies in backpack
* @param error The error callback.
*/
fun subscribeToBackpack(success: (Flow<Set<SchoolSupply>>) -> Unit, error: (Exception) -> Unit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intelligentbackpack.desktopdomain.entities.Book
import com.intelligentbackpack.desktopdomain.entities.Desktop
import com.intelligentbackpack.desktopdomain.entities.SchoolSupply
import com.intelligentbackpack.desktopdomain.repository.DesktopDomainRepository
import kotlinx.coroutines.flow.Flow

/**
* Use case for the desktop domain.
Expand Down Expand Up @@ -45,12 +46,43 @@ class DesktopUseCase(private val repository: DesktopDomainRepository) {
suspend fun getSchoolSupply(rfid: String, success: (SchoolSupply) -> Unit, error: (Exception) -> Unit) =
repository.getSchoolSupply(rfid, success, error)

/**
* Puts a school supply in the backpack.
*
* @param rfid The RFID of the school supply.
* @param success The success callback with the new desktop.
* @param error The error callback.
*/
suspend fun putSchoolSupplyInBackpack(rfid: String, success: (Desktop) -> Unit, error: (Exception) -> Unit) =
repository.putSchoolSupplyInBackpack(rfid, success, error)

/**
* Takes a school supply from the backpack.
*
* @param rfid The RFID of the school supply.
* @param success The success callback with the new desktop.
* @param error The error callback.
*/
suspend fun takeSchoolSupplyFromBackpack(rfid: String, success: (Desktop) -> Unit, error: (Exception) -> Unit) =
repository.takeSchoolSupplyFromBackpack(rfid, success, error)

/**
* Subscribes to the backpack.
*
* @param success The success callback with a [Flow] of the school supplies in backpack
* @param error The error callback.
*/
suspend fun subscribeToBackpack(success: (Flow<Set<SchoolSupply>>) -> Unit, error: (Exception) -> Unit) =
repository.subscribeToBackpack(success, error)

/**
* Delete the desktop.
*
* @param success The success callback.
* @param error The error callback.
*/
suspend fun deleteDesktop(success: () -> Unit, error: (Exception) -> Unit) =
suspend

fun deleteDesktop(success: () -> Unit, error: (Exception) -> Unit) =
repository.deleteDesktop(success, error)
}

0 comments on commit f628d3a

Please sign in to comment.