Skip to content

Commit

Permalink
Another important work (refactoring, Clean Architecture)
Browse files Browse the repository at this point in the history
  • Loading branch information
SiekamCebule committed Nov 22, 2024
1 parent 560853c commit c6fd0ce
Show file tree
Hide file tree
Showing 215 changed files with 3,042 additions and 2,380 deletions.
22 changes: 22 additions & 0 deletions lib/core/algorithms/filter/composite_filter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:sj_manager/core/algorithms/filter/filter.dart';

class CompositeFilter<T> implements Filter<T> {
const CompositeFilter({
required this.filters,
});

final Iterable<Filter<T>> filters;

@override
Iterable<T> call(Iterable<T> source) {
Iterable<T> currentItems = List.of(source);
for (var filter in filters) {
currentItems = filter(currentItems);
}
return currentItems;
}

@override
bool get isValid =>
filters.isNotEmpty ? filters.every((filter) => filter.isValid) : false;
}
6 changes: 6 additions & 0 deletions lib/core/algorithms/filter/filter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
abstract interface class Filter<T> {
const Filter();

bool get isValid;
Iterable<T> call(Iterable<T> source);
}
56 changes: 56 additions & 0 deletions lib/core/algorithms/filter/generic_filters.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:sj_manager/core/classes/country/country.dart';
import 'package:sj_manager/core/algorithms/filter/filter.dart';
import 'package:sj_manager/core/mixins/country_mixin.dart';
import 'package:sj_manager/core/mixins/name_and_surname_mixin.dart';
import 'package:sj_manager/utilities/filters/matching_algorithms/matching_by_text_algorithm.dart';

class NoFilter<T> implements Filter<T> {
@override
Iterable<T> call(Iterable<T> source) {
return source;
}

@override
bool get isValid => false;
}

class NameSurnameFilter<T extends NameAndSurnameMixin> implements Filter<T> {
const NameSurnameFilter({
required this.text,
});

final String text;

@override
Iterable<T> call(Iterable<T> source) {
bool shouldPass(NameAndSurnameMixin data) {
final base = data.nameAndSurname();
return DefaultMatchingByTextAlgorithm(target: base, text: text).matches();
}

return source.where(shouldPass);
}

@override
bool get isValid => text.isNotEmpty;
}

class CountryFilter<T extends CountryMixin> implements Filter<T> {
const CountryFilter({
required this.country,
});

final Country? country;

@override
Iterable<T> call(Iterable<T> source) {
bool shouldPass(CountryMixin data) {
return data.country == country;
}

return source.where(shouldPass);
}

@override
bool get isValid => country != null;
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:sj_manager/core/country/country.dart';
import 'package:sj_manager/core/classes/country/country.dart';
import 'package:sj_manager/features/game_variants/data/models/game_variant_database.dart/sex.dart';
import 'package:sj_manager/core/team/country_team/country_team_facts_model.dart';
import 'package:sj_manager/core/classes/country_team/country_team_facts_model.dart';
import 'package:sj_manager/domain/entities/simulation/team/team.dart';

class CountryTeam extends Team {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:sj_manager/utilities/json/json_types.dart';
import 'package:sj_manager/core/jumps/simple_jump_model.dart';
import 'package:sj_manager/core/classes/jumps/simple_jump_model.dart';
import 'package:sj_manager/domain/entities/simulation/team/subteam_type.dart';

part 'country_team_facts.g.dart';
Expand Down
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions lib/core/countries/countries_repository/countries_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:sj_manager/core/classes/country/country.dart';

abstract interface class CountriesRepository {
Future<Iterable<Country>> getAll();
Future<Country> byCode(String code);
Future<Country> get none;
}

class CountryNotFoundError extends Error {
CountryNotFoundError({
required this.countryCode,
});

final String countryCode;

@override
String toString() {
return 'Didn\'t find a country with the code of \'$countryCode\'';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:collection/collection.dart';
import 'package:equatable/equatable.dart';
import 'package:sj_manager/core/classes/country/country.dart';
import 'package:sj_manager/core/countries/countries_repository/countries_repository.dart';

class InMemoryCountriesRepository with EquatableMixin implements CountriesRepository {
const InMemoryCountriesRepository({
required this.countries,
});

final Iterable<Country> countries;

@override
Future<Iterable<Country>> getAll() async => countries;

@override
Future<Country> byCode(String code) async {
final toReturn = countries.singleWhereOrNull(
(country) => country.code.toLowerCase() == code.toLowerCase(),
);
if (toReturn == null) {
throw CountryNotFoundError(countryCode: code.toLowerCase());
}
return toReturn;
}

@override
Future<Country> get none async => byCode('none');

@override
List<Object?> get props => [countries];
}
4 changes: 4 additions & 0 deletions lib/core/database_editor/database_editor_filter_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enum DatabaseEditorFilterType {
nameSurname,
country,
}
9 changes: 9 additions & 0 deletions lib/core/database_editor/database_editor_items_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
enum DatabaseEditorItemsType {
maleJumper,
femaleJumper,
}

const sjmDatabaseEditorItemsTypeOrder = [
DatabaseEditorItemsType.maleJumper,
DatabaseEditorItemsType.femaleJumper,
];
5 changes: 5 additions & 0 deletions lib/core/mixins/country_mixin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:sj_manager/core/classes/country/country.dart';

mixin CountryMixin {
Country get country;
}
12 changes: 12 additions & 0 deletions lib/core/mixins/name_and_surname_mixin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mixin NameAndSurnameMixin {
String get name;
String get surname;

String nameAndSurname({bool capitalizeSurname = false, bool reverse = false}) {
var appropriateSurname = surname;
if (capitalizeSurname) {
appropriateSurname = appropriateSurname.toUpperCase();
}
return reverse ? '$appropriateSurname $name ' : '$name $appropriateSurname';
}
}
5 changes: 5 additions & 0 deletions lib/core/mixins/sex_mixin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:sj_manager/features/game_variants/data/models/game_variant_database.dart/sex.dart';

mixin SexMixin {
Sex get sex;
}
5 changes: 5 additions & 0 deletions lib/core/utils/jumper/jumper_sex_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:sj_manager/core/mixins/sex_mixin.dart';
import 'package:sj_manager/features/game_variants/data/models/game_variant_database.dart/sex.dart';

bool jumperIsMale(SexMixin jumper) => jumper.sex == Sex.male;
bool jumperIsFemale(SexMixin jumper) => jumper.sex == Sex.female;
2 changes: 1 addition & 1 deletion lib/data/models/running/competition_flow_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:sj_manager/data/models/running/competition_start_list_repository.dart';
import 'package:sj_manager/domain/entities/simulation/competition/rules/competition_rules/default_competition_rules.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/domain/entities/simulation/team/team.dart';

abstract class CompetitionFlowController<E> {
Expand Down
7 changes: 5 additions & 2 deletions lib/domain/entities/game_variant/hill/hill.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:sj_manager/core/mixins/country_mixin.dart';

import 'package:sj_manager/utilities/json/countries.dart';
import 'package:sj_manager/utilities/json/json_types.dart';
import 'package:sj_manager/core/country/country.dart';
import 'package:sj_manager/core/classes/country/country.dart';
import 'package:sj_manager/domain/entities/game_variant/hill/hill_profile_type.dart';
import 'package:sj_manager/domain/entities/game_variant/hill/hill_type_by_size.dart';
import 'package:sj_manager/domain/entities/game_variant/hill/jumps_variability.dart';
Expand All @@ -13,7 +14,7 @@ import 'package:sj_manager/utilities/utils/doubles.dart';

part '../../../../utilities/json/manual_json/hill_json.dart';

class Hill with EquatableMixin {
class Hill with EquatableMixin, CountryMixin {
Hill({
required this.name,
required this.locality,
Expand Down Expand Up @@ -47,6 +48,8 @@ class Hill with EquatableMixin {

String name;
String locality;

@override
Country country;

double k;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:sj_manager/domain/entities/simulation/competition/competition.da
import 'package:sj_manager/domain/entities/simulation/competition/rules/utils/classification_score_creator/classification_score_creator.dart';
import 'package:sj_manager/domain/entities/simulation/standings/score/details/classification_score_details.dart';
import 'package:sj_manager/domain/entities/simulation/standings/standings.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/domain/entities/simulation/team/team.dart';

abstract class ClassificationRules<E> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:sj_manager/domain/entities/simulation/competition/rules/competit
import 'package:sj_manager/domain/entities/simulation/competition/rules/competition_rules/default_competition_rules_provider.dart';
import 'package:sj_manager/domain/entities/simulation/standings/standings.dart';
import 'package:sj_manager/domain/entities/game_variant/hill/hill.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/domain/entities/simulation/team/competition_team.dart';
import 'package:equatable/equatable.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:equatable/equatable.dart';
import 'package:sj_manager/domain/entities/simulation/competition/rules/competition_rules/default_competition_rules.dart';
import 'package:sj_manager/domain/entities/simulation/competition/rules/competition_rules/default_competition_rules_provider.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/presentation/ui/database_item_editors/default_competition_rules_preset_editor/default_competition_rules_editor.dart';

class CalendarMainCompetitionRecordSetup with EquatableMixin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:sj_manager/domain/entities/simulation/competition/high_level_cal
import 'package:sj_manager/domain/entities/simulation/competition/rules/competition_rules/default_competition_rules.dart';
import 'package:sj_manager/domain/entities/simulation/event_series/event_series_calendar.dart';
import 'package:sj_manager/domain/entities/game_variant/hill/hill.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/domain/entities/simulation/team/competition_team.dart';
import 'package:sj_manager/utilities/utils/iterable.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:sj_manager/domain/entities/simulation/standings/score/details/co
import 'package:sj_manager/domain/entities/simulation/standings/score/score.dart';
import 'package:sj_manager/domain/entities/simulation/standings/score/typedefs.dart';
import 'package:sj_manager/domain/entities/simulation/standings/standings_positions_map_creator/standings_positions_creator.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';

class DefaultIndividualCompetitionRoundRules
extends DefaultCompetitionRoundRules<JumperDbRecord> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:equatable/equatable.dart';
import 'package:sj_manager/domain/entities/simulation/competition/rules/competition_rules/default_competition_rules.dart';
import 'package:sj_manager/domain/entities/simulation/competition/rules/competition_rules/default_competition_rules_provider.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/domain/entities/simulation/team/team.dart';

class DefaultCompetitionRulesPreset<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:sj_manager/domain/entities/simulation/event_series/event_series.
import 'package:sj_manager/domain/entities/simulation/standings/score/details/classification_score_details.dart';
import 'package:sj_manager/domain/entities/simulation/standings/score/details/competition_score_details.dart';
import 'package:sj_manager/domain/entities/simulation/standings/standings.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/domain/entities/simulation/team/team.dart';
import 'package:sj_manager/domain/entities/simulation/standings/score/typedefs.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:sj_manager/domain/entities/simulation/competition/competition_la
import 'package:sj_manager/domain/entities/simulation/competition/rules/utils/classification_score_creator/classification_score_creator.dart';
import 'package:sj_manager/domain/entities/simulation/standings/score/details/classification_score_details.dart';
import 'package:sj_manager/domain/entities/simulation/standings/score/typedefs.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';

abstract class DefaultClassificationScoreCreator<E,
C extends DefaultClassificationScoreCreatingContext<E>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:sj_manager/domain/entities/simulation/standings/score/typedefs.d
import 'package:sj_manager/domain/entities/simulation/standings/standings.dart';
import 'package:sj_manager/domain/entities/simulation/standings/standings_positions_map_creator/standings_positions_with_ex_aequos_creator.dart';
import 'package:sj_manager/domain/entities/simulation/standings/utils/standings_utils.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/domain/entities/simulation/team/competition_team.dart';

class DefaultIndividualClassificationScoreCreator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:sj_manager/domain/entities/simulation/competition/rules/utils/cl
import 'package:sj_manager/domain/entities/simulation/standings/score/typedefs.dart';
import 'package:sj_manager/domain/entities/simulation/standings/standings.dart';
import 'package:sj_manager/domain/entities/simulation/standings/utils/standings_utils.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/domain/entities/simulation/team/competition_team.dart';
import 'package:sj_manager/domain/entities/simulation/team/team.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:sj_manager/domain/entities/simulation/standings/score/details/ju
import 'package:sj_manager/domain/entities/simulation/standings/score/score.dart';
import 'package:sj_manager/domain/entities/simulation/standings/standings.dart';
import 'package:sj_manager/domain/entities/game_variant/hill/hill.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/domain/entities/simulation/team/competition_team.dart';

abstract class CompetitionScoreCreatingContext<T>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:sj_manager/domain/entities/simulation/competition/rules/utils/competition_score_creator/competition_score_creator.dart';
import 'package:sj_manager/domain/entities/simulation/standings/score/details/competition_score_details.dart';
import 'package:sj_manager/domain/entities/simulation/standings/score/score.dart';
import 'package:sj_manager/features/game_variants/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/features/database_editor/domain/entities/jumper/jumper_db_record.dart';
import 'package:sj_manager/domain/entities/simulation/team/competition_team.dart';
import 'package:collection/collection.dart';
import 'package:sj_manager/domain/entities/simulation/team/team.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:sj_manager/core/countries/countries_repository/countries_repository.dart';

import 'package:sj_manager/domain/entities/simulation/database/actions/simulation_action_type.dart';
import 'package:sj_manager/domain/entities/simulation/database/actions/simulation_actions_repo.dart';
Expand All @@ -11,9 +12,8 @@ import 'package:sj_manager/domain/entities/simulation/jumper/reports/jumper_repo
import 'package:sj_manager/domain/entities/simulation/flow/reports/team_reports.dart';
import 'package:sj_manager/domain/entities/game_variant/hill/hill.dart';
import 'package:sj_manager/features/game_variants/data/models/game_variant_database.dart/sex.dart';
import 'package:sj_manager/core/team/country_team/country_team.dart';
import 'package:sj_manager/core/classes/country_team/country_team.dart';
import 'package:sj_manager/domain/entities/simulation/team/subteam.dart';
import 'package:sj_manager/domain/repository_interfaces/countries/countries_repo.dart';
import 'package:sj_manager/domain/repository_interfaces/generic/items_ids_repo.dart';

class SimulationDatabase with EquatableMixin, ChangeNotifier {
Expand All @@ -39,7 +39,7 @@ class SimulationDatabase with EquatableMixin, ChangeNotifier {
DateTime currentDate;
List<SimulationJumper> jumpers;
List<Hill> hills;
CountriesRepo countries;
CountriesRepository countries;
List<CountryTeam> countryTeams;
List<SimulationSeason> seasons;
ItemsIdsRepo<String> idsRepo;
Expand Down Expand Up @@ -67,7 +67,7 @@ class SimulationDatabase with EquatableMixin, ChangeNotifier {
DateTime? currentDate,
List<SimulationJumper>? jumpers,
List<Hill>? hills,
CountriesRepo? countries,
CountriesRepository? countries,
List<CountryTeam>? countryTeams,
Map<Subteam, Iterable<String>>? subteamJumpers,
List<SimulationSeason>? seasons,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:async/async.dart';
import 'package:sj_manager/data/models/game_variant/game_variant.dart';
import 'package:sj_manager/data/models/game_variant/game_variant_start_date.dart';
import 'package:sj_manager/core/team/country_team/country_team.dart';
import 'package:sj_manager/core/classes/country_team/country_team.dart';
import 'package:sj_manager/domain/entities/simulation/team/subteam_type.dart';
import 'package:sj_manager/domain/entities/simulation/flow/simulation_mode.dart';
import 'package:sj_manager/domain/repository_interfaces/generic/value_repo.dart';
import 'package:sj_manager/features/game_variants/domain/entities/game_variant.dart';

class SimulationWizardOptionsRepo {
SimulationWizardOptionsRepo() {
Expand Down
Loading

0 comments on commit c6fd0ce

Please sign in to comment.