1
0

models.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package models
  2. import (
  3. "time"
  4. )
  5. // User is an agent‑or‑human account that can call ERP tools.
  6. type User struct {
  7. ID uint `gorm:"primaryKey"`
  8. Email string `gorm:"size:255;not null;uniqueIndex"`
  9. Password string `gorm:"size:255;not null"` // hashed password or credential reference
  10. Roles []Role `gorm:"many2many:user_roles;"`
  11. CreatedAt time.Time
  12. UpdatedAt time.Time
  13. }
  14. // Note represents a note belonging to a user and is associated with a Service.
  15. type Note struct {
  16. ID uint `gorm:"primaryKey"`
  17. Title string `gorm:"size:200;not null"` // title of the note
  18. Content string `gorm:"type:text;not null"` // content body
  19. // Associations
  20. UserID uint
  21. User User `gorm:"foreignKey:UserID"`
  22. ServiceID uint
  23. Service Service `gorm:"foreignKey:ServiceID"`
  24. CreatedAt time.Time
  25. UpdatedAt time.Time
  26. }
  27. // Role groups permissions that can be assigned to users or agents.
  28. type Role struct {
  29. ID uint `gorm:"primaryKey"`
  30. Name string `gorm:"size:100;not null;uniqueIndex"`
  31. Description string `gorm:"size:255"`
  32. Permissions []Permission `gorm:"many2many:role_permissions;"`
  33. }
  34. // Permission is a fine‑grained action that can be allowed/denied.
  35. type Permission struct {
  36. ID uint `gorm:"primaryKey"`
  37. Code string `gorm:"size:100;not null;uniqueIndex"` // e.g. "invoice:create"
  38. Description string `gorm:"size:255"`
  39. }
  40. // Service & related entities (agents coordinate work around Services)
  41. type Service struct {
  42. ID uint `gorm:"primaryKey"`
  43. Name string `gorm:"size:200;not null"` // human‑readable Service name
  44. Description string `gorm:"type:text"`
  45. // Owner/creator of the Service
  46. CreatedByID uint
  47. CreatedBy User `gorm:"foreignKey:CreatedByID"`
  48. // Participants – many‑to‑many (agents & humans)
  49. Participants []User `gorm:"many2many:Service_participants;"`
  50. // Service tasks
  51. Tasks []Task `gorm:"foreignKey:ServiceID"`
  52. CreatedAt time.Time
  53. UpdatedAt time.Time
  54. }
  55. // Task management (assignable work items)
  56. type Task struct {
  57. ID uint `gorm:"primaryKey"`
  58. Title string `gorm:"size:200;not null"`
  59. Content string `gorm:"type:text;not null"`
  60. // Which service the task belongs to
  61. ServiceID *uint
  62. Service *Service `gorm:"foreignKey:ServiceID"`
  63. // Who created the task
  64. CreatedByID uint
  65. CreatedBy User `gorm:"foreignKey:CreatedByID"`
  66. // Who updated the task
  67. UpdatedByID uint
  68. UpdatedBy User `gorm:"foreignKey:UpdatedByID"`
  69. // Assignment – can be nil (unassigned) or point to a user/agent
  70. AssigneeID *uint
  71. Assignee *User `gorm:"foreignKey:AssigneeID"`
  72. StatusID uint // FK to TaskStatus
  73. Status TaskStatus `gorm:"foreignKey:StatusID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
  74. DueDate *time.Time
  75. Priority string `gorm:"size:20"` // e.g. low/medium/high
  76. CreatedAt time.Time
  77. UpdatedAt time.Time
  78. }
  79. // Separate table for task status – makes it easy to add custom workflow steps.
  80. type TaskStatus struct {
  81. ID uint `gorm:"primaryKey"`
  82. Code string `gorm:"size:50;not null;uniqueIndex"` // e.g. "open", "in_progress", "done"
  83. Label string `gorm:"size:100"` // human‑readable label
  84. // Reverse relation (optional)
  85. Tasks []Task `gorm:"foreignKey:StatusID"`
  86. CreatedAt time.Time
  87. UpdatedAt time.Time
  88. }
  89. // Message sent inside a conversation.
  90. type Message struct {
  91. ID uint `gorm:"primaryKey"`
  92. SenderID uint `gorm:"index;not null"` // user/agent that authored the message
  93. Sender User `gorm:"foreignKey:SenderID"`
  94. Content string `gorm:"type:text;not null"`
  95. SentAt time.Time `gorm:"autoCreateTime"`
  96. // Receivers – many‑to‑many (users who should receive this message)
  97. Receivers []User `gorm:"many2many:message_receivers;"`
  98. CreatedAt time.Time
  99. UpdatedAt time.Time
  100. }