Executable
+106
@@ -0,0 +1,106 @@
|
||||
package immessageser
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/models/cache/immessagedata"
|
||||
"91porn-server/models/commod"
|
||||
"91porn-server/models/v/immessagemod"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type WebListReq struct {
|
||||
GroupId *int64 `json:"groupId" form:"groupId"`
|
||||
commod.Page
|
||||
}
|
||||
type WebListRes struct {
|
||||
Total int64 `json:"total"`
|
||||
HasNext bool `json:"hasNext"`
|
||||
List []immessagemod.ImMessage `json:"list"`
|
||||
}
|
||||
|
||||
// GetList 获取列表
|
||||
func (q *WebListReq) GetList() (res WebListRes, err error) {
|
||||
filter := bson.M{}
|
||||
if q.GroupId != nil {
|
||||
filter["groupId"] = *q.GroupId
|
||||
}
|
||||
res.List, res.Total, res.HasNext, err = immessagemod.GetList(filter, int64(q.Skip()), int64(q.Limit()), q.GetSort())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type WebCreateReq struct {
|
||||
GroupId int64 `json:"groupId" form:"groupId" binding:"required"` // 群组id
|
||||
Uid uint64 `json:"uid" form:"uid" binding:"required"` // 用户id
|
||||
Content string `json:"content" form:"content"` // 消息内容
|
||||
Image string `json:"image" form:"image"` // 图片
|
||||
}
|
||||
|
||||
// Create 发布数据
|
||||
func (p *WebCreateReq) Create() error {
|
||||
data := immessagemod.ImMessage{
|
||||
GroupId: p.GroupId,
|
||||
Uid: p.Uid,
|
||||
Content: p.Content,
|
||||
Image: p.Image,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
// 创建数据
|
||||
if _, err := immessagedata.InsertData(nil, data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type WebUpdateReq struct {
|
||||
ID primitive.ObjectID `json:"id" binding:"required"`
|
||||
GroupId *int64 `json:"groupId"` // 群组id
|
||||
Uid *int64 `json:"uid"` // 用户id
|
||||
Content *string `json:"content"` // 消息内容
|
||||
Image *string `json:"image"` // 图片
|
||||
}
|
||||
|
||||
// Update 更新数据
|
||||
func (p *WebUpdateReq) Update() error {
|
||||
_, err := immessagemod.GetInfo(p.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data := make(map[string]interface{})
|
||||
if p.GroupId != nil {
|
||||
data["groupId"] = *p.GroupId
|
||||
}
|
||||
if p.Uid != nil {
|
||||
data["uid"] = *p.Uid
|
||||
}
|
||||
if p.Content != nil {
|
||||
data["content"] = *p.Content
|
||||
}
|
||||
if p.Image != nil {
|
||||
data["image"] = *p.Image
|
||||
}
|
||||
|
||||
if _, err = immessagedata.UpdateData(nil, p.ID.Hex(), data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type WebDeleteReq struct {
|
||||
ID primitive.ObjectID `json:"id" binding:"required"`
|
||||
}
|
||||
|
||||
// Delete 删除数据
|
||||
func (p *WebDeleteReq) Delete() error {
|
||||
if err := immessagedata.DeleteData(nil, p.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user