Codenic Clean Architecture
  • Introduction
  • The Clean Architecture
    • Presentation Layer
    • Domain Layer
    • Infrastructure Layer
  • Tutorial
    • Overview
    • Creating a Flutter Modular Project
      • Tips for Managing a Modular Project
    • Implementing the Domain Layer
      • Core Dependencies
      • Creating an Entity
      • Creating a Failure
      • Creating a Repository Interface
      • Creating Use Cases
        • CRUD Operations (Runner)
        • Data Streams (Watcher)
    • Implementing the Infrastructure Layer
      • External Dependencies
      • Creating a Data Model
      • Creating a Data Source
      • Implementing a Repository
    • Implementing the Presentation Layer
      • External Dependencies
      • Dependency Injection and Service Locator
      • Widgets
        • Snackbar Handler
        • Global Blocs Widget
        • Note Widgets
  • Packages
    • Codenic Bloc Use Case
      • Runner
      • Watcher
    • Codenic Logger
      • Usage
      • Example
      • Modifying the Logger
      • Integrating Firebase Crashlytics to the logger
    • Codenic Exception Converter
      • Failure Object
      • Exception Converter
      • Exception Converter Suite
      • Example
Powered by GitBook
On this page
  1. Tutorial
  2. Implementing the Domain Layer

Creating a Repository Interface

PreviousCreating a FailureNextCreating Use Cases

Last updated 2 years ago

Once the and have been created, we can proceed with the creation of the which defines the functionalities of the note feature without providing any implementation details.

All repository methods must abide by these rules :

  • A repository method must always return an Either monad A repository method always returns an object which can denote a Left or Right value. If the method fails, then a Failure object (Left Value) will be returned. If the method succeeds, then a null, primitive object, or an Entity (Right Value) will be returned.

  • A stream return type must be wrapped by a VerboseStream A is a stream wrapper (from the ) which enables us to convert any exceptions into Failure objects.

In the note_app/modules/domain/lib/note/repository_interfaces/ directory, create the note_repository.dart file:

import 'dart:async';

import 'package:codenic_bloc_use_case/codenic_bloc_use_case.dart';
import 'package:codenic_exception_converter/codenic_exception_converter.dart';
import 'package:domain/note/entities/note_entry.dart';
import 'package:domain/note/failures/note_content_too_long_failure.dart';
import 'package:domain/note/failures/note_title_too_long_failure.dart';

/// {@template NoteRepository}
/// A repository for managing [NoteEntry]s.
/// {@endtemplate}
abstract class NoteRepository {
  /// {@macro NoteRepository}
  const NoteRepository();

  /// Creates a new [NoteEntry] initialized the given [title] and [content].
  ///
  /// A [Failure] may be thrown:
  /// - [NoteContentTooLongFailure]
  /// - [NoteTitleTooLongFailure]
  FutureOr<Either<Failure, void>> createNoteEntry({
    String? title,
    String? content,
  });

  /// Updates the [NoteEntry] referenced by the given [id].
  ///
  /// A [Failure] may be thrown:
  /// - [NoteContentTooLongFailure]
  /// - [NoteTitleTooLongFailure]
  FutureOr<Either<Failure, void>> updateNoteEntry({
    required String id,
    String? title,
    String? content,
  });

  /// Deletes an existing [NoteEntry] with the given [id].
  FutureOr<Either<Failure, void>> deleteNoteEntry({required String id});

  /// Fetches a collection of [NoteEntry]s.
  ///
  /// The [limit] parameter can be used to limit the number of entries.
  /// The [pageToken] parameter can be used to fetch a specific page of entries.
  FutureOr<Either<Failure, List<NoteEntry>>> fetchNoteEntries({
    int? limit,
    dynamic pageToken,
  });

  /// Streams a collection of [NoteEntry]s.
  ///
  /// The [limit] parameter can be used to limit the number of entries.
  ///
  /// A [VerboseStream] is a [Stream] wrapper which gives it an error
  /// handler for converting [Exception]s into [Failure]s before it gets
  /// emitted
  FutureOr<Either<Failure, VerboseStream<Failure, List<NoteEntry>>>>
      watchNoteEntries({int? limit});
}
Entities
Failures
Either
VerboseStream
codenic_bloc_use_case package
Note Repository