user.rs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. use crate::entities::{SignInResponse, SignUpResponse, UpdateUserParams};
  2. use flowy_database::schema::user_table;
  3. use flowy_user_infra::entities::UserProfile;
  4. #[derive(Clone, Default, Queryable, Identifiable, Insertable)]
  5. #[table_name = "user_table"]
  6. pub struct UserTable {
  7. pub(crate) id: String,
  8. pub(crate) name: String,
  9. pub(crate) token: String,
  10. pub(crate) email: String,
  11. pub(crate) workspace: String, // deprecated
  12. }
  13. impl UserTable {
  14. pub fn new(id: String, name: String, email: String, token: String) -> Self {
  15. Self {
  16. id,
  17. name,
  18. email,
  19. token,
  20. workspace: "".to_owned(),
  21. }
  22. }
  23. pub fn set_workspace(mut self, workspace: String) -> Self {
  24. self.workspace = workspace;
  25. self
  26. }
  27. }
  28. impl std::convert::From<SignUpResponse> for UserTable {
  29. fn from(resp: SignUpResponse) -> Self { UserTable::new(resp.user_id, resp.name, resp.email, resp.token) }
  30. }
  31. impl std::convert::From<SignInResponse> for UserTable {
  32. fn from(resp: SignInResponse) -> Self { UserTable::new(resp.user_id, resp.name, resp.email, resp.token) }
  33. }
  34. impl std::convert::From<UserTable> for UserProfile {
  35. fn from(table: UserTable) -> Self {
  36. UserProfile {
  37. id: table.id,
  38. email: table.email,
  39. name: table.name,
  40. token: table.token,
  41. }
  42. }
  43. }
  44. #[derive(AsChangeset, Identifiable, Default, Debug)]
  45. #[table_name = "user_table"]
  46. pub struct UserTableChangeset {
  47. pub id: String,
  48. pub workspace: Option<String>, // deprecated
  49. pub name: Option<String>,
  50. pub email: Option<String>,
  51. }
  52. impl UserTableChangeset {
  53. pub fn new(params: UpdateUserParams) -> Self {
  54. UserTableChangeset {
  55. id: params.id,
  56. workspace: None,
  57. name: params.name,
  58. email: params.email,
  59. }
  60. }
  61. }