summaryrefslogtreecommitdiff
path: root/shrine/models/warning.go
blob: 12631a34eac2a3abd4d1f1064d83985eac812fdb (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
package models

import (
	"shrine/types/warning"

	"gorm.io/gorm"
)

type Warning struct {
	gorm.Model
	UserID    uint   `gorm:"index;not null"`
	User      User   `gorm:"foreignKey:UserID"`
	AdminID   uint   `gorm:"not null"`
	Admin     User   `gorm:"foreignKey:AdminID"`
	LetterID  uint   `gorm:"not null"`
	Letter    Letter `gorm:"foreignKey:LetterID"`
	SystemRef string `gorm:"size:20;uniqueIndex"`
	Message   string `gorm:"type:text;not null"`
	Active    bool   `gorm:"not null;default:true"`
}

func (self *Warning) ToResponse() warning.WarningResponse {
	return warning.WarningResponse{
		SystemRef: self.SystemRef,
		Admin:     self.Admin.Username,
		Message:   self.Message,
		Active:    self.Active,
		CreatedAt: self.CreatedAt,
	}
}