Obey supplied expiration time ShortenReq.ExpiresAfter
This commit is contained in:
parent
0e8dccb9d0
commit
131cc2640a
@ -18,8 +18,8 @@ type (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
ShortenReq {
|
ShortenReq {
|
||||||
LongUrl string `json:"longUrl"`
|
LongUrl string `json:"longUrl"`
|
||||||
ExpiresIn int64 `json:"expiresIn,optional"`
|
ExpiresAfter int64 `json:"expiresAfter,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
ShortenResp {
|
ShortenResp {
|
||||||
|
@ -27,8 +27,14 @@ func NewShortenUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Shorte
|
|||||||
|
|
||||||
func (l *ShortenUrlLogic) ShortenUrl(req *types.ShortenReq) (resp *types.ShortenResp, err error) {
|
func (l *ShortenUrlLogic) ShortenUrl(req *types.ShortenReq) (resp *types.ShortenResp, err error) {
|
||||||
id := l.svcCtx.Snowflake.Generate().Base58()
|
id := l.svcCtx.Snowflake.Generate().Base58()
|
||||||
|
insertBuilder := db.UrlTable.InsertBuilder()
|
||||||
|
|
||||||
insertUrl := db.UrlTable.InsertBuilder().TTL(30 * time.Second).Query(l.svcCtx.DB)
|
logx.Info(req.ExpiresAfter)
|
||||||
|
if req.ExpiresAfter != 0 {
|
||||||
|
insertBuilder.TTL(time.Second * time.Duration(req.ExpiresAfter))
|
||||||
|
}
|
||||||
|
|
||||||
|
insertUrl := insertBuilder.Query(l.svcCtx.DB)
|
||||||
insertUrl.BindStruct(db.UrlModel{
|
insertUrl.BindStruct(db.UrlModel{
|
||||||
ID: id,
|
ID: id,
|
||||||
LongUrl: req.LongUrl,
|
LongUrl: req.LongUrl,
|
||||||
|
@ -10,8 +10,8 @@ type ExpandResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ShortenReq struct {
|
type ShortenReq struct {
|
||||||
LongUrl string `json:"longUrl"`
|
LongUrl string `json:"longUrl"`
|
||||||
ExpiresIn int64 `json:"expiresIn,optional"`
|
ExpiresAfter int64 `json:"expiresAfter,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShortenResp struct {
|
type ShortenResp struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user