Globally renamed property RedirectUrl to LongUrl

This commit is contained in:
strNophix 2022-08-27 14:16:23 +02:00
parent 590906d555
commit 092cbcfdd1
7 changed files with 14 additions and 14 deletions

View File

@ -12,14 +12,14 @@ type (
} }
ExpandResp { ExpandResp {
RedirectUrl string `json:"redirectUrl"` LongUrl string `json:"longUrl"`
} }
) )
type ( type (
ShortenReq { ShortenReq {
RedirectUrl string `json:"redirectUrl"` LongUrl string `json:"longUrl"`
ExpiresIn int64 `json:"expiresIn,optional"` ExpiresIn int64 `json:"expiresIn,optional"`
} }
ShortenResp { ShortenResp {

View File

@ -4,12 +4,12 @@ import "github.com/scylladb/gocqlx/v2/table"
var UrlTable = table.New(table.Metadata{ var UrlTable = table.New(table.Metadata{
Name: "fivefeeteleven.urls", Name: "fivefeeteleven.urls",
Columns: []string{"id", "redirect_url"}, Columns: []string{"id", "long_url"},
PartKey: []string{"id"}, PartKey: []string{"id"},
SortKey: []string{}, SortKey: []string{},
}) })
type UrlModel struct { type UrlModel struct {
ID string ID string
RedirectUrl string LongUrl string
} }

View File

@ -15,7 +15,7 @@ func Seed(session gocqlx.Session) error {
err = session.ExecStmt(` err = session.ExecStmt(`
CREATE TABLE IF NOT EXISTS fivefeeteleven.urls ( CREATE TABLE IF NOT EXISTS fivefeeteleven.urls (
id text PRIMARY KEY, id text PRIMARY KEY,
redirect_url text long_url text
)`) )`)
if err != nil { if err != nil {

View File

@ -23,7 +23,7 @@ func ExpandUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
if err != nil { if err != nil {
httpx.Error(w, err) httpx.Error(w, err)
} else { } else {
http.Redirect(w, r, resp.RedirectUrl, http.StatusTemporaryRedirect) http.Redirect(w, r, resp.LongUrl, http.StatusTemporaryRedirect)
} }
} }
} }

View File

@ -39,7 +39,7 @@ func (l *ExpandUrlLogic) ExpandUrl(req *types.ExpandReq) (resp *types.ExpandResp
} }
resp = &types.ExpandResp{ resp = &types.ExpandResp{
RedirectUrl: urls[0].RedirectUrl, LongUrl: urls[0].LongUrl,
} }
return resp, err return resp, err

View File

@ -30,8 +30,8 @@ func (l *ShortenUrlLogic) ShortenUrl(req *types.ShortenReq) (resp *types.Shorten
insertUrl := db.UrlTable.InsertBuilder().TTL(30 * time.Second).Query(l.svcCtx.DB) insertUrl := db.UrlTable.InsertBuilder().TTL(30 * time.Second).Query(l.svcCtx.DB)
insertUrl.BindStruct(db.UrlModel{ insertUrl.BindStruct(db.UrlModel{
ID: id, ID: id,
RedirectUrl: req.RedirectUrl, LongUrl: req.LongUrl,
}) })
if err := insertUrl.ExecRelease(); err != nil { if err := insertUrl.ExecRelease(); err != nil {

View File

@ -6,12 +6,12 @@ type ExpandReq struct {
} }
type ExpandResp struct { type ExpandResp struct {
RedirectUrl string `json:"redirectUrl"` LongUrl string `json:"longUrl"`
} }
type ShortenReq struct { type ShortenReq struct {
RedirectUrl string `json:"redirectUrl"` LongUrl string `json:"longUrl"`
ExpiresIn int64 `json:"expiresIn,optional"` ExpiresIn int64 `json:"expiresIn,optional"`
} }
type ShortenResp struct { type ShortenResp struct {