summaryrefslogtreecommitdiff
path: root/internal/repository
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-02 12:32:22 +0300
committerPaul Buetow <paul@buetow.org>2026-05-02 12:32:22 +0300
commite898357da954acb561a0a88b4443da52f774ce36 (patch)
tree15bf2dad7297010f0b3623dd7740527f0c51f882 /internal/repository
parent23d017ff90abfe7aeea7fb43619d7469e3ec0c2a (diff)
feat: secure shares with keyboard-first My Shares modal (hotkeys S/L)
Diffstat (limited to 'internal/repository')
-rw-r--r--internal/repository/mock.go10
-rw-r--r--internal/repository/repository.go1
-rw-r--r--internal/repository/share.go19
3 files changed, 30 insertions, 0 deletions
diff --git a/internal/repository/mock.go b/internal/repository/mock.go
index a4122cd..f93d5f8 100644
--- a/internal/repository/mock.go
+++ b/internal/repository/mock.go
@@ -195,6 +195,9 @@ func (m *MockStore) GetShareByToken(ctx context.Context, token string) (*model.S
func (m *MockStore) ListSharesByMedia(ctx context.Context, mediaID int64) ([]model.Share, error) {
return m.ShareRepo.ListSharesByMedia(ctx, mediaID)
}
+func (m *MockStore) ListSharesByUser(ctx context.Context, userID int64) ([]model.Share, error) {
+ return m.ShareRepo.ListSharesByUser(ctx, userID)
+}
func (m *MockStore) UseShare(ctx context.Context, token string) error {
return m.ShareRepo.UseShare(ctx, token)
}
@@ -587,6 +590,7 @@ type MockShareRepo struct {
CreateShareFunc func(ctx context.Context, share *model.Share) error
GetShareByTokenFunc func(ctx context.Context, token string) (*model.Share, error)
ListSharesByMediaFunc func(ctx context.Context, mediaID int64) ([]model.Share, error)
+ ListSharesByUserFunc func(ctx context.Context, userID int64) ([]model.Share, error)
UseShareFunc func(ctx context.Context, token string) error
DeleteShareFunc func(ctx context.Context, token string) error
DeleteExpiredSharesFunc func(ctx context.Context, now time.Time) error
@@ -610,6 +614,12 @@ func (m *MockShareRepo) ListSharesByMedia(ctx context.Context, mediaID int64) ([
}
return nil, nil
}
+func (m *MockShareRepo) ListSharesByUser(ctx context.Context, userID int64) ([]model.Share, error) {
+ if m.ListSharesByUserFunc != nil {
+ return m.ListSharesByUserFunc(ctx, userID)
+ }
+ return nil, nil
+}
func (m *MockShareRepo) UseShare(ctx context.Context, token string) error {
if m.UseShareFunc != nil {
return m.UseShareFunc(ctx, token)
diff --git a/internal/repository/repository.go b/internal/repository/repository.go
index 8669011..9e73a9d 100644
--- a/internal/repository/repository.go
+++ b/internal/repository/repository.go
@@ -173,6 +173,7 @@ type ShareRepo interface {
CreateShare(ctx context.Context, share *model.Share) error
GetShareByToken(ctx context.Context, token string) (*model.Share, error)
ListSharesByMedia(ctx context.Context, mediaID int64) ([]model.Share, error)
+ ListSharesByUser(ctx context.Context, userID int64) ([]model.Share, error)
UseShare(ctx context.Context, token string) error
DeleteShare(ctx context.Context, token string) error
DeleteExpiredShares(ctx context.Context, now time.Time) error
diff --git a/internal/repository/share.go b/internal/repository/share.go
index 700b4a3..177decd 100644
--- a/internal/repository/share.go
+++ b/internal/repository/share.go
@@ -62,6 +62,25 @@ func (s *SQLite) ListSharesByMedia(ctx context.Context, mediaID int64) ([]model.
return shares, rows.Err()
}
+// ListSharesByUser returns all shares created by a specific user.
+func (s *SQLite) ListSharesByUser(ctx context.Context, userID int64) ([]model.Share, error) {
+ rows, err := s.db.QueryContext(ctx,
+ `SELECT token, media_id, created_by, created_at, expires_at, max_uses, used_count FROM shares WHERE created_by = ? ORDER BY created_at DESC`, userID)
+ if err != nil {
+ return nil, fmt.Errorf("list shares by user: %w", err)
+ }
+ defer rows.Close()
+ var shares []model.Share
+ for rows.Next() {
+ sh, err := scanShare(rows)
+ if err != nil {
+ return nil, err
+ }
+ shares = append(shares, *sh)
+ }
+ return shares, rows.Err()
+}
+
// UseShare increments the used_count of a share token.
func (s *SQLite) UseShare(ctx context.Context, token string) error {
_, err := s.db.ExecContext(ctx, `UPDATE shares SET used_count = used_count + 1 WHERE token = ?`, token)