feat(links): create basic link shortening algo
This commit is contained in:
parent
fc46164556
commit
81e72cedfa
9 changed files with 144 additions and 23 deletions
|
|
@ -14,3 +14,21 @@ func (db *Database) GetLinks(ctx context.Context) ([]*domain.Link, error) {
|
|||
|
||||
return links, nil
|
||||
}
|
||||
|
||||
func (db *Database) CreateLink(ctx context.Context, link *domain.Link) (*domain.Link, error) {
|
||||
if err := db.WithContext(ctx).Create(link).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return link, nil
|
||||
}
|
||||
|
||||
func (db *Database) GetLinkByShortCode(ctx context.Context, shortCode string) (*domain.Link, error) {
|
||||
link := &domain.Link{}
|
||||
|
||||
if err := db.WithContext(ctx).Where("short_url = ?", shortCode).First(link).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return link, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue