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.
52 lines
1.2 KiB
52 lines
1.2 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 SubmitAllergyLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewSubmitAllergyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubmitAllergyLogic {
|
|
return &SubmitAllergyLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *SubmitAllergyLogic) SubmitAllergy(req *types.SubmitAllergyReq) (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, "请先填写基础信息")
|
|
}
|
|
|
|
record := model.AllergyRecord{
|
|
HealthProfileID: profile.ID,
|
|
AllergyType: req.AllergyType,
|
|
Allergen: req.Allergen,
|
|
Severity: req.Severity,
|
|
ReactionDesc: req.ReactionDesc,
|
|
}
|
|
|
|
if err := l.svcCtx.DB.Create(&record).Error; err != nil {
|
|
return nil, errorx.ErrServerError
|
|
}
|
|
|
|
return &types.CommonResp{Code: 0, Message: "提交成功"}, nil
|
|
}
|
|
|