user.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. use crate::entities::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,
  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. #[derive(AsChangeset, Identifiable, Default, Debug)]
  28. #[table_name = "user_table"]
  29. pub struct UserTableChangeset {
  30. pub id: String,
  31. pub workspace: Option<String>,
  32. pub name: Option<String>,
  33. pub email: Option<String>,
  34. pub password: Option<String>,
  35. }
  36. impl UserTableChangeset {
  37. pub fn new(params: UpdateUserParams) -> Self {
  38. UserTableChangeset {
  39. id: params.id,
  40. workspace: params.workspace,
  41. name: params.name,
  42. email: params.email,
  43. password: params.password,
  44. }
  45. }
  46. }