Skip to content

Instantly share code, notes, and snippets.

View fredgrott's full-sized avatar
👾
focusing on flutter cross platform mobile dev

Fred Grott fredgrott

👾
focusing on flutter cross platform mobile dev
View GitHub Profile
@fredgrott
fredgrott / calling_json-data_fixture.dart
Created March 2, 2025 17:59
calling json data fixture
CompanyFixture.factory().makeJsonArray(10)
CompanyFixture.factory().empty("EmptyCompany").makeJsonObject();
CompanyFixture.factory().empty("EmptyCompany").makeJsonArray(10);
@fredgrott
fredgrott / calling.dart
Created March 2, 2025 17:56
calling the data fixture
CompanyFixture.factory(0.makeMany(10);
@fredgrott
fredgrott / json_data_fixture.dart
Created March 2, 2025 17:11
extension json data fixture
import 'company_model.dart';
extension CompanyFixture on Company {
static _CompanyFixtureFactory factory() =>
_CompanyFixtureFactory();
}
class _CompanyFixtureFactory extends
JsonFixtureFactory<Company> {
@override
@fredgrott
fredgrott / data_fixture.dart
Last active March 2, 2025 16:35
extension and data fixture
import 'company_model.dart';
extension CompanyFixture on Company{
static _CompanyFixtureFactory factory() => _CompanyFixtureFactory();
}
class _CompanyFixtureFactory extends FixtureFactory<Company>{
@override
FixtureDefinition<Company> defintion() => define(
(faker) => Company(
import 'package:equatable/equatable.dart';
import 'package:uuid/uuid.dart';
import 'domain_model.dart';
class Company with DomainModel, Equatable{
final String name;
final Ktlist<Person> employees;
Company({this.id - Uuuid().v4(), this.name,
this.employees});
mixin DomainModel {
late String id;
}
@fredgrott
fredgrott / main.dart
Created February 22, 2025 15:54
cqrs demo
main() async {
final cqrs = Cqrs()
..registerAggregate(AccountAggregate())
..registerRepository(InMemoryRepository<Account>(forAggregate: "account"));
cqrs.events.listen(print);
await cqrs.submitCommand(CreateAccountCmd(owner: "Teja", modelId: "1"));
await cqrs.submitCommand(DepositCmd(modelId: "1", amount: 200.0));
await cqrs.submitCommand(DepositCmd(modelId: "1", amount: 200.0));
@fredgrott
fredgrott / aggregate.dart
Created February 22, 2025 15:45
cqrs aggregate
class AccountAggregate extends Aggregate<Account> {
final String name = 'account';
@override
Account initializeModel() => Account();
@override
Future<void> apply(Account model, DomainEvent event) async {
if (event is AccountCreatedEvent) {
model.id = event.id;
@fredgrott
fredgrott / events.dart
Created February 22, 2025 15:30
cqrs events
class AccountCreatedEvent implements Event {
String get forAggregate => "account";
final String id;
final String owner;
AccountCreatedEvent({@required this.id, @required this.owner});
String toString() => "Created account ($id) for $owner.";
@fredgrott
fredgrott / commands.dart
Created February 22, 2025 15:14
cqrs command
abstract class ForAccount {
final String forAggregate = "account";
}
class CreateAccountCmd extends Command with ForAccount {
final String modelId;
final String owner;
CreateAccountCmd({@required this.owner, @required this.modelId});