mirror of
				https://github.com/AppFlowy-IO/AppFlowy.git
				synced 2025-10-31 10:03:18 +00:00 
			
		
		
		
	 bf70be1841
			
		
	
	
		bf70be1841
		
			
		
	
	
	
	
		
			
			* feat: add icon field * fix: add sqlx migration files * chore: fix tst * chore: fix duplicate event name * chore: update to lastest stable rust toolchain * chore: use 1.75 channel * chore: fix duplicate event name * chore: fix duplicate event name * chore: use more reliable assertion --------- Co-authored-by: nathan <nathan@appflowy.io>
		
			
				
	
	
		
			154 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			154 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'dart:async';
 | |
| 
 | |
| import 'package:appflowy_backend/dispatch/dispatch.dart';
 | |
| import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
 | |
| import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';
 | |
| import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
 | |
| import 'package:appflowy_result/appflowy_result.dart';
 | |
| import 'package:fixnum/fixnum.dart';
 | |
| 
 | |
| class UserBackendService {
 | |
|   UserBackendService({
 | |
|     required this.userId,
 | |
|   });
 | |
| 
 | |
|   final Int64 userId;
 | |
| 
 | |
|   static Future<FlowyResult<UserProfilePB, FlowyError>>
 | |
|       getCurrentUserProfile() async {
 | |
|     final result = await UserEventGetUserProfile().send();
 | |
|     return result;
 | |
|   }
 | |
| 
 | |
|   Future<FlowyResult<void, FlowyError>> updateUserProfile({
 | |
|     String? name,
 | |
|     String? password,
 | |
|     String? email,
 | |
|     String? iconUrl,
 | |
|     String? openAIKey,
 | |
|     String? stabilityAiKey,
 | |
|   }) {
 | |
|     final payload = UpdateUserProfilePayloadPB.create()..id = userId;
 | |
| 
 | |
|     if (name != null) {
 | |
|       payload.name = name;
 | |
|     }
 | |
| 
 | |
|     if (password != null) {
 | |
|       payload.password = password;
 | |
|     }
 | |
| 
 | |
|     if (email != null) {
 | |
|       payload.email = email;
 | |
|     }
 | |
| 
 | |
|     if (iconUrl != null) {
 | |
|       payload.iconUrl = iconUrl;
 | |
|     }
 | |
| 
 | |
|     if (openAIKey != null) {
 | |
|       payload.openaiKey = openAIKey;
 | |
|     }
 | |
| 
 | |
|     if (stabilityAiKey != null) {
 | |
|       payload.stabilityAiKey = stabilityAiKey;
 | |
|     }
 | |
| 
 | |
|     return UserEventUpdateUserProfile(payload).send();
 | |
|   }
 | |
| 
 | |
|   Future<FlowyResult<void, FlowyError>> deleteWorkspace({
 | |
|     required String workspaceId,
 | |
|   }) {
 | |
|     throw UnimplementedError();
 | |
|   }
 | |
| 
 | |
|   static Future<FlowyResult<void, FlowyError>> signOut() {
 | |
|     return UserEventSignOut().send();
 | |
|   }
 | |
| 
 | |
|   Future<FlowyResult<void, FlowyError>> initUser() async {
 | |
|     return UserEventInitUser().send();
 | |
|   }
 | |
| 
 | |
|   static Future<FlowyResult<UserProfilePB, FlowyError>> getAnonUser() async {
 | |
|     return UserEventGetAnonUser().send();
 | |
|   }
 | |
| 
 | |
|   static Future<FlowyResult<void, FlowyError>> openAnonUser() async {
 | |
|     return UserEventOpenAnonUser().send();
 | |
|   }
 | |
| 
 | |
|   Future<FlowyResult<List<UserWorkspacePB>, FlowyError>> getWorkspaces() {
 | |
|     return UserEventGetAllWorkspace().send().then((value) {
 | |
|       return value.fold(
 | |
|         (workspaces) => FlowyResult.success(workspaces.items),
 | |
|         (error) => FlowyResult.failure(error),
 | |
|       );
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   Future<FlowyResult<void, FlowyError>> openWorkspace(String workspaceId) {
 | |
|     final payload = UserWorkspaceIdPB.create()..workspaceId = workspaceId;
 | |
|     return UserEventOpenWorkspace(payload).send();
 | |
|   }
 | |
| 
 | |
|   Future<FlowyResult<WorkspacePB, FlowyError>> getCurrentWorkspace() {
 | |
|     return FolderEventReadCurrentWorkspace().send().then((result) {
 | |
|       return result.fold(
 | |
|         (workspace) => FlowyResult.success(workspace),
 | |
|         (error) => FlowyResult.failure(error),
 | |
|       );
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   Future<FlowyResult<WorkspacePB, FlowyError>> createWorkspace(
 | |
|     String name,
 | |
|     String desc,
 | |
|   ) {
 | |
|     final request = CreateWorkspacePayloadPB.create()
 | |
|       ..name = name
 | |
|       ..desc = desc;
 | |
|     return FolderEventCreateFolderWorkspace(request).send().then((result) {
 | |
|       return result.fold(
 | |
|         (workspace) => FlowyResult.success(workspace),
 | |
|         (error) => FlowyResult.failure(error),
 | |
|       );
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   Future<FlowyResult<UserWorkspacePB, FlowyError>> createUserWorkspace(
 | |
|     String name,
 | |
|   ) {
 | |
|     final request = CreateWorkspacePB.create()..name = name;
 | |
|     return UserEventCreateWorkspace(request).send();
 | |
|   }
 | |
| 
 | |
|   Future<FlowyResult<void, FlowyError>> deleteWorkspaceById(
 | |
|     String workspaceId,
 | |
|   ) {
 | |
|     final request = UserWorkspaceIdPB.create()..workspaceId = workspaceId;
 | |
|     return UserEventDeleteWorkspace(request).send();
 | |
|   }
 | |
| 
 | |
|   Future<FlowyResult<void, FlowyError>> renameWorkspace(
 | |
|     String workspaceId,
 | |
|     String name,
 | |
|   ) {
 | |
|     final request = RenameWorkspacePB()
 | |
|       ..workspaceId = workspaceId
 | |
|       ..newName = name;
 | |
|     return UserEventRenameWorkspace(request).send();
 | |
|   }
 | |
| 
 | |
|   Future<FlowyResult<void, FlowyError>> updateWorkspaceIcon(
 | |
|     String workspaceId,
 | |
|     String icon,
 | |
|   ) {
 | |
|     final request = ChangeWorkspaceIconPB()
 | |
|       ..workspaceId = workspaceId
 | |
|       ..newIcon = icon;
 | |
|     return UserEventChangeWorkspaceIcon(request).send();
 | |
|   }
 | |
| }
 |