| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package topic
- import (
- "github.com/gin-gonic/gin"
- "gorm.io/gorm/clause"
- "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.Preload(clause.Associations).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
- }
|