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.
58 lines
1.4 KiB
58 lines
1.4 KiB
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"healthapi/internal/model"
|
|
"healthapi/internal/svc"
|
|
"healthapi/internal/types"
|
|
"healthapi/pkg/errorx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetBasicProfileLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetBasicProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBasicProfileLogic {
|
|
return &GetBasicProfileLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetBasicProfileLogic) GetBasicProfile() (resp *types.HealthProfile, err error) {
|
|
userID, err := GetUserIDFromCtx(l.ctx)
|
|
if err != nil {
|
|
return nil, errorx.ErrUnauthorized
|
|
}
|
|
|
|
var profile model.HealthProfile
|
|
if err := l.svcCtx.DB.Where("user_id = ?", userID).First(&profile).Error; err != nil {
|
|
return nil, errorx.NewCodeError(errorx.CodeNotFound, "健康档案不存在")
|
|
}
|
|
|
|
birthDate := ""
|
|
if profile.BirthDate != nil {
|
|
birthDate = profile.BirthDate.Format("2006-01-02")
|
|
}
|
|
|
|
return &types.HealthProfile{
|
|
ID: uint(profile.ID),
|
|
UserID: profile.UserID,
|
|
Name: profile.Name,
|
|
BirthDate: birthDate,
|
|
Gender: profile.Gender,
|
|
Height: profile.Height,
|
|
Weight: profile.Weight,
|
|
BMI: profile.BMI,
|
|
BloodType: profile.BloodType,
|
|
Occupation: profile.Occupation,
|
|
MaritalStatus: profile.MaritalStatus,
|
|
Region: profile.Region,
|
|
}, nil
|
|
}
|
|
|