diff --git a/packages/model/CHANGELOG.md b/packages/model/CHANGELOG.md index 3311e0bb..fed8fde0 100644 --- a/packages/model/CHANGELOG.md +++ b/packages/model/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 7.1.0 + +* Return -1 instead of throwing exception when id is null +* Added `idAsString` to return id or "" if null +* Added `AuditableModel` + ## 7.0.0 * Require Dart >= 2.17 diff --git a/packages/model/README.md b/packages/model/README.md index 1e9b1a61..53e76f48 100644 --- a/packages/model/README.md +++ b/packages/model/README.md @@ -1,14 +1,19 @@ -# Angel3 Basic Data Model +# Angel3 Data Model ![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_model?include_prereleases) [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) [![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) [![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/model/LICENSE) -Angel3 basic data model class, no longer with the added weight of the whole framework. +The basic data models for Angel3 framework. ```dart import 'package:angel3_model/angel3_model.dart'; ``` -This package was created to prevent dependency collisions with third-party packages. +The available data models are: + +* `Model` class + * A basic data model +* `AuditableModel` class + * A basic data model with audit log feature diff --git a/packages/model/lib/angel3_model.dart b/packages/model/lib/angel3_model.dart index 7c64fd0c..0ee8fabf 100644 --- a/packages/model/lib/angel3_model.dart +++ b/packages/model/lib/angel3_model.dart @@ -1,6 +1,4 @@ -//library angel3_model; - -/// Represents arbitrary data, with an associated ID and timestamps. +/// Represents a generic data model with an ID and timestamps. class Model { /// A unique identifier corresponding to this item. String? id; @@ -14,5 +12,24 @@ class Model { Model({this.id, this.createdAt, this.updatedAt}); /// Returns the [id], parsed as an [int]. - int get idAsInt => id != null ? int.tryParse(id!) ?? -1 : -1; + int get idAsInt => id != null ? int.tryParse(id ?? "-1") ?? -1 : -1; + + /// Returns the [id] or "" if null. + String get idAsString => id ?? ""; +} + +/// Represents a generic data model with audit log feature. +class AuditableModel extends Model { + /// The authorized user who created the record. + String? createdBy; + + /// The user who updated the record last time. + String? updatedBy; + + AuditableModel( + {super.id, + super.createdAt, + this.createdBy, + super.updatedAt, + this.updatedBy}); } diff --git a/packages/model/pubspec.yaml b/packages/model/pubspec.yaml index 7dd00448..b7621aca 100644 --- a/packages/model/pubspec.yaml +++ b/packages/model/pubspec.yaml @@ -1,5 +1,5 @@ name: angel3_model -version: 7.0.0 +version: 7.1.0 description: Angel3 basic data model class, no longer with the added weight of the whole framework. homepage: https://angel3-framework.web.app/ repository: https://github.com/dukefirehawk/angel/tree/master/packages/model