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 / aggregate_model.dart
Created February 22, 2025 15:09
aggregate model
class Account implements AggregateModel {
String id;
String owner;
double amount;
Account({this.id = Uuid().v4(), this.owner, this.amount});
}
@fredgrott
fredgrott / repository.dart
Created February 21, 2025 19:33
repository part of cqrs
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Modified from jaguar cqrs MIT license
// Copyright 2016
import 'dart:async';
import 'package:fdd_api/core/cqrs/definition.dart';
@fredgrott
fredgrott / definition.dart
Created February 21, 2025 16:57
definition part of cqrs
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Modified from jaguar cqrs MIT license
// Copyright 2016
// ignore_for_file: use_setters_to_change_properties
import 'dart:async';
@fredgrott
fredgrott / main.dart
Created February 21, 2025 16:14
main demo cqrs
void main() async {
final cqrs = CQRS()
..registerAggregate(AccountAggregate())
..resigerRepository(InMemoryRepository<Account>(forAggregate: "account"));
cqrs.events.listen(debugPrint);
@fredgrott
fredgrott / cqrs.dart
Created February 21, 2025 15:57
jaguar CQRS updated to dart 3
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Modified from jaguar cqrs MIT license
// Copyright 2016
// ignore_for_file: unnecessary_null_comparison
import 'dart:async';
@fredgrott
fredgrott / value_objects.dart
Created February 9, 2025 15:46
value objects
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// ignore_for_file: unnecessary_null_comparison
import 'package:dartz/dartz.dart';
import 'package:fdd_api/core/value_objects/errors.dart';
import 'package:fdd_api/core/value_objects/failures.dart';
import 'package:fdd_api/core/value_objects/ivalidatable.dart';
@fredgrott
fredgrott / value_validators.dart
Created February 9, 2025 15:44
value validators
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import 'package:dartz/dartz.dart';
import 'package:fdd_api/core/value_objects/failures.dart';
import 'package:kt_dart/kt.dart';
Either<ValueFailure<String>, String> validateMaxStringLength(String input, int maxLength) {
if (input.length <= maxLength) {
@fredgrott
fredgrott / ivalidatable.dart
Created February 9, 2025 15:43
vo ivalidatable
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
abstract class IValidatable {
bool isValid();
}
@fredgrott
fredgrott / failures.dart
Created February 9, 2025 15:41
vo failures
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import 'package:freezed_annotation/freezed_annotation.dart';
part 'failures.freezed.dart';
@freezed
abstract class ValueFailure<T> with _$ValueFailure<T> {
@fredgrott
fredgrott / errors.dart
Created February 9, 2025 15:40
vo errors
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import 'package:fdd_api/core/value_objects/failures.dart';
class UnexpectedValueError extends Error {
final ValueFailure valueFailure;
UnexpectedValueError(this.valueFailure);