You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-fly/models/welcomes.go

48 lines
1.1 KiB

4 years ago
package models
import "time"
type Welcome struct {
ID uint `gorm:"primary_key" json:"id"`
UserId string `json:"user_id"`
Content string `json:"content"`
IsDefault uint `json:"is_default"`
Ctime time.Time `json:"ctime"`
4 years ago
}
func CreateWelcome(userId string, content string) uint {
if userId == "" || content == "" {
return 0
}
w := &Welcome{
UserId: userId,
Content: content,
Ctime: time.Now(),
}
DB.Create(w)
return w.ID
}
func UpdateWelcome(userId string,id string, content string) uint {
if userId == "" || content == "" {
return 0
}
w := &Welcome{
Content: content,
}
DB.Model(w).Where("user_id = ? and id = ?", userId,id).Update(w)
return w.ID
}
func FindWelcomeByUserId(userId interface{}) Welcome {
4 years ago
var w Welcome
DB.Where("user_id = ? and is_default=?", userId, 1).First(&w)
4 years ago
return w
}
func FindWelcomesByUserId(userId interface{}) []Welcome {
var w []Welcome
DB.Where("user_id = ?", userId).Find(&w)
return w
}
func DeleteWelcome(userId interface{}, id string) {
DB.Where("user_id = ? and id = ?", userId, id).Delete(Welcome{})
}