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 GetAddressLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetAddressLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAddressLogic {
|
|
return &GetAddressLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetAddressLogic) GetAddress(req *types.AddressIdReq) (resp *types.Address, err error) {
|
|
userID, err := GetUserIDFromCtx(l.ctx)
|
|
if err != nil {
|
|
return nil, errorx.ErrUnauthorized
|
|
}
|
|
|
|
var addr model.Address
|
|
if err := l.svcCtx.DB.Where("id = ? AND user_id = ?", req.Id, userID).First(&addr).Error; err != nil {
|
|
return nil, errorx.NewCodeError(404, "地址不存在")
|
|
}
|
|
|
|
resp = &types.Address{
|
|
ID: uint(addr.ID),
|
|
ReceiverName: addr.ReceiverName,
|
|
Phone: addr.Phone,
|
|
Province: addr.Province,
|
|
City: addr.City,
|
|
District: addr.District,
|
|
DetailAddr: addr.DetailAddr,
|
|
PostalCode: addr.PostalCode,
|
|
IsDefault: addr.IsDefault,
|
|
Tag: addr.Tag,
|
|
}
|
|
return resp, nil
|
|
}
|
|
|