Skip to content

Commit

Permalink
rename for refactoring
Browse files Browse the repository at this point in the history
wip #377
  • Loading branch information
zin- committed Aug 5, 2024
1 parent e11436f commit c747f69
Show file tree
Hide file tree
Showing 53 changed files with 126 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const _name = "DatabaseTupleRepository tests";

class TestEntity extends EntityV1 {}

class SavedTestEntity extends TestEntity with SavedDatabaseTupleMixin<int> {}
class SavedTestEntity extends TestEntity with SavedDatabaseTupleMixinV1<int> {}

class TestRepository
extends DatabaseTupleRepository<TestEntity, SavedTestEntity, int> {
extends DatabaseTupleRepositoryV1<TestEntity, SavedTestEntity, int> {
TestRepository(super.tableDefinition);

@override
Expand Down Expand Up @@ -52,12 +52,12 @@ void main() => group(
);
}

DatabaseTupleRepository.databaseAccessor =
DatabaseTupleRepositoryV1.databaseAccessor =
await DatabaseRepository().receive(sampleDefDBAddedColumn);
});
tearDownAll(() {
DatabaseFactory.onTest = false;
DatabaseTupleRepository.databaseAccessor = null;
DatabaseTupleRepositoryV1.databaseAccessor = null;
});

test(
Expand Down
2 changes: 1 addition & 1 deletion integration_test/scenarios/task_scenario.dart
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ void testTaskScenario() => group(': $_scenarioName', () {
testWidgets(
'not notify on active act.',
(widgetTester) async {
DatabaseTupleRepository.databaseAccessor = dbA;
DatabaseTupleRepositoryV1.databaseAccessor = dbA;

widgetTester.setMockMethodCallHandler(
MethodChannelMock.flutterLocalNotifications,
Expand Down
2 changes: 1 addition & 1 deletion integration_test/scenarios/todo_scenario.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void testTodoScenario() => group(': $_scenarioName', () {
testWidgets(
'not notify on done mem.',
(widgetTester) async {
DatabaseTupleRepository.databaseAccessor = dbA;
DatabaseTupleRepositoryV1.databaseAccessor = dbA;

int initializeCount = 0;
int cancelCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/act_counter/act_counter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:mem/framework/repository/entity.dart';
import 'package:mem/repositories/mem.dart';

class ActCounter extends EntityV1 {
final SavedMem _mem;
final SavedMemV1 _mem;
final Iterable<SavedAct> _acts;
final int memId;
final String? name;
Expand Down
4 changes: 2 additions & 2 deletions lib/act_counter/act_counter_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'act_counter_repository.dart';

class ActCounterClient {
final ActsClient _actsClient;
final MemRepository _memRepository;
final MemRepositoryV1 _memRepository;
final ActRepository _actRepository;
final ActCounterRepository _actCounterRepository;

Expand Down Expand Up @@ -64,7 +64,7 @@ class ActCounterClient {

factory ActCounterClient() => _instance ??= ActCounterClient._(
ActsClient(),
MemRepository(),
MemRepositoryV1(),
ActRepository(),
ActCounterRepository(),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/act_counter/single_selectable_mem_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SingleSelectableMemListItem extends ConsumerWidget {

class _SingleSelectableMemListItemComponent extends ListTile {
_SingleSelectableMemListItemComponent(
SavedMem mem,
SavedMemV1 mem,
bool isSelected,
void Function(int? memId) onSelected,
) : super(
Expand Down
2 changes: 1 addition & 1 deletion lib/acts/act_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension _ActOrderByExt on ActOrderBy {
}
}

class ActRepository extends DatabaseTupleRepository<Act, SavedAct, int> {
class ActRepository extends DatabaseTupleRepositoryV1<Act, SavedAct, int> {
@override
Future<SavedAct?> findOneBy({
int? memId,
Expand Down
2 changes: 1 addition & 1 deletion lib/acts/list/act_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class _ActList extends StatelessWidget {
final bool _isDateView;
final bool _isTimeView;
final List<Act> _actList;
final List<SavedMem> _memList;
final List<SavedMemV1> _memList;
final ScrollController? _scrollController;

const _ActList(
Expand Down
2 changes: 1 addition & 1 deletion lib/acts/list/item/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'view.dart';

class ActListItemBuilder {
final MapEntry<DateTime, List<Act>> _actListWithDatetime;
final List<SavedMem> _memList;
final List<SavedMemV1> _memList;
final bool _isTimeView;

late final Map _actListGroupedByMemId;
Expand Down
2 changes: 1 addition & 1 deletion lib/acts/list/item/total_act_time_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:mem/repositories/mem.dart';

class TotalActTimeListItem extends StatelessWidget {
final List<Act> _actList;
final SavedMem? _mem;
final SavedMemV1? _mem;

const TotalActTimeListItem(this._actList, this._mem, {super.key});

Expand Down
4 changes: 2 additions & 2 deletions lib/components/created_and_updated_at_texts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import 'package:mem/repositories/mem.dart';
import 'package:mem/values/colors.dart';

class CreatedAndUpdatedAtTexts extends StatelessWidget {
final Mem _entity;
final MemV1 _entity;

const CreatedAndUpdatedAtTexts(this._entity, {super.key});

@override
Widget build(BuildContext context) => v(
() {
if (_entity is SavedMem) {
if (_entity is SavedMemV1) {
return Wrap(
direction: Axis.horizontal,
children: [
Expand Down
4 changes: 2 additions & 2 deletions lib/components/mem/list/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final loadMemList = FutureProvider(
final showDone = ref.watch(showDoneProvider);

final mems = await v(
() => MemRepository().ship(
() => MemRepositoryV1().ship(
archived: showNotArchived == showArchived ? null : showArchived,
done: showNotDone == showDone ? null : showDone,
),
Expand All @@ -31,7 +31,7 @@ final loadMemList = FutureProvider(
ref.read(memsProvider.notifier).upsertAll(
mems,
(tmp, item) =>
tmp is SavedMem && item is SavedMem ? tmp.id == item.id : false,
tmp is SavedMemV1 && item is SavedMemV1 ? tmp.id == item.id : false,
);
for (var mem in mems) {
ref.read(memItemsProvider.notifier).upsertAll(
Expand Down
10 changes: 5 additions & 5 deletions lib/components/mem/list/states.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ final showDoneProvider = StateNotifierProvider<ValueStateNotifier<bool>, bool>(
),
);
final _filteredMemsProvider = StateNotifierProvider.autoDispose<
ListValueStateNotifier<SavedMem>, List<SavedMem>>(
ListValueStateNotifier<SavedMemV1>, List<SavedMemV1>>(
(ref) {
final savedMems = ref.watch(memsProvider).map((e) => e as SavedMem);
final savedMems = ref.watch(memsProvider).map((e) => e as SavedMemV1);

final showNotArchived = ref.watch(showNotArchivedProvider);
final showArchived = ref.watch(showArchivedProvider);
Expand Down Expand Up @@ -85,7 +85,7 @@ final _filteredMemsProvider = StateNotifierProvider.autoDispose<
);

final memListProvider = StateNotifierProvider.autoDispose<
ValueStateNotifier<List<SavedMem>>, List<SavedMem>>((ref) {
ValueStateNotifier<List<SavedMemV1>>, List<SavedMemV1>>((ref) {
final filtered = ref.watch(_filteredMemsProvider);
final latestActsByMem = ref.watch(latestActsByMemProvider);
final savedMemNotifications = ref.watch(savedMemNotificationsProvider);
Expand Down Expand Up @@ -197,7 +197,7 @@ final latestActsByMemProvider = StateNotifierProvider.autoDispose<
() async {
if (current.isEmpty) {
final memIds =
ref.read(memsProvider).whereType<SavedMem>().map((e) => e.id);
ref.read(memsProvider).whereType<SavedMemV1>().map((e) => e.id);

final actsByMemIds = await ActRepository().ship(
memIdsIn: memIds,
Expand All @@ -224,7 +224,7 @@ final savedMemNotificationsProvider = StateNotifierProvider.autoDispose<
() async {
if (current.isEmpty) {
final memIds =
ref.read(memsProvider).whereType<SavedMem>().map((e) => e.id);
ref.read(memsProvider).whereType<SavedMemV1>().map((e) => e.id);

final actsByMemIds = await MemNotificationRepository().ship(
memIdsIn: memIds,
Expand Down
2 changes: 1 addition & 1 deletion lib/components/mem/list/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MemListView extends ConsumerWidget {
}

class _MemListViewComponent extends StatelessWidget {
final List<SavedMem> _memList;
final List<SavedMemV1> _memList;
final Widget _appBar;
final Widget Function(int memId) _itemBuilder;
final ScrollController? _scrollController;
Expand Down
6 changes: 3 additions & 3 deletions lib/components/mem/mem_done_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:mem/logger/log_service.dart';
import 'package:mem/repositories/mem.dart';

class MemDoneCheckbox extends StatelessWidget {
final Mem _mem;
final MemV1 _mem;
final Function(bool? value) _onChanged;

const MemDoneCheckbox(
Expand All @@ -19,11 +19,11 @@ class MemDoneCheckbox extends StatelessWidget {
() => HeroView(
heroTag(
'mem-done',
_mem is SavedMem ? _mem.id : null,
_mem is SavedMemV1 ? _mem.id : null,
),
Checkbox(
value: _mem.isDone,
onChanged: (_mem is SavedMem ? _mem.isArchived : false)
onChanged: (_mem is SavedMemV1 ? _mem.isArchived : false)
? null
: _onChanged,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/components/mem/mem_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Key keyMemName = const Key("mem-name");
String _memNameTag(int? memId) => heroTag('mem-name', memId);

class MemNameText extends StatelessWidget {
final SavedMem _mem;
final SavedMemV1 _mem;

const MemNameText(this._mem, {super.key});

Expand Down
2 changes: 1 addition & 1 deletion lib/core/act.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Act extends EntityV1 {
}}";
}

class SavedAct extends Act with SavedDatabaseTupleMixin<int> {
class SavedAct extends Act with SavedDatabaseTupleMixinV1<int> {
SavedAct(super.memId, super.period);

SavedAct copiedWith(DateAndTimePeriod Function()? period) => SavedAct(
Expand Down
12 changes: 6 additions & 6 deletions lib/core/mem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import 'package:mem/notifications/notification/type.dart';
import 'package:mem/notifications/schedule.dart';
import 'package:mem/repositories/mem.dart';

class Mem extends EntityV1 {
class MemV1 extends EntityV1 {
final String name;
final DateTime? doneAt;
final DateAndTimePeriod? period;

Mem(this.name, this.doneAt, this.period);
MemV1(this.name, this.doneAt, this.period);

bool get isDone => doneAt != null;

factory Mem.defaultNew() => Mem("", null, null);
factory MemV1.defaultNew() => MemV1("", null, null);

Iterable<Schedule> periodSchedules(
TimeOfDay startOfDay,
) =>
v(
() {
final id = this is SavedMem ? (this as SavedMem).id : null;
final id = this is SavedMemV1 ? (this as SavedMemV1).id : null;

return id == null
? throw Exception() // coverage:ignore-line
Expand Down Expand Up @@ -64,12 +64,12 @@ class Mem extends EntityV1 {
},
);

Mem copiedWith({
MemV1 copiedWith({
String Function()? name,
DateTime? Function()? doneAt,
DateAndTimePeriod? Function()? period,
}) =>
Mem(
MemV1(
name == null ? this.name : name(),
doneAt == null ? this.doneAt : doneAt(),
period == null ? this.period : period(),
Expand Down
2 changes: 1 addition & 1 deletion lib/core/mem_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:mem/core/mem_item.dart';
import 'package:mem/core/mem_notification.dart';

class MemDetail {
final Mem mem;
final MemV1 mem;
final List<MemItem> memItems;
final List<MemNotification>? notifications;

Expand Down
2 changes: 1 addition & 1 deletion lib/framework/database/definition/database_definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:mem/framework/database/definition/exceptions.dart';
import 'package:mem/framework/database/definition/table_definition.dart';
import 'package:mem/framework/repository/entity.dart';

class DatabaseDefinition extends Entity {
class DatabaseDefinition extends EntityV2 {
final String name;
final int version;
final List<TableDefinition> tableDefinitions;
Expand Down
4 changes: 2 additions & 2 deletions lib/framework/repository/database_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:mem/framework/database/factory.dart';
import 'package:mem/framework/repository/repository.dart';
import 'package:mem/logger/log_service.dart';

class DatabaseRepository extends Repository<DatabaseDefinition>
class DatabaseRepository extends RepositoryV2<DatabaseDefinition>
with Receiver<DatabaseDefinition, DatabaseAccessor> {
static DatabaseRepository? _instance;

Expand Down Expand Up @@ -46,7 +46,7 @@ class DatabaseRepository extends Repository<DatabaseDefinition>

Future<void> replace(String name, File backup) => v(
() async {
await DatabaseTupleRepository.close();
await DatabaseTupleRepositoryV1.close();

final current = (await shipFileByNameIs(name))!;

Expand Down
4 changes: 2 additions & 2 deletions lib/framework/repository/database_tuple_entity.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:mem/databases/table_definitions/base.dart';
import 'package:mem/framework/repository/entity.dart';

mixin SavedDatabaseTupleMixin<T> on EntityV1 {
mixin SavedDatabaseTupleMixinV1<T> on EntityV1 {
late T id;
late DateTime createdAt;
DateTime? updatedAt;
Expand All @@ -25,7 +25,7 @@ mixin SavedDatabaseTupleMixin<T> on EntityV1 {
};
}

SavedDatabaseTupleMixin copiedFrom(SavedDatabaseTupleMixin origin) => this
SavedDatabaseTupleMixinV1 copiedFrom(SavedDatabaseTupleMixinV1 origin) => this
..id = origin.id
..createdAt = origin.createdAt
..updatedAt = origin.updatedAt
Expand Down
4 changes: 2 additions & 2 deletions lib/framework/repository/database_tuple_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:mem/framework/repository/condition/conditions.dart';
// DatabaseTupleに型情報を付与することでズレは発生しなくなった
// ただ、これだと未保存のDatabaseTupleが
// FIXME SavedEntityはSavedDatabaseTupleをmixinしている必要があるが型制約を定義できていない
abstract class DatabaseTupleRepository<E extends EntityV1,
abstract class DatabaseTupleRepositoryV1<E extends EntityV1,
SavedEntity extends E, Id> implements RepositoryV1<E, SavedEntity> {
Map<String, dynamic> unpack(E entity);

Expand Down Expand Up @@ -228,5 +228,5 @@ abstract class DatabaseTupleRepository<E extends EntityV1,

final TableDefinition _tableDefinition;

DatabaseTupleRepository(this._tableDefinition);
DatabaseTupleRepositoryV1(this._tableDefinition);
}
4 changes: 2 additions & 2 deletions lib/framework/repository/entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// # 語源
//
// 「存在するもの」、「実体」
abstract class EntityV1 {}
abstract class EntityV2 {}

abstract class Entity {}
abstract class EntityV1 {}
// memo
// - view, domain, dataのそれぞれの領域で似た内容でも型が変わることになるはず
// これをしっかりと定義したい
Expand Down
2 changes: 1 addition & 1 deletion lib/framework/repository/key_with_value.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:mem/framework/repository/entity.dart';

abstract class KeyWithValue<Key, Value> extends Entity {
abstract class KeyWithValue<Key, Value> extends EntityV2 {
final Key key;
final Value value;

Expand Down
4 changes: 2 additions & 2 deletions lib/framework/repository/key_with_value_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'package:mem/framework/repository/key_with_value.dart';
import 'package:mem/framework/repository/repository.dart';

abstract class KeyWithValueRepository<E extends KeyWithValue<Key, dynamic>, Key>
extends Repository<E>
extends RepositoryV2<E>
with Receiver<E, bool>, DiscarderByKey<E, Key, bool> {}

mixin DiscarderByKey<E extends KeyWithValue<Key, dynamic>, Key, Result>
on Repository<E> {
on RepositoryV2<E> {
Future<Result> discard(Key key);
}
Loading

0 comments on commit c747f69

Please sign in to comment.