Initial commit
This commit is contained in:
46
internal/logic/expandurllogic.go
Normal file
46
internal/logic/expandurllogic.go
Normal file
@ -0,0 +1,46 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"5feet11/internal/db"
|
||||
"5feet11/internal/svc"
|
||||
"5feet11/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ExpandUrlLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewExpandUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ExpandUrlLogic {
|
||||
return &ExpandUrlLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ExpandUrlLogic) ExpandUrl(req *types.ExpandReq) (resp *types.ExpandResp, err error) {
|
||||
queryUrl := db.UrlTable.SelectBuilder("redirect_url").Query(l.svcCtx.DB)
|
||||
queryUrl.BindStruct(db.UrlModel{Id: req.Snowflake})
|
||||
|
||||
var urls []db.UrlModel
|
||||
if err := queryUrl.Select(&urls); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(urls) != 1 {
|
||||
return nil, fmt.Errorf("no URL found")
|
||||
}
|
||||
|
||||
resp = &types.ExpandResp{
|
||||
RedirectUrl: urls[0].RedirectUrl,
|
||||
}
|
||||
|
||||
return resp, err
|
||||
}
|
Reference in New Issue
Block a user