add color

This commit is contained in:
Havoc412 2024-10-23 02:54:56 +08:00
parent da2ecf2eba
commit 4d3238e230
5 changed files with 20 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"time"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
)
type BaseModel struct {
@ -24,6 +25,16 @@ type BriefModel struct {
NameEn string `json:"name_en"`
}
type Color struct {
ColorFont string `json:"color_font" gorm:"type:char(10)"`
ColorBackground string `json:"color_background" gorm:"type:char(10)"`
}
type DeletedAt struct {
DeletedAt *time.Time `json:"deleted_at" gorm:"defalt:NULL"`
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag"`
}
func UseDbConn(sqlType string) *gorm.DB {
var db *gorm.DB
sqlType = strings.Trim(sqlType, " ")

View File

@ -23,7 +23,7 @@ type Encounter struct { // Encounter 或者称为 post指的就是 Human 单
Title string `gorm:"size:20;column:title" json:"title"`
Content string `json:"content"`
Level uint8 `json:"level" gorm:"level;default:1"`
Level uint8 `json:"level" gorm:"column:level;default:1"`
// Time 从 CreatedAt 中解析
// TAG Avatar 最好是压缩后的备份图像

View File

@ -2,4 +2,5 @@ package model
type EncounerLevel struct {
BriefModel
Color
}

View File

@ -6,4 +6,5 @@ type EncounterLike struct {
UsersModel UsersModel
EncounterId int `gorm:"column:encounter_id" json:"encounter_id"`
Encounter Encounter
DeletedAt
}

View File

@ -47,6 +47,8 @@ func TestEncounterLevel(t *testing.T) {
ZH := []string{"日常", "重大", "标志", "代办", "日程"}
EN := []string{"daily", "serious", "flag", "todo", "schedule"}
colorbg := []string{"#F0F0F0", "#FFD700", "#FF69B4", "#87CEFA", "#32CD32"}
colorfont := []string{"#333333", "#000000", "#FFFFFF", "#000000", "#FFFFFF"}
for i := 0; i < len(ZH); i++ {
encounterLevel := model.EncounerLevel{
@ -54,6 +56,10 @@ func TestEncounterLevel(t *testing.T) {
NameZh: ZH[i],
NameEn: EN[i],
},
Color: model.Color{
ColorBackground: colorbg[i],
ColorFont: colorfont[i],
},
}
DB.Create(&encounterLevel)
}