healthapp
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.
 
 
 
 
 
 

46 lines
1015 B

package logic
import (
"context"
"healthapi/internal/model"
"healthapi/internal/svc"
"healthapi/internal/types"
"healthapi/pkg/errorx"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteAddressLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteAddressLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteAddressLogic {
return &DeleteAddressLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteAddressLogic) DeleteAddress(req *types.AddressIdReq) (resp *types.CommonResp, err error) {
userID, err := GetUserIDFromCtx(l.ctx)
if err != nil {
return nil, errorx.ErrUnauthorized
}
result := l.svcCtx.DB.Where("id = ? AND user_id = ?", req.Id, userID).Delete(&model.Address{})
if result.Error != nil {
return nil, result.Error
}
if result.RowsAffected == 0 {
return nil, errorx.NewCodeError(404, "地址不存在")
}
return &types.CommonResp{
Code: 0,
Message: "删除成功",
}, nil
}