fix: fix push setting page (#68)
* fix: unknown channel on message page * feat: add get all chanels short api * style: temporaryly change label color * fix: update query for new api * fix: fix PushSetting page * fix: fix PushSetting page --------- Co-authored-by: JustSong <quanpengsong@gmail.com>
This commit is contained in:
+13
-1
@@ -2,6 +2,7 @@ package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"message-pusher/common"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,7 +23,7 @@ const (
|
||||
type Channel struct {
|
||||
Id int `json:"id"`
|
||||
Type string `json:"type" gorm:"type:varchar(32)"`
|
||||
UserId int `json:"user_id" gorm:"uniqueIndex:name_user_id"`
|
||||
UserId int `json:"user_id" gorm:"uniqueIndex:name_user_id;index"`
|
||||
Name string `json:"name" gorm:"type:varchar(32);uniqueIndex:name_user_id"`
|
||||
Description string `json:"description"`
|
||||
Status int `json:"status" gorm:"default:1"` // enabled, disabled
|
||||
@@ -34,6 +35,12 @@ type Channel struct {
|
||||
CreatedTime int64 `json:"created_time" gorm:"bigint"`
|
||||
}
|
||||
|
||||
type BriefChannel struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
func GetChannelById(id int, userId int) (*Channel, error) {
|
||||
if id == 0 || userId == 0 {
|
||||
return nil, errors.New("id 或 userId 为空!")
|
||||
@@ -67,6 +74,11 @@ func GetChannelsByUserId(userId int, startIdx int, num int) (channels []*Channel
|
||||
return channels, err
|
||||
}
|
||||
|
||||
func GetBriefChannelsByUserId(userId int) (channels []*BriefChannel, err error) {
|
||||
err = DB.Model(&Channel{}).Select("id", "name", "description").Where("user_id = ? and status = ?", userId, common.ChannelStatusEnabled).Find(&channels).Error
|
||||
return channels, err
|
||||
}
|
||||
|
||||
func SearchChannels(userId int, keyword string) (channels []*Channel, err error) {
|
||||
err = DB.Omit("secret").Where("user_id = ?", userId).Where("id = ? or name LIKE ?", keyword, keyword+"%").Find(&channels).Error
|
||||
return channels, err
|
||||
|
||||
Reference in New Issue
Block a user