aboutsummaryrefslogtreecommitdiff
path: root/pkg/database/sql
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/database/sql')
-rw-r--r--pkg/database/sql/media.go28
-rw-r--r--pkg/database/sql/settings.go10
-rw-r--r--pkg/database/sql/user_test.go20
3 files changed, 29 insertions, 29 deletions
diff --git a/pkg/database/sql/media.go b/pkg/database/sql/media.go
index 3446f79..27f8cf0 100644
--- a/pkg/database/sql/media.go
+++ b/pkg/database/sql/media.go
@@ -6,7 +6,7 @@ import (
"gorm.io/gorm"
- "git.sr.ht/~gabrielgio/img/pkg/components/media"
+ "git.sr.ht/~gabrielgio/img/pkg/database/repository"
"git.sr.ht/~gabrielgio/img/pkg/list"
)
@@ -46,10 +46,10 @@ type (
}
)
-var _ media.Repository = &MediaRepository{}
+var _ repository.MediaRepository = &MediaRepository{}
-func (self *Media) ToModel() *media.Media {
- return &media.Media{
+func (self *Media) ToModel() *repository.Media {
+ return &repository.Media{
ID: self.ID,
Path: self.Path,
PathHash: self.PathHash,
@@ -58,8 +58,8 @@ func (self *Media) ToModel() *media.Media {
}
}
-func (m *MediaEXIF) ToModel() *media.MediaEXIF {
- return &media.MediaEXIF{
+func (m *MediaEXIF) ToModel() *repository.MediaEXIF {
+ return &repository.MediaEXIF{
Height: m.Height,
Width: m.Width,
Description: m.Description,
@@ -85,7 +85,7 @@ func NewMediaRepository(db *gorm.DB) *MediaRepository {
}
}
-func (self *MediaRepository) Create(ctx context.Context, createMedia *media.CreateMedia) error {
+func (self *MediaRepository) Create(ctx context.Context, createMedia *repository.CreateMedia) error {
media := &Media{
Name: createMedia.Name,
Path: createMedia.Path,
@@ -119,7 +119,7 @@ func (self *MediaRepository) Exists(ctx context.Context, path string) (bool, err
return exists, nil
}
-func (self *MediaRepository) List(ctx context.Context, pagination *media.Pagination) ([]*media.Media, error) {
+func (self *MediaRepository) List(ctx context.Context, pagination *repository.Pagination) ([]*repository.Media, error) {
medias := make([]*Media, 0)
result := self.db.
WithContext(ctx).
@@ -133,14 +133,14 @@ func (self *MediaRepository) List(ctx context.Context, pagination *media.Paginat
return nil, result.Error
}
- m := list.Map(medias, func(s *Media) *media.Media {
+ m := list.Map(medias, func(s *Media) *repository.Media {
return s.ToModel()
})
return m, nil
}
-func (self *MediaRepository) Get(ctx context.Context, pathHash string) (*media.Media, error) {
+func (self *MediaRepository) Get(ctx context.Context, pathHash string) (*repository.Media, error) {
m := &Media{}
result := self.db.
WithContext(ctx).
@@ -173,7 +173,7 @@ func (self *MediaRepository) GetPath(ctx context.Context, pathHash string) (stri
return path, nil
}
-func (m *MediaRepository) GetEXIF(ctx context.Context, mediaID uint) (*media.MediaEXIF, error) {
+func (m *MediaRepository) GetEXIF(ctx context.Context, mediaID uint) (*repository.MediaEXIF, error) {
exif := &MediaEXIF{}
result := m.db.
WithContext(ctx).
@@ -189,7 +189,7 @@ func (m *MediaRepository) GetEXIF(ctx context.Context, mediaID uint) (*media.Med
return exif.ToModel(), nil
}
-func (s *MediaRepository) CreateEXIF(ctx context.Context, id uint, info *media.MediaEXIF) error {
+func (s *MediaRepository) CreateEXIF(ctx context.Context, id uint, info *repository.MediaEXIF) error {
media := &MediaEXIF{
MediaID: id,
Width: info.Width,
@@ -220,7 +220,7 @@ func (s *MediaRepository) CreateEXIF(ctx context.Context, id uint, info *media.M
return nil
}
-func (r *MediaRepository) GetEmptyEXIF(ctx context.Context, pagination *media.Pagination) ([]*media.Media, error) {
+func (r *MediaRepository) GetEmptyEXIF(ctx context.Context, pagination *repository.Pagination) ([]*repository.Media, error) {
medias := make([]*Media, 0)
result := r.db.
WithContext(ctx).
@@ -236,7 +236,7 @@ func (r *MediaRepository) GetEmptyEXIF(ctx context.Context, pagination *media.Pa
return nil, result.Error
}
- m := list.Map(medias, func(s *Media) *media.Media {
+ m := list.Map(medias, func(s *Media) *repository.Media {
return s.ToModel()
})
diff --git a/pkg/database/sql/settings.go b/pkg/database/sql/settings.go
index 7ad718b..4e73878 100644
--- a/pkg/database/sql/settings.go
+++ b/pkg/database/sql/settings.go
@@ -5,7 +5,7 @@ import (
"gorm.io/gorm"
- "git.sr.ht/~gabrielgio/img/pkg/components/settings"
+ "git.sr.ht/~gabrielgio/img/pkg/database/repository"
)
type (
@@ -20,7 +20,7 @@ type (
}
)
-var _ settings.Repository = &SettingsRepository{}
+var _ repository.SettingsRepository = &SettingsRepository{}
func NewSettingsRespository(db *gorm.DB) *SettingsRepository {
return &SettingsRepository{
@@ -41,7 +41,7 @@ func (self *SettingsRepository) ensureSettings(ctx context.Context) (*Settings,
return s, nil
}
-func (self *SettingsRepository) Save(ctx context.Context, toSaveSettings *settings.Settings) error {
+func (self *SettingsRepository) Save(ctx context.Context, toSaveSettings *repository.Settings) error {
db := self.db.WithContext(ctx)
s, err := self.ensureSettings(ctx)
@@ -56,13 +56,13 @@ func (self *SettingsRepository) Save(ctx context.Context, toSaveSettings *settin
return result.Error
}
-func (self *SettingsRepository) Load(ctx context.Context) (*settings.Settings, error) {
+func (self *SettingsRepository) Load(ctx context.Context) (*repository.Settings, error) {
s, err := self.ensureSettings(ctx)
if err != nil {
return nil, err
}
- return &settings.Settings{
+ return &repository.Settings{
ShowMode: s.ShowMode,
ShowOwner: s.ShowOwner,
}, nil
diff --git a/pkg/database/sql/user_test.go b/pkg/database/sql/user_test.go
index f0d89ad..01f6729 100644
--- a/pkg/database/sql/user_test.go
+++ b/pkg/database/sql/user_test.go
@@ -12,7 +12,7 @@ import (
"gorm.io/gorm"
"gorm.io/gorm/logger"
- "git.sr.ht/~gabrielgio/img/pkg/components/user"
+ "git.sr.ht/~gabrielgio/img/pkg/database/repository"
)
func setup(t *testing.T) (*gorm.DB, func()) {
@@ -46,9 +46,9 @@ func TestCreate(t *testing.T) {
db, tearDown := setup(t)
defer tearDown()
- repository := NewUserRepository(db)
+ userRepository := NewUserRepository(db)
- id, err := repository.Create(context.Background(), &user.CreateUser{
+ id, err := userRepository.Create(context.Background(), &repository.CreateUser{
Username: "new_username",
Name: "new_name",
})
@@ -56,11 +56,11 @@ func TestCreate(t *testing.T) {
t.Fatalf("Error creating: %s", err.Error())
}
- got, err := repository.Get(context.Background(), id)
+ got, err := userRepository.Get(context.Background(), id)
if err != nil {
t.Fatalf("Error getting: %s", err.Error())
}
- want := &user.User{
+ want := &repository.User{
ID: id,
Username: "new_username",
Name: "new_name",
@@ -76,9 +76,9 @@ func TestUpdate(t *testing.T) {
db, tearDown := setup(t)
defer tearDown()
- repository := NewUserRepository(db)
+ userRepository := NewUserRepository(db)
- id, err := repository.Create(context.Background(), &user.CreateUser{
+ id, err := userRepository.Create(context.Background(), &repository.CreateUser{
Username: "username",
Name: "name",
})
@@ -86,7 +86,7 @@ func TestUpdate(t *testing.T) {
t.Fatalf("Error creating user: %s", err.Error())
}
- err = repository.Update(context.Background(), id, &user.UpdateUser{
+ err = userRepository.Update(context.Background(), id, &repository.UpdateUser{
Username: "new_username",
Name: "new_name",
})
@@ -94,11 +94,11 @@ func TestUpdate(t *testing.T) {
t.Fatalf("Error update user: %s", err.Error())
}
- got, err := repository.Get(context.Background(), 1)
+ got, err := userRepository.Get(context.Background(), 1)
if err != nil {
t.Fatalf("Error getting user: %s", err.Error())
}
- want := &user.User{
+ want := &repository.User{
ID: id,
Username: "new_username",
Name: "new_name",