package handlers

import (
	"errors"
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"health-go/config"
	"health-go/models"
	"net/http"
)

func FirstUser(c *gin.Context) {
	var user models.User
	result := config.DB.Where("user_name = ?", "Biid").First(&user)
	if result.Error != nil {
		if errors.Is(result.Error, gorm.ErrRecordNotFound) {
			c.JSON(http.StatusNotFound, gin.H{
				"code": 404,
				"msg":  "用户未找到",
				"data": nil,
			})
		} else {
			c.JSON(http.StatusInternalServerError, gin.H{
				"code": 500,
				"msg":  "内部服务器错误",
				"data": nil,
			})
		}
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "ok",
		"data": map[string]interface{}{
			"first_user": user,
		},
	})
}