Skip to content

Commit

Permalink
fix short url lookup (#11)
Browse files Browse the repository at this point in the history
* fix short url lookup

* fix short url lookup
  • Loading branch information
bueti committed Dec 22, 2023
1 parent 5d9fdce commit 687f16d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/api/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (app *application) redirectUrlHandler(c echo.Context) error {
shortUrl := url2.PathEscape(strings.TrimSuffix(wildcardValue, "/"))
url, err := app.models.Urls.GetRedirect(shortUrl)
if err != nil {
return c.JSON(http.StatusInternalServerError, err.Error())
return c.JSON(http.StatusNotFound, err.Error())
}

return c.Redirect(http.StatusPermanentRedirect, url.Original)
Expand Down
2 changes: 1 addition & 1 deletion internal/model/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (u *UrlModel) Create(urlReq *UrlCreateRequest) (Url, error) {
return Url{}, fmt.Errorf("url cannot start with shrink.ch/s/")
}
if urlReq.ShortCode != "" {
url.ShortUrl = url2.PathEscape(urlReq.ShortCode)
url.ShortUrl = strings.ToLower(url2.PathEscape(urlReq.ShortCode))
} else {
id := base62Encode(rand.Uint64())
url.ShortUrl = id
Expand Down

0 comments on commit 687f16d

Please sign in to comment.