package handler import ( "strconv" "health-ai/internal/api/middleware" "health-ai/internal/service" "health-ai/pkg/response" "github.com/gin-gonic/gin" ) type HealthHandler struct { healthService *service.HealthService } func NewHealthHandler() *HealthHandler { return &HealthHandler{ healthService: service.NewHealthService(), } } // GetHealthProfile 获取完整健康档案 // @Summary 获取完整健康档案 // @Tags 健康档案 // @Accept json // @Produce json // @Param Authorization header string true "Bearer Token" // @Success 200 {object} response.Response{data=service.HealthProfileResponse} // @Router /api/user/health-profile [get] func (h *HealthHandler) GetHealthProfile(c *gin.Context) { userID := middleware.GetUserID(c) profile, err := h.healthService.GetHealthProfile(userID) if err != nil { response.Error(c, 500, err.Error()) return } response.Success(c, profile) } // GetBasicProfile 获取基础档案 // @Summary 获取基础档案 // @Tags 健康档案 // @Accept json // @Produce json // @Param Authorization header string true "Bearer Token" // @Success 200 {object} response.Response{data=model.HealthProfile} // @Router /api/user/basic-profile [get] func (h *HealthHandler) GetBasicProfile(c *gin.Context) { userID := middleware.GetUserID(c) profile, err := h.healthService.GetBasicProfile(userID) if err != nil { response.Error(c, 404, err.Error()) return } response.Success(c, profile) } // GetLifestyle 获取生活习惯 // @Summary 获取生活习惯 // @Tags 健康档案 // @Accept json // @Produce json // @Param Authorization header string true "Bearer Token" // @Success 200 {object} response.Response{data=model.LifestyleInfo} // @Router /api/user/lifestyle [get] func (h *HealthHandler) GetLifestyle(c *gin.Context) { userID := middleware.GetUserID(c) lifestyle, err := h.healthService.GetLifestyle(userID) if err != nil { response.Error(c, 404, err.Error()) return } response.Success(c, lifestyle) } // GetMedicalHistory 获取病史列表 // @Summary 获取病史列表 // @Tags 健康档案 // @Accept json // @Produce json // @Param Authorization header string true "Bearer Token" // @Success 200 {object} response.Response{data=[]model.MedicalHistory} // @Router /api/user/medical-history [get] func (h *HealthHandler) GetMedicalHistory(c *gin.Context) { userID := middleware.GetUserID(c) history, err := h.healthService.GetMedicalHistory(userID) if err != nil { response.Error(c, 404, err.Error()) return } response.Success(c, history) } // GetFamilyHistory 获取家族病史列表 // @Summary 获取家族病史列表 // @Tags 健康档案 // @Accept json // @Produce json // @Param Authorization header string true "Bearer Token" // @Success 200 {object} response.Response{data=[]model.FamilyHistory} // @Router /api/user/family-history [get] func (h *HealthHandler) GetFamilyHistory(c *gin.Context) { userID := middleware.GetUserID(c) history, err := h.healthService.GetFamilyHistory(userID) if err != nil { response.Error(c, 404, err.Error()) return } response.Success(c, history) } // GetAllergyRecords 获取过敏记录列表 // @Summary 获取过敏记录列表 // @Tags 健康档案 // @Accept json // @Produce json // @Param Authorization header string true "Bearer Token" // @Success 200 {object} response.Response{data=[]model.AllergyRecord} // @Router /api/user/allergy-records [get] func (h *HealthHandler) GetAllergyRecords(c *gin.Context) { userID := middleware.GetUserID(c) records, err := h.healthService.GetAllergyRecords(userID) if err != nil { response.Error(c, 404, err.Error()) return } response.Success(c, records) } // DeleteMedicalHistory 删除病史记录 // @Summary 删除病史记录 // @Tags 健康档案 // @Accept json // @Produce json // @Param Authorization header string true "Bearer Token" // @Param id path int true "记录ID" // @Success 200 {object} response.Response // @Router /api/user/medical-history/{id} [delete] func (h *HealthHandler) DeleteMedicalHistory(c *gin.Context) { userID := middleware.GetUserID(c) id, err := strconv.ParseUint(c.Param("id"), 10, 32) if err != nil { response.BadRequest(c, "无效的ID") return } if err := h.healthService.DeleteMedicalHistory(userID, uint(id)); err != nil { response.Error(c, 500, err.Error()) return } response.SuccessWithMessage(c, "删除成功", nil) } // DeleteFamilyHistory 删除家族病史记录 // @Summary 删除家族病史记录 // @Tags 健康档案 // @Accept json // @Produce json // @Param Authorization header string true "Bearer Token" // @Param id path int true "记录ID" // @Success 200 {object} response.Response // @Router /api/user/family-history/{id} [delete] func (h *HealthHandler) DeleteFamilyHistory(c *gin.Context) { userID := middleware.GetUserID(c) id, err := strconv.ParseUint(c.Param("id"), 10, 32) if err != nil { response.BadRequest(c, "无效的ID") return } if err := h.healthService.DeleteFamilyHistory(userID, uint(id)); err != nil { response.Error(c, 500, err.Error()) return } response.SuccessWithMessage(c, "删除成功", nil) } // DeleteAllergyRecord 删除过敏记录 // @Summary 删除过敏记录 // @Tags 健康档案 // @Accept json // @Produce json // @Param Authorization header string true "Bearer Token" // @Param id path int true "记录ID" // @Success 200 {object} response.Response // @Router /api/user/allergy-records/{id} [delete] func (h *HealthHandler) DeleteAllergyRecord(c *gin.Context) { userID := middleware.GetUserID(c) id, err := strconv.ParseUint(c.Param("id"), 10, 32) if err != nil { response.BadRequest(c, "无效的ID") return } if err := h.healthService.DeleteAllergyRecord(userID, uint(id)); err != nil { response.Error(c, 500, err.Error()) return } response.SuccessWithMessage(c, "删除成功", nil) }