100 lines
1.9 KiB
Go
100 lines
1.9 KiB
Go
package actvser
|
|
|
|
import (
|
|
"time"
|
|
|
|
"91porn-server/models/v/actmod"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
)
|
|
|
|
func GetActities(req GetActitiesRequest) (int64, []actmod.Activity, bool, error) {
|
|
skip := (req.PageNum - 1) * req.PageSize
|
|
count, err := actmod.GetActivitiesCount()
|
|
if err != nil {
|
|
return 0, nil, false, err
|
|
}
|
|
if uint64(count) <= skip {
|
|
return 0, nil, false, err
|
|
}
|
|
limit := req.PageSize + 1
|
|
actvs, err := actmod.GetActivities(skip, limit)
|
|
if err != nil {
|
|
return count, nil, false, err
|
|
}
|
|
hasNext := false
|
|
if uint64(len(actvs)) > req.PageSize {
|
|
hasNext = true
|
|
actvs = actvs[:req.PageSize]
|
|
}
|
|
return count, actvs, hasNext, nil
|
|
}
|
|
|
|
func AddActivity(req AddActivityRequest) error {
|
|
now := time.Now()
|
|
act := actmod.Activity{
|
|
CreatedAt: now,
|
|
UpdatedAt: now,
|
|
}
|
|
if req.ActivityName != nil {
|
|
act.ActivityName = *req.ActivityName
|
|
}
|
|
if req.Desc != nil {
|
|
act.Desc = *req.Desc
|
|
}
|
|
if req.Img != nil {
|
|
act.Img = *req.Img
|
|
}
|
|
if req.Content != nil {
|
|
act.Content = *req.Content
|
|
}
|
|
if req.Link != nil {
|
|
act.Link = *req.Link
|
|
}
|
|
if req.Sort != nil {
|
|
act.Sort = *req.Sort
|
|
}
|
|
if req.Status != nil {
|
|
act.Status = *req.Status
|
|
}
|
|
if req.ExpiredIn != nil {
|
|
act.ExpiredIn = *req.ExpiredIn
|
|
}
|
|
return actmod.AddACtivity(act)
|
|
}
|
|
|
|
func UpdateActivity(req UpdateActivityRequest) error {
|
|
b := make(bson.M)
|
|
if req.ActivityName != nil {
|
|
b["activityName"] = *req.ActivityName
|
|
}
|
|
if req.Desc != nil {
|
|
b["desc"] = *req.Desc
|
|
}
|
|
if req.Img != nil {
|
|
b["img"] = *req.Img
|
|
}
|
|
if req.Content != nil {
|
|
b["content"] = *req.Content
|
|
}
|
|
if req.Link != nil {
|
|
b["link"] = *req.Link
|
|
}
|
|
if req.Sort != nil {
|
|
b["sort"] = *req.Sort
|
|
}
|
|
if req.Status != nil {
|
|
b["status"] = *req.Status
|
|
}
|
|
if req.ExpiredIn != nil {
|
|
b["expiredIn"] = *req.ExpiredIn
|
|
}
|
|
if len(b) == 0 {
|
|
return nil
|
|
}
|
|
now := time.Now()
|
|
b["createdAt"] = now
|
|
b["updatedAt"] = now
|
|
return actmod.EidtActivity(req.ActvID, b)
|
|
}
|