59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"muyu-apiserver/rpc/production/internal/svc"
|
|
"muyu-apiserver/rpc/production/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetShareLinkLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGetShareLinkLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShareLinkLogic {
|
|
return &GetShareLinkLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
|
}
|
|
|
|
func (l *GetShareLinkLogic) GetShareLink(in *pb.GetShareLinkReq) (*pb.ShareLinkInfo, error) {
|
|
link, err := l.svcCtx.ShareLinkModel.FindByShortCode(l.ctx, in.ShortCode)
|
|
if err != nil {
|
|
return nil, ErrLinkNotFound
|
|
}
|
|
|
|
// Check if expired
|
|
if time.Now().After(link.ExpiresAt) {
|
|
return nil, ErrLinkExpired
|
|
}
|
|
|
|
info := &pb.ShareLinkInfo{
|
|
LinkId: link.LinkId,
|
|
TenantId: link.TenantId,
|
|
PlanId: link.PlanId,
|
|
ShortCode: link.ShortCode,
|
|
Token: link.Token,
|
|
FactoryType: link.FactoryType,
|
|
HideSensitive: link.HideSensitive,
|
|
Status: link.Status,
|
|
ClickCount: link.ClickCount,
|
|
RejectReason: link.RejectReason,
|
|
ExpiresAt: link.ExpiresAt.Format("2006-01-02 15:04:05"),
|
|
CreatedBy: link.CreatedBy,
|
|
CreatedAt: link.CreatedAt.Format("2006-01-02 15:04:05"),
|
|
UpdatedAt: link.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
}
|
|
if link.ClickedAt.Valid {
|
|
info.ClickedAt = link.ClickedAt.Time.Format("2006-01-02 15:04:05")
|
|
}
|
|
if link.RespondedAt.Valid {
|
|
info.RespondedAt = link.RespondedAt.Time.Format("2006-01-02 15:04:05")
|
|
}
|
|
|
|
return info, nil
|
|
}
|