mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-07-24 17:42:16 +00:00

* refactor: rename structs * chore: read database id from view * chore: fix open database error because of create a database view for database id * chore: fix tests * chore: rename datbase id to view id in flutter * refactor: move grid and board to database view folder * refactor: rename functions * refactor: move calender to datbase view folder * refactor: rename app_flowy to appflowy_flutter * chore: reanming * chore: fix freeze gen * chore: remove todos * refactor: view process events * chore: add link database test * chore: just open view if there is opened database
99 lines
2.5 KiB
Dart
99 lines
2.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:dartz/dartz.dart';
|
|
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/user_profile.pb.dart';
|
|
|
|
class UserBackendService {
|
|
UserBackendService({
|
|
required this.userId,
|
|
});
|
|
|
|
final String userId;
|
|
|
|
static Future<Either<UserProfilePB, FlowyError>> getCurrentUserProfile() {
|
|
return UserEventGetUserProfile().send();
|
|
}
|
|
|
|
Future<Either<Unit, FlowyError>> updateUserProfile({
|
|
String? name,
|
|
String? password,
|
|
String? email,
|
|
String? iconUrl,
|
|
String? openAIKey,
|
|
}) {
|
|
var 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;
|
|
}
|
|
|
|
return UserEventUpdateUserProfile(payload).send();
|
|
}
|
|
|
|
Future<Either<Unit, FlowyError>> deleteWorkspace(
|
|
{required String workspaceId}) {
|
|
throw UnimplementedError();
|
|
}
|
|
|
|
Future<Either<Unit, FlowyError>> signOut() {
|
|
return UserEventSignOut().send();
|
|
}
|
|
|
|
Future<Either<Unit, FlowyError>> initUser() async {
|
|
return UserEventInitUser().send();
|
|
}
|
|
|
|
Future<Either<List<WorkspacePB>, FlowyError>> getWorkspaces() {
|
|
final request = WorkspaceIdPB.create();
|
|
|
|
return FolderEventReadWorkspaces(request).send().then((result) {
|
|
return result.fold(
|
|
(workspaces) => left(workspaces.items),
|
|
(error) => right(error),
|
|
);
|
|
});
|
|
}
|
|
|
|
Future<Either<WorkspacePB, FlowyError>> openWorkspace(String workspaceId) {
|
|
final request = WorkspaceIdPB.create()..value = workspaceId;
|
|
return FolderEventOpenWorkspace(request).send().then((result) {
|
|
return result.fold(
|
|
(workspace) => left(workspace),
|
|
(error) => right(error),
|
|
);
|
|
});
|
|
}
|
|
|
|
Future<Either<WorkspacePB, FlowyError>> createWorkspace(
|
|
String name, String desc) {
|
|
final request = CreateWorkspacePayloadPB.create()
|
|
..name = name
|
|
..desc = desc;
|
|
return FolderEventCreateWorkspace(request).send().then((result) {
|
|
return result.fold(
|
|
(workspace) => left(workspace),
|
|
(error) => right(error),
|
|
);
|
|
});
|
|
}
|
|
}
|