| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package topic
- import (
- "github.com/gin-gonic/gin"
- "github.com/runningwater/gohub/pkg/app"
- "github.com/runningwater/gohub/pkg/database"
- "github.com/runningwater/gohub/pkg/paginator"
- )
- func Get(idStr string) (topic Topic) {
- database.DB.Where("id", idStr).First(&topic)
- return
- }
- func GetBy(field, value string) (topic Topic) {
- database.DB.Where("? = ?", field, value).First(&topic)
- return
- }
- func All() (topics []Topic) {
- database.DB.Find(&topics)
- return
- }
- func IsExist(field, value string) bool {
- var count int64
- database.DB.Model(Topic{}).Where("? = ?", field, value).Count(&count)
- return count > 0
- }
- // Paginate 分页内容
- func Paginate(c *gin.Context, pageSize int) (topics []Topic, paging paginator.Paging) {
- paging = paginator.Paginate(
- c,
- database.DB.Model(Topic{}),
- &topics,
- app.V1URL(database.TableName(&Topic{})),
- pageSize,
- )
- return
- }
|