mirror of
https://gitee.com/shikong-sk/gofiber-study
synced 2025-02-24 07:42:15 +08:00
40 lines
660 B
Go
40 lines
660 B
Go
package topical
|
|
|
|
import (
|
|
"gofiber.study.skcks.cn/global"
|
|
"gofiber.study.skcks.cn/model/generic/models"
|
|
"strconv"
|
|
)
|
|
|
|
type Service struct {
|
|
}
|
|
|
|
var Services *Service
|
|
|
|
func InitService() {
|
|
Services = &Service{}
|
|
}
|
|
|
|
type CreateTopicalDTO struct {
|
|
Title string
|
|
Content string
|
|
}
|
|
|
|
func (s *Service) CreateTopical(dto CreateTopicalDTO, userId string) error {
|
|
id, _ := global.SonyFlake.NextID()
|
|
_, err := global.DataSources.Insert(&models.Topical{
|
|
Id: strconv.FormatUint(id, 10),
|
|
Active: true,
|
|
Content: dto.Content,
|
|
ModifyTimes: 0,
|
|
Title: dto.Title,
|
|
UserId: userId,
|
|
})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|