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.
54 lines
1.3 KiB
54 lines
1.3 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 GetFamilyHistoryLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetFamilyHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFamilyHistoryLogic {
|
|
return &GetFamilyHistoryLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetFamilyHistoryLogic) GetFamilyHistory() (resp []types.FamilyHistory, 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, "请先填写基础信息")
|
|
}
|
|
|
|
var histories []model.FamilyHistory
|
|
l.svcCtx.DB.Where("health_profile_id = ?", profile.ID).Find(&histories)
|
|
|
|
resp = make([]types.FamilyHistory, 0, len(histories))
|
|
for _, h := range histories {
|
|
resp = append(resp, types.FamilyHistory{
|
|
ID: uint(h.ID),
|
|
HealthProfileID: h.HealthProfileID,
|
|
Relation: h.Relation,
|
|
DiseaseName: h.DiseaseName,
|
|
Notes: h.Notes,
|
|
})
|
|
}
|
|
|
|
return resp, nil
|
|
}
|
|
|