Files
huangguo_server/web/service/quicksearchser/quicksearch.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

140 lines
3.8 KiB
Go
Executable File

package quicksearchser
import (
"time"
"91porn-server/models/cache/quicksearchdata"
"91porn-server/models/commod"
"91porn-server/models/v/quicksearchmod"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type WebListReq struct {
Title *string `form:"title" json:"title"` // 标题
Enabled *bool `form:"enabled" json:"enabled"` // 状态
Type *int `form:"type" json:"type"` // 类型
LinkType *int `form:"linkType" json:"linkType"` // 跳转链接类型
commod.Page
}
func (q *WebListReq) filter() bson.M {
var query = bson.M{}
if q.Title != nil && *q.Title != "" {
query["title"] = bson.M{"$regex": q.Title}
}
if q.Enabled != nil {
query["enabled"] = q.Enabled
}
if q.Type != nil {
query["type"] = q.Type
}
if q.LinkType != nil {
query["linkType"] = q.LinkType
}
return query
}
type WebListRes struct {
Total int64 `json:"total"`
HasNext bool `json:"hasNext"`
List []quicksearchmod.QuickSearch `json:"list"`
}
// GetList 获取列表
func (q *WebListReq) GetList() (res WebListRes, err error) {
res.List, res.Total, res.HasNext, err = quicksearchmod.GetList(q.filter(), int64(q.Skip()), int64(q.Limit()), q.GetSort())
return
}
type WebCreateReq struct {
Enabled bool `json:"enabled" form:"enabled"` // 是否开启
Title string `json:"title" form:"title"` // 展示标题
SearchKeyword string `json:"searchKeyword" form:"searchKeyword"` // 搜索关键字
Link string `json:"link" form:"link"` // 跳转链接
Type int `json:"type" form:"type"` // 配置类型 1:置顶,2:大家都在搜
LinkType int `json:"linkType" form:"linkType"` // 跳转链接类型
}
// Create 发布数据
func (p *WebCreateReq) Create() error {
data := quicksearchmod.QuickSearch{
Enabled: p.Enabled,
Title: p.Title,
SearchKeyword: p.SearchKeyword,
Link: p.Link,
Type: p.Type,
LinkType: p.LinkType,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
// 创建数据
if _, err := quicksearchdata.InsertData(nil, data); err != nil {
return err
}
return nil
}
type WebUpdateReq struct {
ID primitive.ObjectID `json:"id" binding:"required"`
Enabled *bool `json:"enabled" bson:"enabled"` // 是否开启
Title *string `json:"title" bson:"title"` // 展示标题
SearchKeyword *string `json:"searchKeyword" bson:"searchKeyword"` // 搜索关键字
Link *string `json:"link" bson:"link"` // 跳转链接
Type *int `json:"type" bson:"type"` // 配置类型 1:置顶,2:大家都在搜
LinkType *int `json:"linkType" bson:"linkType"` // 跳转链接类型
}
// Update 更新数据
func (p *WebUpdateReq) Update() error {
_, err := quicksearchmod.GetInfo(p.ID)
if err != nil {
return err
}
data := make(map[string]interface{})
if p.Enabled != nil {
data["enabled"] = p.Enabled
}
if p.Title != nil {
data["title"] = p.Title
}
if p.SearchKeyword != nil {
data["searchKeyword"] = p.SearchKeyword
}
if p.Link != nil {
data["link"] = p.Link
}
if p.LinkType != nil {
data["linkType"] = p.LinkType
}
if p.Type != nil {
data["type"] = p.Type
}
data["updatedAt"] = time.Now()
if _, err = quicksearchdata.UpdateData(nil, p.ID.Hex(), data); err != nil {
return err
}
return nil
}
type WebDeleteReq struct {
ID primitive.ObjectID `json:"id" binding:"required"` // ID
}
// Delete 删除数据
func (p *WebDeleteReq) Delete() error {
if err := quicksearchdata.DeleteData(nil, p.ID); err != nil {
return err
}
return nil
}