aboutsummaryrefslogtreecommitdiff
path: root/pkg/database/sql
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-08-13 21:36:42 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-08-13 21:36:42 +0200
commitc51fb8cc8b850b4915e083d0dd2c30d79f8b632e (patch)
tree527ba9e4f897bc2faf997ff648aeb85cc9c247eb /pkg/database/sql
parentf99f2bc94808d784c92ec4e58c660a8be3ed7fce (diff)
downloadlens-c51fb8cc8b850b4915e083d0dd2c30d79f8b632e.tar.gz
lens-c51fb8cc8b850b4915e083d0dd2c30d79f8b632e.tar.bz2
lens-c51fb8cc8b850b4915e083d0dd2c30d79f8b632e.zip
feat: Add (yet again) crude album implementation
This is a initial UI album implementation. This should cover the most basic album navigation. This is still plenty to do :)
Diffstat (limited to 'pkg/database/sql')
-rw-r--r--pkg/database/sql/media.go46
1 files changed, 41 insertions, 5 deletions
diff --git a/pkg/database/sql/media.go b/pkg/database/sql/media.go
index 59e39ee..4b48608 100644
--- a/pkg/database/sql/media.go
+++ b/pkg/database/sql/media.go
@@ -23,7 +23,7 @@ type (
gorm.Model
Width *float64
Height *float64
- MediaID uint
+ MediaID uint `gorm:"not null"`
Media Media
Description *string
Camera *string
@@ -43,8 +43,8 @@ type (
MediaThumbnail struct {
gorm.Model
- Path string
- MediaID uint
+ Path string `gorm:"not null;unique"`
+ MediaID uint `gorm:"not null"`
Media Media
}
@@ -53,7 +53,7 @@ type (
ParentID *uint
Parent *MediaAlbum
Name string
- Path string
+ Path string `gorm:"not null; unique"`
}
MediaAlbumFile struct {
@@ -104,7 +104,9 @@ func (m *MediaEXIF) ToModel() *repository.MediaEXIF {
func (a *MediaAlbum) ToModel() *repository.Album {
return &repository.Album{
- ID: a.ID,
+ ID: a.ID,
+ Name: a.Name,
+ Path: a.Path,
}
}
@@ -407,6 +409,22 @@ func (r *MediaRepository) GetAlbumByAbsolutePath(ctx context.Context, path strin
return m.ToModel(), nil
}
+func (r *MediaRepository) GetAlbum(ctx context.Context, albumID uint) (*repository.Album, error) {
+ m := &MediaAlbum{}
+ result := r.db.
+ WithContext(ctx).
+ Model(&MediaAlbum{}).
+ Where("id = ?", albumID).
+ Limit(1).
+ Take(m)
+
+ if result.Error != nil {
+ return nil, result.Error
+ }
+
+ return m.ToModel(), nil
+}
+
func (m *MediaRepository) CreateAlbum(ctx context.Context, createAlbum *repository.CreateAlbum) (*repository.Album, error) {
album := &MediaAlbum{
ParentID: createAlbum.ParentID,
@@ -439,3 +457,21 @@ func (m *MediaRepository) CreateAlbumFile(ctx context.Context, createAlbumFile *
return nil
}
+
+func (m *MediaRepository) ListAlbums(ctx context.Context, albumID uint) ([]*repository.Album, error) {
+ albums := make([]*MediaAlbum, 0)
+
+ result := m.db.
+ WithContext(ctx).
+ Model(&MediaAlbum{}).
+ Where("parent_id = ?", albumID).
+ Find(&albums)
+
+ if result.Error != nil {
+ return nil, result.Error
+ }
+
+ return list.Map(albums, func(a *MediaAlbum) *repository.Album {
+ return a.ToModel()
+ }), nil
+}