35 lines
849 B
Go
35 lines
849 B
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"lone-services/pkg/rpcclient"
|
|
"lone-services/pkg/utils"
|
|
storepb "lone-services/rpc/store/pb"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func fetchStoreById(ctx context.Context, storeSvcName string, storeId int64) (*storepb.InfoResponse, error) {
|
|
if storeSvcName == utils.StringEmpty || storeId < utils.NumberOne {
|
|
return nil, nil
|
|
}
|
|
cli, err := rpcclient.Get(storeSvcName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
data, err := storepb.NewStoreClient(cli.Conn()).GetInfoById(ctx, &storepb.IdRequest{Id: storeId})
|
|
if err != nil {
|
|
if st, ok := status.FromError(err); ok &&
|
|
(st.Code() == codes.NotFound || st.Message() == utils.ErrorNotFund.Msg) {
|
|
return nil, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
if data == nil || data.Id < utils.NumberOne {
|
|
return nil, nil
|
|
}
|
|
return data, nil
|
|
}
|