common.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package models
  2. import (
  3. "time"
  4. )
  5. // APIResponse represents a standard API response
  6. type APIResponse struct {
  7. Success bool `json:"success"`
  8. Message string `json:"message,omitempty"`
  9. Data interface{} `json:"data,omitempty"`
  10. Error string `json:"error,omitempty"`
  11. }
  12. // LoginRequest represents a login request
  13. type LoginRequest struct {
  14. Email string `json:"email" binding:"required"`
  15. Password string `json:"password" binding:"required"`
  16. }
  17. // LoginResponse represents a login response
  18. type LoginResponse struct {
  19. Token string `json:"token"`
  20. User User `json:"user"`
  21. }
  22. const (
  23. AppStatusBuilding = "building"
  24. AppStatusDeploying = "deploying"
  25. AppStatusReady = "ready"
  26. AppStatusFailed = "failed"
  27. )
  28. type App struct {
  29. ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
  30. UserID uint `json:"user_id" gorm:"not null;index"`
  31. Name string `json:"name" gorm:"not null" validate:"required"`
  32. Description string `json:"description"`
  33. Components string `json:"components" gorm:"type:text"` // JSON array of Component IDs
  34. Status string `json:"status" gorm:"not null;default:'building'"` // e.g., AppStatusBuilding, AppStatusReady, AppStatusFailed
  35. PreviewID uint `json:"preview_id"`
  36. PreviewURL string `json:"preview_url"`
  37. CurrentImageTag string `json:"current_image_tag"`
  38. CurrentImageURI string `json:"current_image_uri"`
  39. ErrorMsg string `json:"error_msg"`
  40. CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
  41. UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
  42. }
  43. // Component represents a deployable component
  44. type Component struct {
  45. ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
  46. UserID uint `json:"user_id" gorm:"not null;index"`
  47. Name string `json:"name" gorm:"not null"`
  48. Description string `json:"description"`
  49. Type string `json:"type" gorm:"not null"` // web, api, database, etc.
  50. Status string `json:"status" gorm:"not null"` // active, inactive, deploying, etc.
  51. ErrorMsg string `json:"error_msg"`
  52. Config string `json:"config" gorm:"type:text"` // JSON configuration
  53. Repository string `json:"repository"` // URL to the git repository
  54. Branch string `json:"branch"`
  55. SourceType string `json:"source_type,omitempty"` // "autodetect", "dockerfile", "docker-compose"
  56. ServiceName string `json:"service_name,omitempty"` // Service name from docker-compose (if applicable)
  57. BuildContext string `json:"build_context,omitempty"` // Build context path for docker-compose services
  58. DockerfilePath string `json:"dockerfile_path,omitempty"` // Dockerfile path relative to build context
  59. CurrentImageTag string `json:"current_image_tag"`
  60. CurrentImageURI string `json:"current_image_uri"`
  61. CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
  62. UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
  63. }
  64. // Deployment represents a deployment instance
  65. type Deployment struct {
  66. ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
  67. AppID uint `json:"app_id" gorm:"not null;index"`
  68. ClientID uint `json:"client_id" gorm:"not null;index"`
  69. Name string `json:"name" gorm:"not null"`
  70. Description string `json:"description"`
  71. Environment string `json:"environment" gorm:"default:'development'"` // dev, staging, prod
  72. Status string `json:"status" gorm:"default:'pending'"` // pending, running, stopped, failed
  73. URL string `json:"url"`
  74. Config string `json:"config" gorm:"type:text;default:'{}'"` // JSON deployment configuration
  75. DeployedAt *time.Time `json:"deployed_at,omitempty"`
  76. CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
  77. UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
  78. }
  79. // Provider represents a cloud provider
  80. type Provider struct {
  81. ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
  82. Name string `json:"name" gorm:"not null"`
  83. Type string `json:"type" gorm:"not null"` // aws, digitalocean, ovh, etc.
  84. Config string `json:"config" gorm:"type:text;default:'{}'"`
  85. Active bool `json:"active" gorm:"default:true"`
  86. CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
  87. UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
  88. }
  89. // TicketStatus defines the possible statuses for a ticket.
  90. const (
  91. TicketStatusOpen = "open"
  92. TicketStatusInProgress = "in_progress"
  93. TicketStatusResolved = "resolved"
  94. TicketStatusClosed = "closed"
  95. )
  96. // TicketPriority defines the possible priorities for a ticket.
  97. const (
  98. TicketPriorityLow = "low"
  99. TicketPriorityMedium = "medium"
  100. TicketPriorityHigh = "high"
  101. TicketPriorityCritical = "critical"
  102. )
  103. // Ticket represents a support ticket
  104. type Ticket struct {
  105. ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
  106. ClientID uint `json:"client_id" gorm:"not null;index"` // Link to Client who reported it
  107. UserID *uint `json:"user_id,omitempty"` // Link to User who reported it (optional)
  108. AssignedTo *uint `json:"assigned_to,omitempty"` // Link to User it is assigned to (optional)
  109. Title string `json:"title" gorm:"not null"`
  110. Description string `json:"description" gorm:"type:text"`
  111. Status string `json:"status" gorm:"default:'open'"` // e.g., open, in_progress, resolved, closed
  112. Priority string `json:"priority" gorm:"default:'medium'"` // e.g., low, medium, high, critical
  113. CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
  114. UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
  115. ResolvedAt *time.Time `json:"resolved_at,omitempty"` // When the ticket was resolved
  116. }
  117. // TicketComment represents a comment on a support ticket
  118. type TicketComment struct {
  119. ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
  120. TicketID uint `json:"ticket_id" gorm:"not null;index"` // Link to the parent Ticket
  121. UserID uint `json:"user_id" gorm:"not null;index"` // Link to User who made the comment
  122. Content string `json:"content" gorm:"type:text;not null"`
  123. CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
  124. UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
  125. }
  126. // Role constants for User
  127. const (
  128. RoleAdmin = "admin"
  129. RoleUser = "user"
  130. RoleEditor = "editor" // Example additional role
  131. )
  132. // User represents a user in the system
  133. type User struct {
  134. ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
  135. Email string `json:"email" gorm:"uniqueIndex;not null" validate:"required,email"`
  136. Password string `json:"-" gorm:"not null"` // Never include password in JSON responses
  137. Name string `json:"name" gorm:"not null" validate:"required"`
  138. Role string `json:"role" gorm:"default:'user'" validate:"required,oneof=user admin editor"`
  139. Active bool `json:"active" gorm:"default:true"`
  140. CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
  141. UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
  142. }
  143. // Client represents a client in the system
  144. type Client struct {
  145. ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
  146. Name string `json:"name" gorm:"not null" validate:"required"`
  147. Description string `json:"description"`
  148. ContactInfo string `json:"contact_info"`
  149. Active bool `json:"active" gorm:"default:true"`
  150. CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
  151. UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
  152. }
  153. // PreviewStatus defines the possible statuses for a preview.
  154. const (
  155. PreviewStatusBuilding = "building"
  156. PreviewStatusDeploying = "deploying"
  157. PreviewStatusRunning = "running"
  158. PreviewStatusFailed = "failed"
  159. PreviewStatusStopped = "stopped"
  160. )
  161. type Preview struct {
  162. ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
  163. AppID uint `json:"app_id" gorm:"not null;index"`
  164. Status string `json:"status" gorm:"not null;default:'building'"` // e.g., PreviewStatusBuilding, PreviewStatusRunning
  165. URL string `json:"url"` // Preview URL (http://vps-ip)
  166. VPSID string `json:"vps_id"` // OVH VPS ID
  167. IPAddress string `json:"ip_address"` // VPS IP address
  168. ErrorMsg string `json:"error_msg"`
  169. BuildLogs string `json:"build_logs" gorm:"type:text"`
  170. DeployLogs string `json:"deploy_logs" gorm:"type:text"`
  171. ExpiresAt time.Time `json:"expires_at" gorm:"not null"` // Auto-cleanup after X hours
  172. CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
  173. UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
  174. }