user.rs 1.7 KB

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