package logic import ( "context" "healthapi/internal/model" "healthapi/internal/svc" "healthapi/internal/types" "healthapi/pkg/errorx" "github.com/zeromicro/go-zero/core/logx" ) type DeleteMedicalHistoryLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewDeleteMedicalHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMedicalHistoryLogic { return &DeleteMedicalHistoryLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *DeleteMedicalHistoryLogic) DeleteMedicalHistory(req *types.IdPathReq) (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.ErrNotFound } var history model.MedicalHistory if err := l.svcCtx.DB.Where("id = ? AND health_profile_id = ?", req.Id, profile.ID).First(&history).Error; err != nil { return nil, errorx.ErrNotFound } if err := l.svcCtx.DB.Delete(&history).Error; err != nil { return nil, errorx.ErrServerError } return &types.CommonResp{Code: 0, Message: "删除成功"}, nil }