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.
49 lines
1.2 KiB
49 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 DeleteFamilyHistoryLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewDeleteFamilyHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteFamilyHistoryLogic {
|
|
return &DeleteFamilyHistoryLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *DeleteFamilyHistoryLogic) DeleteFamilyHistory(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.FamilyHistory
|
|
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
|
|
}
|
|
|