You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

43 lines
905 B

package organization
import (
"net/http"
"strconv"
"task-track-backend/model"
"github.com/gin-gonic/gin"
)
func (h *OrganizationHandler) GetOrganizations(c *gin.Context) {
var organizations []model.Organization
// 分页参数
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "10"))
offset := (page - 1) * limit
// 查询机构
if err := h.db.Offset(offset).Limit(limit).Find(&organizations).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"code": 500,
"message": "Failed to get organizations",
"error": err.Error(),
})
return
}
// 获取总数
var total int64
h.db.Model(&model.Organization{}).Count(&total)
c.JSON(http.StatusOK, gin.H{
"code": 200,
"message": "Success",
"data": gin.H{
"list": organizations,
"total": total,
"page": page,
"limit": limit,
},
})
}