Add internal/handler/enterprise.go
This commit is contained in:
86
internal/handler/enterprise.go
Normal file
86
internal/handler/enterprise.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"gotest/internal/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// EnterpriseHandler 企业数据处理器
|
||||
type EnterpriseHandler struct {
|
||||
svc *service.EnterpriseService
|
||||
}
|
||||
|
||||
// NewEnterpriseHandler 创建企业数据处理器
|
||||
func NewEnterpriseHandler(svc *service.EnterpriseService) *EnterpriseHandler {
|
||||
return &EnterpriseHandler{svc: svc}
|
||||
}
|
||||
|
||||
// GetAllData 获取企业官网全部数据 GET /api/v1/enterprise/all
|
||||
func (h *EnterpriseHandler) GetAllData(c *gin.Context) {
|
||||
data, err := h.svc.GetAllData()
|
||||
if err != nil {
|
||||
FailInternal(c, "获取数据失败")
|
||||
return
|
||||
}
|
||||
Success(c, data)
|
||||
}
|
||||
|
||||
// GetCompany 获取企业信息 GET /api/v1/enterprise/company
|
||||
func (h *EnterpriseHandler) GetCompany(c *gin.Context) {
|
||||
data, err := h.svc.GetCompany()
|
||||
if err != nil {
|
||||
FailInternal(c, "获取企业信息失败")
|
||||
return
|
||||
}
|
||||
Success(c, data)
|
||||
}
|
||||
|
||||
// ListServices 获取服务列表 GET /api/v1/enterprise/services
|
||||
func (h *EnterpriseHandler) ListServices(c *gin.Context) {
|
||||
data, err := h.svc.ListServices()
|
||||
if err != nil {
|
||||
FailInternal(c, "获取服务列表失败")
|
||||
return
|
||||
}
|
||||
Success(c, data)
|
||||
}
|
||||
|
||||
// ListNews 获取新闻列表 GET /api/v1/enterprise/news?category=&limit=
|
||||
func (h *EnterpriseHandler) ListNews(c *gin.Context) {
|
||||
category := c.Query("category")
|
||||
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "0"))
|
||||
data, err := h.svc.ListNews(category, limit)
|
||||
if err != nil {
|
||||
FailInternal(c, "获取新闻列表失败")
|
||||
return
|
||||
}
|
||||
Success(c, data)
|
||||
}
|
||||
|
||||
// GetNews 获取新闻详情 GET /api/v1/enterprise/news/:id
|
||||
func (h *EnterpriseHandler) GetNews(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
FailBadRequest(c, "无效的新闻 ID")
|
||||
return
|
||||
}
|
||||
data, err := h.svc.GetNews(uint(id))
|
||||
if err != nil {
|
||||
FailBadRequest(c, "新闻不存在")
|
||||
return
|
||||
}
|
||||
Success(c, data)
|
||||
}
|
||||
|
||||
// ListTeam 获取团队列表 GET /api/v1/enterprise/team
|
||||
func (h *EnterpriseHandler) ListTeam(c *gin.Context) {
|
||||
data, err := h.svc.ListTeam()
|
||||
if err != nil {
|
||||
FailInternal(c, "获取团队列表失败")
|
||||
return
|
||||
}
|
||||
Success(c, data)
|
||||
}
|
||||
Reference in New Issue
Block a user