From 590906d5557ed727f7d8ad616c95c4ce9d477c56 Mon Sep 17 00:00:00 2001 From: strNophix Date: Sat, 27 Aug 2022 14:05:59 +0200 Subject: [PATCH] Globally renamed `Snowflake` to `ID` --- 5feet11.api | 8 ++++---- internal/db/models.go | 2 +- internal/handler/routes.go | 2 +- internal/logic/expandurllogic.go | 2 +- internal/logic/shortenurllogic.go | 4 ++-- internal/types/types.go | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/5feet11.api b/5feet11.api index fadb37b..f97c41b 100644 --- a/5feet11.api +++ b/5feet11.api @@ -8,7 +8,7 @@ info ( type ( ExpandReq { - Snowflake string `path:"snowflake"` + ID string `path:"id"` } ExpandResp { @@ -23,14 +23,14 @@ type ( } ShortenResp { - Id string `json:"id"` + ID string `json:"id"` } ) service fivefeeteleven-api { @handler ExpandUrl - get /:snowflake(ExpandReq) returns(ExpandResp) + get /:id(ExpandReq) returns(ExpandResp) @handler ShortenUrl post /redirect(ShortenReq) returns(ShortenResp) -} +} \ No newline at end of file diff --git a/internal/db/models.go b/internal/db/models.go index 1d805e8..87b4e8e 100644 --- a/internal/db/models.go +++ b/internal/db/models.go @@ -10,6 +10,6 @@ var UrlTable = table.New(table.Metadata{ }) type UrlModel struct { - Id string + ID string RedirectUrl string } diff --git a/internal/handler/routes.go b/internal/handler/routes.go index a9103c0..014a868 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -14,7 +14,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { []rest.Route{ { Method: http.MethodGet, - Path: "/:snowflake", + Path: "/:id", Handler: ExpandUrlHandler(serverCtx), }, { diff --git a/internal/logic/expandurllogic.go b/internal/logic/expandurllogic.go index cc879da..5000e63 100644 --- a/internal/logic/expandurllogic.go +++ b/internal/logic/expandurllogic.go @@ -27,7 +27,7 @@ func NewExpandUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ExpandU 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}) + queryUrl.BindStruct(db.UrlModel{ID: req.ID}) var urls []db.UrlModel if err := queryUrl.Select(&urls); err != nil { diff --git a/internal/logic/shortenurllogic.go b/internal/logic/shortenurllogic.go index cb39408..45de21a 100644 --- a/internal/logic/shortenurllogic.go +++ b/internal/logic/shortenurllogic.go @@ -30,7 +30,7 @@ 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, + ID: id, RedirectUrl: req.RedirectUrl, }) @@ -39,7 +39,7 @@ func (l *ShortenUrlLogic) ShortenUrl(req *types.ShortenReq) (resp *types.Shorten } resp = &types.ShortenResp{ - Id: id, + ID: id, } return resp, nil } diff --git a/internal/types/types.go b/internal/types/types.go index dd20cbb..6e260ae 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -2,7 +2,7 @@ package types type ExpandReq struct { - Snowflake string `path:"snowflake"` + ID string `path:"id"` } type ExpandResp struct { @@ -15,5 +15,5 @@ type ShortenReq struct { } type ShortenResp struct { - Id string `json:"id"` + ID string `json:"id"` }