This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AlbumDataMapper( | |
private val songListDataMapper: NullableInputListMapper<NetworkSong, Song> | |
) : Mapper<NetworkAlbum, Album> { | |
override fun map(input: NetworkAlbum): Album { | |
return Album( | |
input.id.orEmpty(), | |
input.title.orEmpty(), | |
songListDataMapper.map(input.songs) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun mapAlbumDto(input: NetworkAlbum, mapSongList: (List<NetworkSong>?) -> List<Song>): Album { | |
return Album( | |
input.id.orEmpty(), | |
input.title.orEmpty(), | |
mapSongList(input.songs) | |
) | |
} | |
fun mapSongDto(input: NetworkSong): Song { | |
return Song( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AlbumRepositoryImpl( | |
private val albumApiService: AlbumApiService, | |
private val albumDataMapper: Mapper<NetworkAlbum, Album> | |
) : AlbumRepository { | |
override fun getAlbumById(id: String): Single<SimpleResult<Album>> { | |
return albumApiService.getAlbumById(id).map { | |
it.fold( | |
success = { dto -> Result.Success(albumDataMapper.map(dto)) }, | |
failure = { throwable -> Result.Failure(throwable) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AlbumRepositoryImpl( | |
private val albumApiService: AlbumApiService, | |
private val mapAlbumDto: (NetworkAlbum) -> Album | |
) : AlbumRepository { | |
override fun getAlbumById(id: String): Single<SimpleResult<Album>> { | |
return albumApiService.getAlbumById(id).map { | |
it.fold( | |
success = { dto -> Result.Success(mapAlbumDto(dto)) }, | |
failure = { throwable -> Result.Failure(throwable) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object OOPRepositoryFactory { | |
fun makeAlbumRepository(): AlbumRepository { | |
return AlbumRepositoryImpl( | |
AlbumApiServiceImpl(), | |
AlbumDataMapper(NullableInputListMapperImpl(SongDataMapper())) | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object FPRepositoryFactory { | |
fun makeAlbumRepository(): AlbumRepository { | |
return AlbumRepositoryImpl( | |
AlbumApiServiceImpl(), | |
makeAlbumDataMapper() | |
) | |
} | |
private fun makeAlbumDataMapper(): (NetworkAlbum) -> Album = { albumDto -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GetTransactionsUseCaseImpl( | |
private val getUserUseCase: GetUserUseCase, | |
private val transactionRepository: TransactionRepository | |
) : GetTransactionsUseCase { | |
override fun invoke(): Single<SimpleResult<List<Transaction>>> { | |
return transactionRepository.getTransactions(getUserUseCase().id) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun getTransactions( | |
getUserUseCase: GetUserUseCase, | |
transactionRepository: TransactionRepository | |
): Single<SimpleResult<List<Transaction>>> { | |
return transactionRepository.getTransactions(getUserUseCase().id) | |
} | |
typealias GetTransactionsUseCase = () -> Single<SimpleResult<List<Transaction>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface TransactionRepository { | |
fun getTransactions(userId: String): Single<SimpleResult<List<Transaction>>> | |
} | |
interface UserRepository { | |
fun getUser(): User |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GetUserUseCaseImpl( | |
private val userRepository: UserRepository | |
) : GetUserUseCase { | |
override fun invoke(): User = userRepository.getUser() | |
} |