Created
May 9, 2022 15:41
-
-
Save yunus-floo/d61b9c785fa6297c49080fb6036b0355 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
abstract class AttachmentRepository { | |
Future<Either<Failure, List<Attachment>>> getData(); | |
} | |
class AttachmentRepositoryImpl implements AttachmentRepository { | |
AttachmentRepositoryImpl({ | |
required this.remoteDataSource, | |
}); | |
final AttachmentRemoteDataSource remoteDataSource; | |
@override | |
Future<Either<Failure, List<Attachment>>> getData() async { | |
try { | |
final result = await remoteDataSource.getData(); | |
return right(result.toDomainList); | |
} on RestApiException { | |
return left( | |
const Failure.serverError(), | |
); | |
} | |
} | |
} | |
extension DTOListToDomainList on List<AttachmentDTO> { | |
List<Attachment> get toDomainList => map((e) => e.toDomain()).toList(); | |
} |
This file contains hidden or 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 Failure { | |
const factory Failure.serverError() = Failure(); | |
const factory Failure.anotherFailure() = Failure(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment