user_model.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package common
  2. import (
  3. "time"
  4. "github.com/google/uuid"
  5. )
  6. type User struct {
  7. ID uuid.UUID `gorm:"type:uuid;primary_key" json:"id"`
  8. Email string `gorm:"unique;size:255" json:"email"`
  9. Name string `gorm:"size:255" json:"name"`
  10. PhoneNumber string `gorm:"size:50" json:"phone_number"`
  11. Password string `gorm:"size:255" json:"-"`
  12. PasswordCreated bool `gorm:"default:false" json:"password_created"`
  13. PasswordCreatedAt time.Time
  14. Role string `gorm:"size:50;default:member"`
  15. Status string `gorm:"size:50;default:active"`
  16. InvitedBy uuid.UUID `gorm:"type:uuid"`
  17. CreatedAt time.Time
  18. UpdatedAt time.Time
  19. Workspaces []Workspace `gorm:"many2many:user_workspace_roles;"`
  20. }
  21. type UserMe struct {
  22. User User `json:"user"`
  23. Workspaces []Workspace `json:"workspaces"`
  24. }
  25. // Invite represents an invitation to join the system.
  26. type Invite struct {
  27. ID uuid.UUID `gorm:"type:uuid;primary_key" json:"id"`
  28. Email string `gorm:"size:255" json:"email"`
  29. WorkspaceID uuid.UUID `gorm:"size:255" json:"workspace_id"`
  30. Role string `gorm:"size:50;default:member" json:"role"`
  31. Token string `gorm:"unique;size:255" json:"token"`
  32. Status string `gorm:"size:50;default:pending" json:"status"`
  33. ExpiresAt time.Time `json:"expires_at"`
  34. CreatedAt time.Time `json:"created_at"`
  35. UpdatedAt time.Time `json:"updated_at"`
  36. }
  37. type UserWorkspaceRole struct {
  38. UserID uuid.UUID `gorm:"primaryKey;type:uuid"`
  39. WorkspaceID uuid.UUID `gorm:"primaryKey;type:uuid"`
  40. Role string `gorm:"size:50;default:member"`
  41. CreatedAt time.Time
  42. UpdatedAt time.Time
  43. // Optional: Add these if you want GORM to handle the relationships
  44. User User `gorm:"foreignKey:UserID"`
  45. Workspace Workspace `gorm:"foreignKey:WorkspaceID"`
  46. }
  47. type CreateOwnerResponse struct {
  48. User User `json:"user"`
  49. Token string `json:"token"`
  50. }
  51. type InitWorkspaceOwnerRequest struct {
  52. Email string `json:"email"`
  53. Name string `json:"name"`
  54. Phone string `json:"phone_number"`
  55. }
  56. type CreateInvitedUserRequest struct {
  57. Email string `json:"email"`
  58. Name string `json:"name"`
  59. PhoneNumber string `json:"phone_number"`
  60. Password string `json:"password"`
  61. Token string `json:"token"`
  62. }
  63. type CreateInvitedUserResponse struct {
  64. User User `json:"user"`
  65. Worspace string `json:"workspace_id"`
  66. }
  67. type InviteUserRequest struct {
  68. Email string `json:"email"`
  69. Workspace string `json:"workspace_id"`
  70. Role string `json:"role"`
  71. }
  72. type ValidateInvitedUserRequest struct {
  73. Valid bool `json:"valid"`
  74. WorkspaceID string `json:"workspace_id"`
  75. Email string `json:"email"`
  76. Error string `json:"error"`
  77. }