Improve repo structure (#22)
* app updated * readme updated * rename base folder * update chatty's readme * move apps to packages dir * update repo overview Co-authored-by: diegoveloper <[email protected]>
This commit is contained in:
co-authored by
diegoveloper
parent
bd6bb66279
commit
030c3eb428
@@ -0,0 +1,10 @@
|
||||
enum AuthErrorCode {
|
||||
not_auth,
|
||||
not_chat_user,
|
||||
}
|
||||
|
||||
class AuthException implements Exception {
|
||||
AuthException(this.error);
|
||||
|
||||
final AuthErrorCode error;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class AuthUser {
|
||||
AuthUser(this.id);
|
||||
final String id;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class ChatUser {
|
||||
const ChatUser({this.name, this.image, this.id});
|
||||
final String name;
|
||||
final String image;
|
||||
final String id;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:stream_chatter/data/stream_api_repository.dart';
|
||||
import 'package:stream_chatter/data/upload_storage_repository.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class CreateGroupInput {
|
||||
CreateGroupInput({this.imageFile, this.name, this.members});
|
||||
final File imageFile;
|
||||
final String name;
|
||||
final List<String> members;
|
||||
}
|
||||
|
||||
class CreateGroupUseCase {
|
||||
CreateGroupUseCase(
|
||||
this._streamApiRepository,
|
||||
this._uploadStorageRepository,
|
||||
);
|
||||
|
||||
final UploadStorageRepository _uploadStorageRepository;
|
||||
final StreamApiRepository _streamApiRepository;
|
||||
|
||||
Future<Channel> createGroup(CreateGroupInput input) async {
|
||||
final channelId = Uuid().v4();
|
||||
String image;
|
||||
if (input.imageFile != null) {
|
||||
image = await _uploadStorageRepository.uploadPhoto(input.imageFile, 'channels/$channelId');
|
||||
}
|
||||
final channel = await _streamApiRepository.createGroupChat(
|
||||
channelId,
|
||||
input.name,
|
||||
input.members,
|
||||
image: image,
|
||||
);
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:stream_chatter/data/auth_repository.dart';
|
||||
import 'package:stream_chatter/data/stream_api_repository.dart';
|
||||
import 'package:stream_chatter/domain/exceptions/auth_exception.dart';
|
||||
import 'package:stream_chatter/domain/models/auth_user.dart';
|
||||
|
||||
class LoginUseCase {
|
||||
LoginUseCase(this.authRepository, this.streamApiRepository);
|
||||
|
||||
final AuthRepository authRepository;
|
||||
final StreamApiRepository streamApiRepository;
|
||||
|
||||
Future<bool> validateLogin() async {
|
||||
print('validateLogin');
|
||||
final user = await authRepository.getAuthUser();
|
||||
print('user: ${user?.id}');
|
||||
if (user != null) {
|
||||
final result = await streamApiRepository.connectIfExist(user.id);
|
||||
if (result) {
|
||||
return true;
|
||||
} else {
|
||||
throw AuthException(AuthErrorCode.not_chat_user);
|
||||
}
|
||||
}
|
||||
throw AuthException(AuthErrorCode.not_auth);
|
||||
}
|
||||
|
||||
Future<AuthUser> signIn() async {
|
||||
return await authRepository.signIn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import 'package:stream_chatter/data/auth_repository.dart';
|
||||
import 'package:stream_chatter/data/stream_api_repository.dart';
|
||||
|
||||
class LogoutUseCase {
|
||||
LogoutUseCase(this.streamApiRepository, this.authRepository);
|
||||
final StreamApiRepository streamApiRepository;
|
||||
final AuthRepository authRepository;
|
||||
|
||||
Future<void> logout() async {
|
||||
await streamApiRepository.logout();
|
||||
await authRepository.logout();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:stream_chatter/data/auth_repository.dart';
|
||||
import 'package:stream_chatter/data/stream_api_repository.dart';
|
||||
import 'package:stream_chatter/data/upload_storage_repository.dart';
|
||||
import 'package:stream_chatter/domain/models/chat_user.dart';
|
||||
|
||||
class ProfileInput {
|
||||
ProfileInput({this.imageFile, this.name});
|
||||
final File imageFile;
|
||||
final String name;
|
||||
}
|
||||
|
||||
class ProfileSignInUseCase {
|
||||
ProfileSignInUseCase(
|
||||
this._authRepository,
|
||||
this._streamApiRepository,
|
||||
this._uploadStorageRepository,
|
||||
);
|
||||
|
||||
final AuthRepository _authRepository;
|
||||
final UploadStorageRepository _uploadStorageRepository;
|
||||
final StreamApiRepository _streamApiRepository;
|
||||
|
||||
Future<void> verify(ProfileInput input) async {
|
||||
final auth = await _authRepository.getAuthUser();
|
||||
final token = await _streamApiRepository.getToken(auth.id);
|
||||
String image;
|
||||
if (input.imageFile != null) {
|
||||
image = await _uploadStorageRepository.uploadPhoto(input.imageFile, 'users/${auth.id}');
|
||||
}
|
||||
await _streamApiRepository.connectUser(ChatUser(name: input.name, id: auth.id, image: image), token);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user