Globally renamed Snowflake
to ID
This commit is contained in:
@ -8,7 +8,7 @@ info (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
ExpandReq {
|
ExpandReq {
|
||||||
Snowflake string `path:"snowflake"`
|
ID string `path:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpandResp {
|
ExpandResp {
|
||||||
@ -23,14 +23,14 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShortenResp {
|
ShortenResp {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
service fivefeeteleven-api {
|
service fivefeeteleven-api {
|
||||||
@handler ExpandUrl
|
@handler ExpandUrl
|
||||||
get /:snowflake(ExpandReq) returns(ExpandResp)
|
get /:id(ExpandReq) returns(ExpandResp)
|
||||||
|
|
||||||
@handler ShortenUrl
|
@handler ShortenUrl
|
||||||
post /redirect(ShortenReq) returns(ShortenResp)
|
post /redirect(ShortenReq) returns(ShortenResp)
|
||||||
}
|
}
|
@ -10,6 +10,6 @@ var UrlTable = table.New(table.Metadata{
|
|||||||
})
|
})
|
||||||
|
|
||||||
type UrlModel struct {
|
type UrlModel struct {
|
||||||
Id string
|
ID string
|
||||||
RedirectUrl string
|
RedirectUrl string
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/:snowflake",
|
Path: "/:id",
|
||||||
Handler: ExpandUrlHandler(serverCtx),
|
Handler: ExpandUrlHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -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) {
|
func (l *ExpandUrlLogic) ExpandUrl(req *types.ExpandReq) (resp *types.ExpandResp, err error) {
|
||||||
queryUrl := db.UrlTable.SelectBuilder("redirect_url").Query(l.svcCtx.DB)
|
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
|
var urls []db.UrlModel
|
||||||
if err := queryUrl.Select(&urls); err != nil {
|
if err := queryUrl.Select(&urls); err != nil {
|
||||||
|
@ -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 := 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,
|
RedirectUrl: req.RedirectUrl,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ func (l *ShortenUrlLogic) ShortenUrl(req *types.ShortenReq) (resp *types.Shorten
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp = &types.ShortenResp{
|
resp = &types.ShortenResp{
|
||||||
Id: id,
|
ID: id,
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
type ExpandReq struct {
|
type ExpandReq struct {
|
||||||
Snowflake string `path:"snowflake"`
|
ID string `path:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExpandResp struct {
|
type ExpandResp struct {
|
||||||
@ -15,5 +15,5 @@ type ShortenReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ShortenResp struct {
|
type ShortenResp struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user