announcement.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. "github.com/Wei-Shaw/sub2api/ent/announcement"
  11. "github.com/Wei-Shaw/sub2api/internal/domain"
  12. )
  13. // Announcement is the model entity for the Announcement schema.
  14. type Announcement struct {
  15. config `json:"-"`
  16. // ID of the ent.
  17. ID int64 `json:"id,omitempty"`
  18. // 公告标题
  19. Title string `json:"title,omitempty"`
  20. // 公告内容(支持 Markdown)
  21. Content string `json:"content,omitempty"`
  22. // 状态: draft, active, archived
  23. Status string `json:"status,omitempty"`
  24. // 通知模式: silent(仅铃铛), popup(弹窗提醒)
  25. NotifyMode string `json:"notify_mode,omitempty"`
  26. // 展示条件(JSON 规则)
  27. Targeting domain.AnnouncementTargeting `json:"targeting,omitempty"`
  28. // 开始展示时间(为空表示立即生效)
  29. StartsAt *time.Time `json:"starts_at,omitempty"`
  30. // 结束展示时间(为空表示永久生效)
  31. EndsAt *time.Time `json:"ends_at,omitempty"`
  32. // 创建人用户ID(管理员)
  33. CreatedBy *int64 `json:"created_by,omitempty"`
  34. // 更新人用户ID(管理员)
  35. UpdatedBy *int64 `json:"updated_by,omitempty"`
  36. // CreatedAt holds the value of the "created_at" field.
  37. CreatedAt time.Time `json:"created_at,omitempty"`
  38. // UpdatedAt holds the value of the "updated_at" field.
  39. UpdatedAt time.Time `json:"updated_at,omitempty"`
  40. // Edges holds the relations/edges for other nodes in the graph.
  41. // The values are being populated by the AnnouncementQuery when eager-loading is set.
  42. Edges AnnouncementEdges `json:"edges"`
  43. selectValues sql.SelectValues
  44. }
  45. // AnnouncementEdges holds the relations/edges for other nodes in the graph.
  46. type AnnouncementEdges struct {
  47. // Reads holds the value of the reads edge.
  48. Reads []*AnnouncementRead `json:"reads,omitempty"`
  49. // loadedTypes holds the information for reporting if a
  50. // type was loaded (or requested) in eager-loading or not.
  51. loadedTypes [1]bool
  52. }
  53. // ReadsOrErr returns the Reads value or an error if the edge
  54. // was not loaded in eager-loading.
  55. func (e AnnouncementEdges) ReadsOrErr() ([]*AnnouncementRead, error) {
  56. if e.loadedTypes[0] {
  57. return e.Reads, nil
  58. }
  59. return nil, &NotLoadedError{edge: "reads"}
  60. }
  61. // scanValues returns the types for scanning values from sql.Rows.
  62. func (*Announcement) scanValues(columns []string) ([]any, error) {
  63. values := make([]any, len(columns))
  64. for i := range columns {
  65. switch columns[i] {
  66. case announcement.FieldTargeting:
  67. values[i] = new([]byte)
  68. case announcement.FieldID, announcement.FieldCreatedBy, announcement.FieldUpdatedBy:
  69. values[i] = new(sql.NullInt64)
  70. case announcement.FieldTitle, announcement.FieldContent, announcement.FieldStatus, announcement.FieldNotifyMode:
  71. values[i] = new(sql.NullString)
  72. case announcement.FieldStartsAt, announcement.FieldEndsAt, announcement.FieldCreatedAt, announcement.FieldUpdatedAt:
  73. values[i] = new(sql.NullTime)
  74. default:
  75. values[i] = new(sql.UnknownType)
  76. }
  77. }
  78. return values, nil
  79. }
  80. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  81. // to the Announcement fields.
  82. func (_m *Announcement) assignValues(columns []string, values []any) error {
  83. if m, n := len(values), len(columns); m < n {
  84. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  85. }
  86. for i := range columns {
  87. switch columns[i] {
  88. case announcement.FieldID:
  89. value, ok := values[i].(*sql.NullInt64)
  90. if !ok {
  91. return fmt.Errorf("unexpected type %T for field id", value)
  92. }
  93. _m.ID = int64(value.Int64)
  94. case announcement.FieldTitle:
  95. if value, ok := values[i].(*sql.NullString); !ok {
  96. return fmt.Errorf("unexpected type %T for field title", values[i])
  97. } else if value.Valid {
  98. _m.Title = value.String
  99. }
  100. case announcement.FieldContent:
  101. if value, ok := values[i].(*sql.NullString); !ok {
  102. return fmt.Errorf("unexpected type %T for field content", values[i])
  103. } else if value.Valid {
  104. _m.Content = value.String
  105. }
  106. case announcement.FieldStatus:
  107. if value, ok := values[i].(*sql.NullString); !ok {
  108. return fmt.Errorf("unexpected type %T for field status", values[i])
  109. } else if value.Valid {
  110. _m.Status = value.String
  111. }
  112. case announcement.FieldNotifyMode:
  113. if value, ok := values[i].(*sql.NullString); !ok {
  114. return fmt.Errorf("unexpected type %T for field notify_mode", values[i])
  115. } else if value.Valid {
  116. _m.NotifyMode = value.String
  117. }
  118. case announcement.FieldTargeting:
  119. if value, ok := values[i].(*[]byte); !ok {
  120. return fmt.Errorf("unexpected type %T for field targeting", values[i])
  121. } else if value != nil && len(*value) > 0 {
  122. if err := json.Unmarshal(*value, &_m.Targeting); err != nil {
  123. return fmt.Errorf("unmarshal field targeting: %w", err)
  124. }
  125. }
  126. case announcement.FieldStartsAt:
  127. if value, ok := values[i].(*sql.NullTime); !ok {
  128. return fmt.Errorf("unexpected type %T for field starts_at", values[i])
  129. } else if value.Valid {
  130. _m.StartsAt = new(time.Time)
  131. *_m.StartsAt = value.Time
  132. }
  133. case announcement.FieldEndsAt:
  134. if value, ok := values[i].(*sql.NullTime); !ok {
  135. return fmt.Errorf("unexpected type %T for field ends_at", values[i])
  136. } else if value.Valid {
  137. _m.EndsAt = new(time.Time)
  138. *_m.EndsAt = value.Time
  139. }
  140. case announcement.FieldCreatedBy:
  141. if value, ok := values[i].(*sql.NullInt64); !ok {
  142. return fmt.Errorf("unexpected type %T for field created_by", values[i])
  143. } else if value.Valid {
  144. _m.CreatedBy = new(int64)
  145. *_m.CreatedBy = value.Int64
  146. }
  147. case announcement.FieldUpdatedBy:
  148. if value, ok := values[i].(*sql.NullInt64); !ok {
  149. return fmt.Errorf("unexpected type %T for field updated_by", values[i])
  150. } else if value.Valid {
  151. _m.UpdatedBy = new(int64)
  152. *_m.UpdatedBy = value.Int64
  153. }
  154. case announcement.FieldCreatedAt:
  155. if value, ok := values[i].(*sql.NullTime); !ok {
  156. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  157. } else if value.Valid {
  158. _m.CreatedAt = value.Time
  159. }
  160. case announcement.FieldUpdatedAt:
  161. if value, ok := values[i].(*sql.NullTime); !ok {
  162. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  163. } else if value.Valid {
  164. _m.UpdatedAt = value.Time
  165. }
  166. default:
  167. _m.selectValues.Set(columns[i], values[i])
  168. }
  169. }
  170. return nil
  171. }
  172. // Value returns the ent.Value that was dynamically selected and assigned to the Announcement.
  173. // This includes values selected through modifiers, order, etc.
  174. func (_m *Announcement) Value(name string) (ent.Value, error) {
  175. return _m.selectValues.Get(name)
  176. }
  177. // QueryReads queries the "reads" edge of the Announcement entity.
  178. func (_m *Announcement) QueryReads() *AnnouncementReadQuery {
  179. return NewAnnouncementClient(_m.config).QueryReads(_m)
  180. }
  181. // Update returns a builder for updating this Announcement.
  182. // Note that you need to call Announcement.Unwrap() before calling this method if this Announcement
  183. // was returned from a transaction, and the transaction was committed or rolled back.
  184. func (_m *Announcement) Update() *AnnouncementUpdateOne {
  185. return NewAnnouncementClient(_m.config).UpdateOne(_m)
  186. }
  187. // Unwrap unwraps the Announcement entity that was returned from a transaction after it was closed,
  188. // so that all future queries will be executed through the driver which created the transaction.
  189. func (_m *Announcement) Unwrap() *Announcement {
  190. _tx, ok := _m.config.driver.(*txDriver)
  191. if !ok {
  192. panic("ent: Announcement is not a transactional entity")
  193. }
  194. _m.config.driver = _tx.drv
  195. return _m
  196. }
  197. // String implements the fmt.Stringer.
  198. func (_m *Announcement) String() string {
  199. var builder strings.Builder
  200. builder.WriteString("Announcement(")
  201. builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
  202. builder.WriteString("title=")
  203. builder.WriteString(_m.Title)
  204. builder.WriteString(", ")
  205. builder.WriteString("content=")
  206. builder.WriteString(_m.Content)
  207. builder.WriteString(", ")
  208. builder.WriteString("status=")
  209. builder.WriteString(_m.Status)
  210. builder.WriteString(", ")
  211. builder.WriteString("notify_mode=")
  212. builder.WriteString(_m.NotifyMode)
  213. builder.WriteString(", ")
  214. builder.WriteString("targeting=")
  215. builder.WriteString(fmt.Sprintf("%v", _m.Targeting))
  216. builder.WriteString(", ")
  217. if v := _m.StartsAt; v != nil {
  218. builder.WriteString("starts_at=")
  219. builder.WriteString(v.Format(time.ANSIC))
  220. }
  221. builder.WriteString(", ")
  222. if v := _m.EndsAt; v != nil {
  223. builder.WriteString("ends_at=")
  224. builder.WriteString(v.Format(time.ANSIC))
  225. }
  226. builder.WriteString(", ")
  227. if v := _m.CreatedBy; v != nil {
  228. builder.WriteString("created_by=")
  229. builder.WriteString(fmt.Sprintf("%v", *v))
  230. }
  231. builder.WriteString(", ")
  232. if v := _m.UpdatedBy; v != nil {
  233. builder.WriteString("updated_by=")
  234. builder.WriteString(fmt.Sprintf("%v", *v))
  235. }
  236. builder.WriteString(", ")
  237. builder.WriteString("created_at=")
  238. builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
  239. builder.WriteString(", ")
  240. builder.WriteString("updated_at=")
  241. builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
  242. builder.WriteByte(')')
  243. return builder.String()
  244. }
  245. // Announcements is a parsable slice of Announcement.
  246. type Announcements []*Announcement