Compare commits
3 Commits
a74ba3baf3
...
0944a14a97
Author | SHA1 | Date | |
---|---|---|---|
0944a14a97 | |||
9aee40d3b1 | |||
4539c926ec |
@ -32,5 +32,5 @@ service fivefeeteleven-api {
|
|||||||
get /:id(ExpandReq) returns(ExpandResp)
|
get /:id(ExpandReq) returns(ExpandResp)
|
||||||
|
|
||||||
@handler ShortenUrl
|
@handler ShortenUrl
|
||||||
post /redirect(ShortenReq) returns(ShortenResp)
|
post /api/v1/links(ShortenReq) returns(ShortenResp)
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ A URL shortener that generates links even shorter than 5'11.
|
|||||||
# Shorten a URL
|
# Shorten a URL
|
||||||
curl --header "Content-Type: application/json" \
|
curl --header "Content-Type: application/json" \
|
||||||
--request POST \
|
--request POST \
|
||||||
--data '{"redirectUrl":"https://news.ycombinator.com"}' \
|
--data '{"longUrl":"https://news.ycombinator.com"}' \
|
||||||
http://localhost:5111/redirect
|
http://localhost:5111/api/v1/links
|
||||||
|
|
||||||
# Expand the URL
|
# Expand the URL
|
||||||
curl -iL http://localhost:5111/{id}
|
curl -iL http://localhost:5111/{id}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import "github.com/scylladb/gocqlx/v2/table"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"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", "long_url"},
|
Columns: []string{"id", "long_url", "created_at"},
|
||||||
PartKey: []string{"id"},
|
PartKey: []string{"id"},
|
||||||
SortKey: []string{},
|
SortKey: []string{},
|
||||||
})
|
})
|
||||||
@ -12,4 +16,5 @@ var UrlTable = table.New(table.Metadata{
|
|||||||
type UrlModel struct {
|
type UrlModel struct {
|
||||||
ID string
|
ID string
|
||||||
LongUrl string
|
LongUrl string
|
||||||
|
CreatedAt time.Time
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,8 @@ 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,
|
||||||
long_url text
|
long_url text,
|
||||||
|
created_at timestamp
|
||||||
)`)
|
)`)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,7 +19,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/redirect",
|
Path: "/api/v1/links",
|
||||||
Handler: ShortenUrlHandler(serverCtx),
|
Handler: ShortenUrlHandler(serverCtx),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -38,6 +38,7 @@ func (l *ShortenUrlLogic) ShortenUrl(req *types.ShortenReq) (resp *types.Shorten
|
|||||||
insertUrl.BindStruct(db.UrlModel{
|
insertUrl.BindStruct(db.UrlModel{
|
||||||
ID: id,
|
ID: id,
|
||||||
LongUrl: req.LongUrl,
|
LongUrl: req.LongUrl,
|
||||||
|
CreatedAt: time.Now(),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := insertUrl.ExecRelease(); err != nil {
|
if err := insertUrl.ExecRelease(); err != nil {
|
||||||
|
Reference in New Issue
Block a user