Skip to content

Commit

Permalink
Fixed readme error for private repos in which user contributes
Browse files Browse the repository at this point in the history
  • Loading branch information
kishan-dhankecha committed May 7, 2022
1 parent ec112be commit 2e23002
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions lib/github/readme/infrastructure/readme_repository.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:repostar/core/domain/fresh.dart';
import 'package:repostar/core/infrastructure/network_exceptions.dart';
import 'package:repostar/github/core/domain/github_failure.dart';
Expand All @@ -18,32 +19,40 @@ class ReadmeRepository {
String fullName,
) async {
try {
final html = await _remoteService.getReadmeHtml(fullName);
return right(await html.when(
noConnection: () async {
return Fresh.no(
await _localService.getReadme(fullName).then((dto) {
return dto?.toDomain();
}),
);
},
notModified: (_) async {
final cachedDto = await _localService.getReadme(fullName);
final starred = await _remoteService.getStarredStatus(fullName);
final updatedDto = cachedDto?.copyWith(starred: starred ?? false);
return Fresh.yes(updatedDto?.toDomain());
},
withNewData: (html, _) async {
final starred = await _remoteService.getStarredStatus(fullName);
final dto = ReadmeDto(
html: html,
starred: starred ?? false,
fullName: fullName,
);
await _localService.upsertReadme(dto);
return Fresh.yes(dto.toDomain());
},
));
try {
final html = await _remoteService.getReadmeHtml(fullName);
return right(await html.when(
noConnection: () async {
return Fresh.no(
await _localService.getReadme(fullName).then((dto) {
return dto?.toDomain();
}),
);
},
notModified: (_) async {
final cachedDto = await _localService.getReadme(fullName);
final starred = await _remoteService.getStarredStatus(fullName);
final updatedDto = cachedDto?.copyWith(starred: starred ?? false);
return Fresh.yes(updatedDto?.toDomain());
},
withNewData: (html, _) async {
final starred = await _remoteService.getStarredStatus(fullName);
final dto = ReadmeDto(
html: html,
starred: starred ?? false,
fullName: fullName,
);
await _localService.upsertReadme(dto);
return Fresh.yes(dto.toDomain());
},
));
} on DioError catch (e) {
if (e.response?.statusCode == 404) {
return right(Fresh.no(null));
} else {
rethrow;
}
}
} on RestApiException catch (e) {
return left(GithubFailure.api(e.errorCode));
}
Expand Down

0 comments on commit 2e23002

Please sign in to comment.