Token API done without verification

This commit is contained in:
JustSong
2023-04-23 11:31:00 +08:00
parent c30b069f2e
commit b908229429
11 changed files with 546 additions and 64 deletions

View File

@@ -5,28 +5,32 @@ import (
)
type Channel struct {
Id int `json:"id"`
Type int `json:"type" gorm:"default:0"`
Key string `json:"key"`
Status int `json:"status" gorm:"default:1"`
Id int `json:"id"`
Type int `json:"type" gorm:"default:0"`
Key string `json:"key"`
Status int `json:"status" gorm:"default:1"`
Name string `json:"name" gorm:"unique;index"`
Weight int `json:"weight"`
CreatedTime int64 `json:"created_time" gorm:"bigint"`
AccessedTime int64 `json:"accessed_time" gorm:"bigint"`
}
func GetAllChannels(startIdx int, num int) ([]*Channel, error) {
var channels []*Channel
var err error
err = DB.Order("id desc").Limit(num).Offset(startIdx).Find(&channels).Error
err = DB.Order("id desc").Limit(num).Offset(startIdx).Omit("key").Find(&channels).Error
return channels, err
}
func SearchChannels(keyword string) (channels []*Channel, err error) {
err = DB.Select([]string{"id", "key"}, keyword, keyword).Find(&channels).Error
err = DB.Omit("key").Where("id = ? or name LIKE ?", keyword, keyword+"%").Find(&channels).Error
return channels, err
}
func GetChannelById(id int) (*Channel, error) {
channel := Channel{Id: id}
var err error = nil
err = DB.Select([]string{"id", "type"}).First(&channel, "id = ?", id).Error
err = DB.Omit("key").First(&channel, "id = ?", id).Error
return &channel, err
}
@@ -42,7 +46,6 @@ func (channel *Channel) Update() error {
return err
}
// Delete Make sure link is valid! Because we will use os.Remove to delete it!
func (channel *Channel) Delete() error {
var err error
err = DB.Delete(channel).Error