Skip to content

Commit 1f3b306

Browse files
committed
prepare starred repos repo
1 parent 52766d4 commit 1f3b306

File tree

4 files changed

+101
-8
lines changed

4 files changed

+101
-8
lines changed

analysis_options.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
include: package:flutter_lints/flutter.yaml
22

3+
analyzer:
4+
errors:
5+
todo: ignore
6+
37
linter:
48
rules:
59
avoid_print: false # Uncomment to disable the `avoid_print` rule

lib/core/domain/fresh.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,26 @@ class Fresh<T> with _$Fresh<T> {
88
const factory Fresh({
99
required T entity,
1010
required bool isFresh,
11+
bool? more,
1112
}) = _Fresh<T>;
13+
14+
factory Fresh.yes(
15+
T entity, {
16+
bool? more,
17+
}) =>
18+
Fresh(
19+
entity: entity,
20+
isFresh: true,
21+
more: more,
22+
);
23+
24+
factory Fresh.no(
25+
T entity, {
26+
bool? more,
27+
}) =>
28+
Fresh(
29+
entity: entity,
30+
isFresh: false,
31+
more: more,
32+
);
1233
}

lib/core/domain/fresh.freezed.dart

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ final _privateConstructorUsedError = UnsupportedError(
1717
class _$FreshTearOff {
1818
const _$FreshTearOff();
1919

20-
_Fresh<T> call<T>({required T entity, required bool isFresh}) {
20+
_Fresh<T> call<T>({required T entity, required bool isFresh, bool? more}) {
2121
return _Fresh<T>(
2222
entity: entity,
2323
isFresh: isFresh,
24+
more: more,
2425
);
2526
}
2627
}
@@ -32,6 +33,7 @@ const $Fresh = _$FreshTearOff();
3233
mixin _$Fresh<T> {
3334
T get entity => throw _privateConstructorUsedError;
3435
bool get isFresh => throw _privateConstructorUsedError;
36+
bool? get more => throw _privateConstructorUsedError;
3537

3638
@JsonKey(ignore: true)
3739
$FreshCopyWith<T, Fresh<T>> get copyWith =>
@@ -42,7 +44,7 @@ mixin _$Fresh<T> {
4244
abstract class $FreshCopyWith<T, $Res> {
4345
factory $FreshCopyWith(Fresh<T> value, $Res Function(Fresh<T>) then) =
4446
_$FreshCopyWithImpl<T, $Res>;
45-
$Res call({T entity, bool isFresh});
47+
$Res call({T entity, bool isFresh, bool? more});
4648
}
4749

4850
/// @nodoc
@@ -57,6 +59,7 @@ class _$FreshCopyWithImpl<T, $Res> implements $FreshCopyWith<T, $Res> {
5759
$Res call({
5860
Object? entity = freezed,
5961
Object? isFresh = freezed,
62+
Object? more = freezed,
6063
}) {
6164
return _then(_value.copyWith(
6265
entity: entity == freezed
@@ -67,6 +70,10 @@ class _$FreshCopyWithImpl<T, $Res> implements $FreshCopyWith<T, $Res> {
6770
? _value.isFresh
6871
: isFresh // ignore: cast_nullable_to_non_nullable
6972
as bool,
73+
more: more == freezed
74+
? _value.more
75+
: more // ignore: cast_nullable_to_non_nullable
76+
as bool?,
7077
));
7178
}
7279
}
@@ -76,7 +83,7 @@ abstract class _$FreshCopyWith<T, $Res> implements $FreshCopyWith<T, $Res> {
7683
factory _$FreshCopyWith(_Fresh<T> value, $Res Function(_Fresh<T>) then) =
7784
__$FreshCopyWithImpl<T, $Res>;
7885
@override
79-
$Res call({T entity, bool isFresh});
86+
$Res call({T entity, bool isFresh, bool? more});
8087
}
8188

8289
/// @nodoc
@@ -92,6 +99,7 @@ class __$FreshCopyWithImpl<T, $Res> extends _$FreshCopyWithImpl<T, $Res>
9299
$Res call({
93100
Object? entity = freezed,
94101
Object? isFresh = freezed,
102+
Object? more = freezed,
95103
}) {
96104
return _then(_Fresh<T>(
97105
entity: entity == freezed
@@ -102,23 +110,30 @@ class __$FreshCopyWithImpl<T, $Res> extends _$FreshCopyWithImpl<T, $Res>
102110
? _value.isFresh
103111
: isFresh // ignore: cast_nullable_to_non_nullable
104112
as bool,
113+
more: more == freezed
114+
? _value.more
115+
: more // ignore: cast_nullable_to_non_nullable
116+
as bool?,
105117
));
106118
}
107119
}
108120

109121
/// @nodoc
110122
111123
class _$_Fresh<T> extends _Fresh<T> {
112-
const _$_Fresh({required this.entity, required this.isFresh}) : super._();
124+
const _$_Fresh({required this.entity, required this.isFresh, this.more})
125+
: super._();
113126

114127
@override
115128
final T entity;
116129
@override
117130
final bool isFresh;
131+
@override
132+
final bool? more;
118133

119134
@override
120135
String toString() {
121-
return 'Fresh<$T>(entity: $entity, isFresh: $isFresh)';
136+
return 'Fresh<$T>(entity: $entity, isFresh: $isFresh, more: $more)';
122137
}
123138

124139
@override
@@ -128,14 +143,18 @@ class _$_Fresh<T> extends _Fresh<T> {
128143
(identical(other.entity, entity) ||
129144
const DeepCollectionEquality().equals(other.entity, entity)) &&
130145
(identical(other.isFresh, isFresh) ||
131-
const DeepCollectionEquality().equals(other.isFresh, isFresh)));
146+
const DeepCollectionEquality()
147+
.equals(other.isFresh, isFresh)) &&
148+
(identical(other.more, more) ||
149+
const DeepCollectionEquality().equals(other.more, more)));
132150
}
133151

134152
@override
135153
int get hashCode =>
136154
runtimeType.hashCode ^
137155
const DeepCollectionEquality().hash(entity) ^
138-
const DeepCollectionEquality().hash(isFresh);
156+
const DeepCollectionEquality().hash(isFresh) ^
157+
const DeepCollectionEquality().hash(more);
139158

140159
@JsonKey(ignore: true)
141160
@override
@@ -144,7 +163,7 @@ class _$_Fresh<T> extends _Fresh<T> {
144163
}
145164

146165
abstract class _Fresh<T> extends Fresh<T> {
147-
const factory _Fresh({required T entity, required bool isFresh}) =
166+
const factory _Fresh({required T entity, required bool isFresh, bool? more}) =
148167
_$_Fresh<T>;
149168
const _Fresh._() : super._();
150169

@@ -153,6 +172,8 @@ abstract class _Fresh<T> extends Fresh<T> {
153172
@override
154173
bool get isFresh => throw _privateConstructorUsedError;
155174
@override
175+
bool? get more => throw _privateConstructorUsedError;
176+
@override
156177
@JsonKey(ignore: true)
157178
_$FreshCopyWith<T, _Fresh<T>> get copyWith =>
158179
throw _privateConstructorUsedError;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import 'package:dartz/dartz.dart';
2+
import 'package:repo_viewer/core/domain/fresh.dart';
3+
import 'package:repo_viewer/core/infra/network_exceptions.dart';
4+
import 'package:repo_viewer/github/core/domain/github_failure.dart';
5+
import 'package:repo_viewer/github/core/domain/github_repo.dart';
6+
import 'package:repo_viewer/github/core/infra/github_repo_dto.dart';
7+
import 'package:repo_viewer/github/repos/starred/infra/starred_repos_remote_service.dart';
8+
9+
class StarredReposRepo {
10+
final StarredReposRemoteService _remoteService;
11+
// TODO: local service
12+
13+
StarredReposRepo(this._remoteService);
14+
15+
Future<Either<GithubFailure, Fresh<List<GithubRepo>>>> getStarredReposPage(
16+
int page,
17+
) async {
18+
try {
19+
final items = await _remoteService.getStarredReposPage(page);
20+
return right(items.when(
21+
// TODO: Get data from local service.
22+
noConnection: (maxPage) => Fresh.no(
23+
[],
24+
more: page < maxPage,
25+
),
26+
// TODO: Get data from local service.
27+
notModified: (maxPage) => Fresh.yes(
28+
[],
29+
more: page < maxPage,
30+
),
31+
// TODO: Save data to local service.
32+
withNewData: (data, maxPage) => Fresh.yes(
33+
data.toDomain(),
34+
more: page < maxPage,
35+
),
36+
));
37+
} on RestApiException catch (e) {
38+
return left(GithubFailure.api(e.errorCode));
39+
}
40+
}
41+
}
42+
43+
extension GithubReposDTOConverter on List<GithubRepoDTO> {
44+
List<GithubRepo> toDomain() {
45+
return map((e) => e.toDomain()).toList();
46+
}
47+
}

0 commit comments

Comments
 (0)