Initial commit

This commit is contained in:
2022-08-26 21:10:50 +02:00
parent f5b7072065
commit 2bf97a0194
21 changed files with 1339 additions and 2 deletions

View File

@ -0,0 +1,46 @@
package logic
import (
"context"
"time"
"5feet11/internal/db"
"5feet11/internal/svc"
"5feet11/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ShortenUrlLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewShortenUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShortenUrlLogic {
return &ShortenUrlLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ShortenUrlLogic) ShortenUrl(req *types.ShortenReq) (resp *types.ShortenResp, err error) {
id := l.svcCtx.Snowflake.Generate().Base58()
insertUrl := db.UrlTable.InsertBuilder().TTL(30 * time.Second).Query(l.svcCtx.DB)
insertUrl.BindStruct(db.UrlModel{
Id: id,
RedirectUrl: req.RedirectUrl,
Secret: &req.Secret,
})
if err := insertUrl.ExecRelease(); err != nil {
return nil, err
}
resp = &types.ShortenResp{
Id: id,
}
return resp, nil
}