redirect
This commit is contained in:
23
repository/RecuperarUrl.go
Normal file
23
repository/RecuperarUrl.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"url-short/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func RecuperarUrl(shortUrl string, db *gorm.DB) (string, error) {
|
||||
|
||||
var url models.Url
|
||||
i, err := strconv.ParseInt(shortUrl, 10, 64);
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
result := db.Where(&models.Url{Shorturl: i}).First(&url)
|
||||
|
||||
if result.Error != nil {
|
||||
return "", result.Error
|
||||
}
|
||||
return url.Longurl, nil
|
||||
}
|
||||
Reference in New Issue
Block a user