activity_log.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package activity
  2. import (
  3. "time"
  4. )
  5. const (
  6. ActivityView = "View"
  7. ActivityEdit = "Edit"
  8. ActivityCreate = "Create"
  9. ActivityDelete = "Delete"
  10. )
  11. type CreatorInterface interface {
  12. GetID() uint
  13. GetName() string
  14. }
  15. type ActivityLogInterface interface {
  16. SetCreatedAt(time.Time)
  17. GetCreatedAt() time.Time
  18. SetUserID(uint)
  19. GetUserID() uint
  20. SetCreator(string)
  21. GetCreator() string
  22. SetAction(string)
  23. GetAction() string
  24. SetModelKeys(string)
  25. GetModelKeys() string
  26. SetModelName(string)
  27. GetModelName() string
  28. SetModelLabel(string)
  29. GetModelLabel() string
  30. SetModelLink(string)
  31. GetModelLink() string
  32. SetModelDiffs(string)
  33. GetModelDiffs() string
  34. }
  35. type ActivityLog struct {
  36. ID uint `gorm:"primary_key"`
  37. UserID uint
  38. CreatedAt time.Time
  39. Creator string
  40. Action string
  41. ModelKeys string `gorm:"index"`
  42. ModelName string `gorm:"index"`
  43. ModelLabel string
  44. ModelLink string
  45. ModelDiffs string `sql:"type:text;"`
  46. }
  47. func (al *ActivityLog) SetCreatedAt(t time.Time) {
  48. al.CreatedAt = t
  49. }
  50. func (al ActivityLog) GetCreatedAt() time.Time {
  51. return al.CreatedAt
  52. }
  53. func (al *ActivityLog) SetUserID(id uint) {
  54. al.UserID = id
  55. }
  56. func (al ActivityLog) GetUserID() uint {
  57. return al.UserID
  58. }
  59. func (al *ActivityLog) SetCreator(s string) {
  60. al.Creator = s
  61. }
  62. func (al *ActivityLog) GetCreator() string {
  63. return al.Creator
  64. }
  65. func (al *ActivityLog) SetAction(s string) {
  66. al.Action = s
  67. }
  68. func (al *ActivityLog) GetAction() string {
  69. return al.Action
  70. }
  71. func (al *ActivityLog) SetModelKeys(s string) {
  72. al.ModelKeys = s
  73. }
  74. func (al *ActivityLog) GetModelKeys() string {
  75. return al.ModelKeys
  76. }
  77. func (al *ActivityLog) SetModelName(s string) {
  78. al.ModelName = s
  79. }
  80. func (al *ActivityLog) GetModelName() string {
  81. return al.ModelName
  82. }
  83. func (al *ActivityLog) SetModelLabel(s string) {
  84. al.ModelLabel = s
  85. }
  86. func (al *ActivityLog) GetModelLabel() string {
  87. if al.ModelLabel == "" {
  88. return "-"
  89. }
  90. return al.ModelLabel
  91. }
  92. func (al *ActivityLog) SetModelLink(s string) {
  93. al.ModelLink = s
  94. }
  95. func (al *ActivityLog) GetModelLink() string {
  96. return al.ModelLink
  97. }
  98. func (al *ActivityLog) SetModelDiffs(s string) {
  99. al.ModelDiffs = s
  100. }
  101. func (al *ActivityLog) GetModelDiffs() string {
  102. return al.ModelDiffs
  103. }