Skip to content

Instantly share code, notes, and snippets.

@yunus-floo
Created May 9, 2022 15:41
Show Gist options
  • Save yunus-floo/d61b9c785fa6297c49080fb6036b0355 to your computer and use it in GitHub Desktop.
Save yunus-floo/d61b9c785fa6297c49080fb6036b0355 to your computer and use it in GitHub Desktop.
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();
}
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