-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add use case refactor model and abstract query parameter
- Loading branch information
Showing
17 changed files
with
282 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
abstract class QueryParameter<T> { | ||
final String queryName; | ||
final T queryValue; | ||
|
||
QueryParameter(this.queryName, this.queryValue); | ||
} | ||
|
||
class BooleanQueryParameter extends QueryParameter<bool> { | ||
BooleanQueryParameter(String queryName, bool queryValue) : super(queryName, queryValue); | ||
} | ||
|
||
class StringQueryParameter extends QueryParameter<String> { | ||
StringQueryParameter(String queryName, String queryValue) : super(queryName, queryValue); | ||
} | ||
|
||
class IntQueryParameter extends QueryParameter<int> { | ||
IntQueryParameter(String queryName, int queryValue) : super(queryName, queryValue); | ||
} | ||
|
||
extension ListQueryParameterExtension on List<QueryParameter?> { | ||
Map<String, dynamic> toMap() => { for (var data in this) if (data != null) data.queryName : data.queryValue }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:twake/core/state/failure.dart'; | ||
import 'package:twake/core/state/success.dart'; | ||
|
||
@immutable | ||
abstract class AppState with EquatableMixin { | ||
final Either<Failure, Success> viewState; | ||
|
||
AppState(this.viewState); | ||
|
||
@override | ||
List<Object?> get props => [viewState]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
abstract class Failure extends Equatable {} | ||
|
||
abstract class FeatureFailure extends Failure {} | ||
|
||
class ExceptionFailure extends Failure { | ||
final dynamic exception; | ||
|
||
ExceptionFailure(this.exception); | ||
|
||
@override | ||
List<Object?> get props => [ | ||
exception, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
abstract class Success with EquatableMixin {} | ||
|
||
abstract class ViewState extends Success {} | ||
|
||
abstract class ViewEvent extends Success {} | ||
|
||
class UIState extends ViewState { | ||
static final idle = UIState(); | ||
|
||
UIState() : super(); | ||
|
||
@override | ||
List<Object?> get props => []; | ||
} | ||
|
||
class SuccessUIState<T> extends ViewState { | ||
final T result; | ||
|
||
SuccessUIState(this.result) : super(); | ||
|
||
@override | ||
List<Object?> get props => [ | ||
result, | ||
]; | ||
} | ||
|
||
class LoadingState extends UIState { | ||
LoadingState(); | ||
|
||
@override | ||
List<Object?> get props => []; | ||
} | ||
|
||
class LoadingMoreState extends UIState { | ||
LoadingMoreState(); | ||
|
||
@override | ||
List<Object?> get props => []; | ||
} | ||
|
||
class RefreshingState extends UIState { | ||
RefreshingState(); | ||
|
||
@override | ||
List<Object?> get props => []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 9 additions & 10 deletions
19
lib/features/message/data/model/message/response/message.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ class Reaction { | |
|
||
final List<String> users; | ||
|
||
int count; | ||
final int count; | ||
|
||
Reaction({ | ||
required this.name, | ||
|
29 changes: 29 additions & 0 deletions
29
lib/features/message/domain/usecases/fetch_message_usecase.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:twake/core/state/failure.dart'; | ||
import 'package:twake/features/message/data/model/message/response/message.dart'; | ||
import 'package:twake/features/message/domain/repository/message_repository.dart'; | ||
|
||
class FetchMessageUseCase { | ||
final MessageRepository _messageRepository; | ||
|
||
FetchMessageUseCase( | ||
this._messageRepository, | ||
); | ||
|
||
Either<ExceptionFailure, Stream<List<Message>>> execute({ String? companyId, | ||
String? workspaceId, | ||
required String channelId, | ||
String? threadId, | ||
bool? withExistedFiles = false,}) { | ||
try { | ||
final stream = _messageRepository.fetch( | ||
channelId: channelId, | ||
threadId: threadId, | ||
workspaceId: workspaceId, | ||
); | ||
return Right<ExceptionFailure, Stream<List<Message>>>(stream); | ||
} catch (e) { | ||
return Left<ExceptionFailure, Stream<List<Message>>>(ExceptionFailure(e)); | ||
} | ||
} | ||
} |
Oops, something went wrong.