first commit

This commit is contained in:
2026-02-06 21:08:15 +03:00
commit 2d7bd20ac0
12 changed files with 395 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package services
import (
"math/rand"
"example.com/m/internal/repositories"
"github.com/sqids/sqids-go"
)
type LinksService struct {
repo *repositories.LinksRepository
sqid *sqids.Sqids
}
func NewLinksService(repo *repositories.LinksRepository) *LinksService {
s, _ := sqids.New()
return &LinksService{
repo: repo,
sqid: s,
}
}
func (s *LinksService) CreateLink(original string) (string, error) {
id, _ := s.sqid.Encode([]uint64{rand.Uint64()})
err := s.repo.CreateLink(id, original)
return id, err
}
func (s *LinksService) GetLink(id string) (string, error) {
return s.repo.GetLink(id)
}