summaryrefslogtreecommitdiff
path: root/shrine/models/audit.go
blob: 03ee299c579b17b0a01640bb664531b584e1cabe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package models

import (
	"shrine/types/audit"
	"time"
)

type AuditLog struct {
	ID         uint      `gorm:"primaryKey;autoIncrement"`
	SystemRef  string    `gorm:"size:20;uniqueIndex"`
	ActorID    uint      `gorm:"index;not null"`
	Actor      User      `gorm:"foreignKey:ActorID"`
	Action     string    `gorm:"size:50;index;not null"`
	TargetType string    `gorm:"size:30"`
	TargetRef  string    `gorm:"size:100"`
	Summary    string    `gorm:"size:500"`
	Details    string    `gorm:"type:text"`
	CreatedAt  time.Time `gorm:"index"`
}

func (self *AuditLog) ToResponse() audit.AuditLogResponse {
	return audit.AuditLogResponse{
		SystemRef:  self.SystemRef,
		Actor:      self.Actor.Username,
		Action:     self.Action,
		TargetType: self.TargetType,
		TargetRef:  self.TargetRef,
		Summary:    self.Summary,
		CreatedAt:  self.CreatedAt,
	}
}

func (self *AuditLog) ToDetailResponse() audit.DetailResponse {
	return audit.DetailResponse{
		AuditLogResponse: self.ToResponse(),
		Details:          self.Details,
	}
}