From 2ad0ded9076890b07e1defc852277ae1c9a8621d Mon Sep 17 00:00:00 2001 From: ata <17314593+asdxzaaaaa@user.noreply.gitee.com> Date: Fri, 10 Jul 2026 10:06:36 +0000 Subject: [PATCH] Add internal/handler/enterprise.go --- internal/handler/enterprise.go | 86 ++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 internal/handler/enterprise.go diff --git a/internal/handler/enterprise.go b/internal/handler/enterprise.go new file mode 100644 index 0000000..a8fbb48 --- /dev/null +++ b/internal/handler/enterprise.go @@ -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) +}