refactor user repo with helpers. better api validation etc.

This commit is contained in:
2025-01-01 19:58:19 +00:00
parent 8559b1c44e
commit 4d52186d21
23 changed files with 1802 additions and 237 deletions
@@ -0,0 +1,6 @@
import 'package:backend_dart/domain/data/user_data_source.dart';
abstract class IDatabase {
UserDataSource get users;
Future<void> close();
}
@@ -0,0 +1,34 @@
import 'package:backend_dart/domain/entities/project.dart';
/// Interface for managing project data interactions.
abstract class ProjectDataSource {
/// Creates a new project in the data source.
///
/// Throws an error if the creation fails.
Future<void> createProject(NewProject project);
/// Retrieves a project by its unique ID.
///
/// Returns `null` if no project is found.
Future<Project?> findProjectById(String id);
/// Retrieves all projects associated with a specific user.
///
/// Returns an empty list if no projects are found.
Future<List<Project>> findProjectsByUserId(String userId);
/// Updates an existing project in the data source.
///
/// Throws an error if the update fails.
Future<void> updateProject(ProjectUpdate project);
/// Deletes a project by its unique ID.
///
/// Throws an error if the deletion fails.
Future<void> deleteProject(String id);
/// Retrieves all projects in the data source.
///
/// Returns an empty list if no projects exist.
Future<List<Project>> findAllProjects();
}
@@ -1,18 +1,19 @@
import 'package:backend_dart/domain/entities/user.dart';
import 'package:backend_dart/domain/interface/error.dart';
import 'package:fpdart/fpdart.dart';
abstract class UserDataSource<T> {
TaskEither<IError, T> create(T user);
abstract class UserDataSource {
TaskEither<IError, User> create(UserCreate user);
TaskEither<IError, T> findByEmail(String email);
TaskEither<IError, User> findByEmail(String email);
TaskEither<IError, T> findById(String id);
TaskEither<IError, User> findById(String id);
TaskEither<IError, T> update(T user);
TaskEither<IError, User> update(UserUpdate user);
TaskEither<IError, void> delete(String id);
TaskEither<IError, List<T>> findAll();
TaskEither<IError, List<User>> findAll();
TaskEither<IError,String> generateId();
TaskEither<IError, String> generateId();
}