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.
51 lines
1.3 KiB
51 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 SubmitFamilyHistoryLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewSubmitFamilyHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubmitFamilyHistoryLogic {
|
|
return &SubmitFamilyHistoryLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *SubmitFamilyHistoryLogic) SubmitFamilyHistory(req *types.SubmitFamilyHistoryReq) (resp *types.CommonResp, 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.CodeBadRequest, "请先填写基础信息")
|
|
}
|
|
|
|
history := model.FamilyHistory{
|
|
HealthProfileID: profile.ID,
|
|
Relation: req.Relation,
|
|
DiseaseName: req.DiseaseName,
|
|
Notes: req.Notes,
|
|
}
|
|
|
|
if err := l.svcCtx.DB.Create(&history).Error; err != nil {
|
|
return nil, errorx.ErrServerError
|
|
}
|
|
|
|
return &types.CommonResp{Code: 0, Message: "提交成功"}, nil
|
|
}
|
|
|