common.go 7.4 KB

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