From 092cbcfdd11a0395929083b5c9221b6ae29eebbb Mon Sep 17 00:00:00 2001 From: strNophix Date: Sat, 27 Aug 2022 14:16:23 +0200 Subject: [PATCH] Globally renamed property `RedirectUrl` to `LongUrl` --- 5feet11.api | 6 +++--- internal/db/models.go | 6 +++--- internal/db/seed.go | 2 +- internal/handler/expandurlhandler.go | 2 +- internal/logic/expandurllogic.go | 2 +- internal/logic/shortenurllogic.go | 4 ++-- internal/types/types.go | 6 +++--- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/5feet11.api b/5feet11.api index f97c41b..5570e20 100644 --- a/5feet11.api +++ b/5feet11.api @@ -12,14 +12,14 @@ type ( } ExpandResp { - RedirectUrl string `json:"redirectUrl"` + LongUrl string `json:"longUrl"` } ) type ( ShortenReq { - RedirectUrl string `json:"redirectUrl"` - ExpiresIn int64 `json:"expiresIn,optional"` + LongUrl string `json:"longUrl"` + ExpiresIn int64 `json:"expiresIn,optional"` } ShortenResp { diff --git a/internal/db/models.go b/internal/db/models.go index 87b4e8e..1be0b03 100644 --- a/internal/db/models.go +++ b/internal/db/models.go @@ -4,12 +4,12 @@ import "github.com/scylladb/gocqlx/v2/table" var UrlTable = table.New(table.Metadata{ Name: "fivefeeteleven.urls", - Columns: []string{"id", "redirect_url"}, + Columns: []string{"id", "long_url"}, PartKey: []string{"id"}, SortKey: []string{}, }) type UrlModel struct { - ID string - RedirectUrl string + ID string + LongUrl string } diff --git a/internal/db/seed.go b/internal/db/seed.go index 33ae8d8..b77d7bb 100644 --- a/internal/db/seed.go +++ b/internal/db/seed.go @@ -15,7 +15,7 @@ func Seed(session gocqlx.Session) error { err = session.ExecStmt(` CREATE TABLE IF NOT EXISTS fivefeeteleven.urls ( id text PRIMARY KEY, - redirect_url text + long_url text )`) if err != nil { diff --git a/internal/handler/expandurlhandler.go b/internal/handler/expandurlhandler.go index 9a44c79..140cb48 100644 --- a/internal/handler/expandurlhandler.go +++ b/internal/handler/expandurlhandler.go @@ -23,7 +23,7 @@ func ExpandUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { if err != nil { httpx.Error(w, err) } else { - http.Redirect(w, r, resp.RedirectUrl, http.StatusTemporaryRedirect) + http.Redirect(w, r, resp.LongUrl, http.StatusTemporaryRedirect) } } } diff --git a/internal/logic/expandurllogic.go b/internal/logic/expandurllogic.go index 5000e63..758c55c 100644 --- a/internal/logic/expandurllogic.go +++ b/internal/logic/expandurllogic.go @@ -39,7 +39,7 @@ func (l *ExpandUrlLogic) ExpandUrl(req *types.ExpandReq) (resp *types.ExpandResp } resp = &types.ExpandResp{ - RedirectUrl: urls[0].RedirectUrl, + LongUrl: urls[0].LongUrl, } return resp, err diff --git a/internal/logic/shortenurllogic.go b/internal/logic/shortenurllogic.go index 45de21a..5fe1ee4 100644 --- a/internal/logic/shortenurllogic.go +++ b/internal/logic/shortenurllogic.go @@ -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.BindStruct(db.UrlModel{ - ID: id, - RedirectUrl: req.RedirectUrl, + ID: id, + LongUrl: req.LongUrl, }) if err := insertUrl.ExecRelease(); err != nil { diff --git a/internal/types/types.go b/internal/types/types.go index 6e260ae..3b9ceda 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -6,12 +6,12 @@ type ExpandReq struct { } type ExpandResp struct { - RedirectUrl string `json:"redirectUrl"` + LongUrl string `json:"longUrl"` } type ShortenReq struct { - RedirectUrl string `json:"redirectUrl"` - ExpiresIn int64 `json:"expiresIn,optional"` + LongUrl string `json:"longUrl"` + ExpiresIn int64 `json:"expiresIn,optional"` } type ShortenResp struct {