Backend: Rename "models" package to "entity"

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2019-12-11 16:55:18 +01:00
parent 5aa116ee06
commit 4e06deda76
38 changed files with 99 additions and 99 deletions

View file

@ -10,9 +10,9 @@ import (
"strings"
"time"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/models"
"github.com/photoprism/photoprism/internal/repo"
"github.com/gin-gonic/gin"
@ -78,7 +78,7 @@ func CreateAlbum(router *gin.RouterGroup, conf *config.Config) {
return
}
m := models.NewAlbum(f.AlbumName)
m := entity.NewAlbum(f.AlbumName)
if res := conf.Db().Create(m); res.Error != nil {
log.Error(res.Error.Error())
@ -245,14 +245,14 @@ func AddPhotosToAlbum(router *gin.RouterGroup, conf *config.Config) {
}
db := conf.Db()
var added []*models.PhotoAlbum
var added []*entity.PhotoAlbum
var failed []string
for _, photoUUID := range f.Photos {
if p, err := r.FindPhotoByUUID(photoUUID); err != nil {
failed = append(failed, photoUUID)
} else {
added = append(added, models.NewPhotoAlbum(p.PhotoUUID, a.AlbumUUID).FirstOrCreate(db))
added = append(added, entity.NewPhotoAlbum(p.PhotoUUID, a.AlbumUUID).FirstOrCreate(db))
}
}
@ -297,7 +297,7 @@ func RemovePhotosFromAlbum(router *gin.RouterGroup, conf *config.Config) {
db := conf.Db()
db.Where("album_uuid = ? AND photo_uuid IN (?)", a.AlbumUUID, f.Photos).Delete(&models.PhotoAlbum{})
db.Where("album_uuid = ? AND photo_uuid IN (?)", a.AlbumUUID, f.Photos).Delete(&entity.PhotoAlbum{})
event.Success(fmt.Sprintf("photos removed from %s", a.AlbumName))

View file

@ -7,9 +7,9 @@ import (
"github.com/jinzhu/gorm"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/models"
"github.com/photoprism/photoprism/internal/util"
"github.com/gin-gonic/gin"
@ -42,7 +42,7 @@ func BatchPhotosDelete(router *gin.RouterGroup, conf *config.Config) {
db := conf.Db()
db.Where("photo_uuid IN (?)", f.Photos).Delete(&models.Photo{})
db.Where("photo_uuid IN (?)", f.Photos).Delete(&entity.Photo{})
elapsed := int(time.Since(start).Seconds())
@ -79,8 +79,8 @@ func BatchAlbumsDelete(router *gin.RouterGroup, conf *config.Config) {
db := conf.Db()
db.Where("album_uuid IN (?)", f.Albums).Delete(&models.Album{})
db.Where("album_uuid IN (?)", f.Albums).Delete(&models.PhotoAlbum{})
db.Where("album_uuid IN (?)", f.Albums).Delete(&entity.Album{})
db.Where("album_uuid IN (?)", f.Albums).Delete(&entity.PhotoAlbum{})
event.Publish("config.updated", event.Data(conf.ClientConfig()))
@ -115,7 +115,7 @@ func BatchPhotosPrivate(router *gin.RouterGroup, conf *config.Config) {
db := conf.Db()
db.Model(models.Photo{}).Where("photo_uuid IN (?)", f.Photos).UpdateColumn("photo_private", gorm.Expr("IF (`photo_private`, 0, 1)"))
db.Model(entity.Photo{}).Where("photo_uuid IN (?)", f.Photos).UpdateColumn("photo_private", gorm.Expr("IF (`photo_private`, 0, 1)"))
elapsed := time.Since(start)
@ -150,7 +150,7 @@ func BatchPhotosStory(router *gin.RouterGroup, conf *config.Config) {
db := conf.Db()
db.Model(models.Photo{}).Where("photo_uuid IN (?)", f.Photos).Updates(map[string]interface{}{
db.Model(entity.Photo{}).Where("photo_uuid IN (?)", f.Photos).Updates(map[string]interface{}{
"photo_story": gorm.Expr("IF (`photo_story`, 0, 1)"),
})

View file

@ -12,8 +12,8 @@ import (
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/sqlite"
gc "github.com/patrickmn/go-cache"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/models"
"github.com/photoprism/photoprism/internal/tidb"
"github.com/photoprism/photoprism/internal/util"
"github.com/sirupsen/logrus"
@ -531,22 +531,22 @@ func (c *Config) MigrateDb() {
// db.LogMode(true)
db.AutoMigrate(
&models.File{},
&models.Photo{},
&models.Event{},
&models.Location{},
&models.Camera{},
&models.Lens{},
&models.Country{},
&models.Share{},
&entity.File{},
&entity.Photo{},
&entity.Event{},
&entity.Location{},
&entity.Camera{},
&entity.Lens{},
&entity.Country{},
&entity.Share{},
&models.Album{},
&models.PhotoAlbum{},
&models.Label{},
&models.Category{},
&models.PhotoLabel{},
&models.Keyword{},
&models.PhotoKeyword{},
&entity.Album{},
&entity.PhotoAlbum{},
&entity.Label{},
&entity.Category{},
&entity.PhotoLabel{},
&entity.Keyword{},
&entity.PhotoKeyword{},
)
}
@ -554,8 +554,8 @@ func (c *Config) MigrateDb() {
func (c *Config) ClientConfig() ClientConfig {
db := c.Db()
var cameras []*models.Camera
var albums []*models.Album
var cameras []*entity.Camera
var albums []*entity.Album
type country struct {
LocCountry string
@ -592,7 +592,7 @@ func (c *Config) ClientConfig() ClientConfig {
Select("COUNT(*) AS countries").
Take(&count)
db.Model(&models.Location{}).
db.Model(&entity.Location{}).
Select("DISTINCT loc_country_code, loc_country").
Scan(&countries)

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"strings"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"testing"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"fmt"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"testing"

View file

@ -1,4 +1,4 @@
package models
package entity
// Labels can have zero or more categories with the same or a similar meaning
type Category struct {

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"github.com/gosimple/slug"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"testing"

View file

@ -7,4 +7,4 @@ Additional information concerning data storage can be found in our Developer Gui
https://github.com/photoprism/photoprism/wiki/Storage
*/
package models
package entity

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"os"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"time"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"fmt"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"testing"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"strings"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"strings"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"testing"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"github.com/gosimple/slug"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"testing"

View file

@ -1,4 +1,4 @@
package models
package entity
// Photo location
type Location struct {

View file

@ -1,4 +1,4 @@
package models
package entity
import "time"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"sort"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"time"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"testing"

View file

@ -1,4 +1,4 @@
package models
package entity
import "github.com/jinzhu/gorm"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"github.com/jinzhu/gorm"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"testing"

View file

@ -1,4 +1,4 @@
package models
package entity
import (
"time"

View file

@ -9,8 +9,8 @@ import (
"strings"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/models"
"github.com/photoprism/photoprism/internal/util"
)
@ -179,7 +179,7 @@ func (i *Importer) DestinationFilename(mainFile *MediaFile, mediaFile *MediaFile
fileExtension := mediaFile.Extension()
dateCreated := mainFile.DateCreated()
if file, err := models.FindFileByHash(i.conf.Db(), mediaFile.Hash()); err == nil {
if file, err := entity.FindFileByHash(i.conf.Db(), mediaFile.Hash()); err == nil {
existingFilename := i.conf.OriginalsPath() + string(os.PathSeparator) + file.FileName
return existingFilename, fmt.Errorf("\"%s\" is identical to \"%s\" (%s)", mediaFile.Filename(), file.FileName, mediaFile.Hash())
}

View file

@ -8,8 +8,8 @@ import (
"time"
"github.com/jinzhu/gorm"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/models"
"github.com/photoprism/photoprism/internal/util"
)
@ -22,8 +22,8 @@ const (
type IndexResult string
func (i *Indexer) indexMediaFile(mediaFile *MediaFile, o IndexerOptions) IndexResult {
var photo models.Photo
var file, primaryFile models.File
var photo entity.Photo
var file, primaryFile entity.File
var isPrimary = false
var exifData *Exif
var photoQuery, fileQuery *gorm.DB
@ -98,8 +98,8 @@ func (i *Indexer) indexMediaFile(mediaFile *MediaFile, o IndexerOptions) IndexRe
if fileChanged || o.UpdateCamera {
// Set UpdateCamera, Lens, Focal Length and F Number
photo.Camera = models.NewCamera(mediaFile.CameraModel(), mediaFile.CameraMake()).FirstOrCreate(i.db)
photo.Lens = models.NewLens(mediaFile.LensModel(), mediaFile.LensMake()).FirstOrCreate(i.db)
photo.Camera = entity.NewCamera(mediaFile.CameraModel(), mediaFile.CameraMake()).FirstOrCreate(i.db)
photo.Lens = entity.NewLens(mediaFile.LensModel(), mediaFile.LensMake()).FirstOrCreate(i.db)
photo.PhotoFocalLength = mediaFile.FocalLength()
photo.PhotoFNumber = mediaFile.FNumber()
photo.PhotoIso = mediaFile.Iso()
@ -273,7 +273,7 @@ func (i *Indexer) classifyImage(jpeg *MediaFile) (results Labels) {
func (i *Indexer) addLabels(photoId uint, labels Labels) {
for _, label := range labels {
lm := models.NewLabel(label.Name, label.Priority).FirstOrCreate(i.db)
lm := entity.NewLabel(label.Name, label.Priority).FirstOrCreate(i.db)
if lm.New {
event.Publish("count.labels", event.Data{
@ -286,11 +286,11 @@ func (i *Indexer) addLabels(photoId uint, labels Labels) {
i.db.Save(&lm)
}
plm := models.NewPhotoLabel(photoId, lm.ID, label.Uncertainty, label.Source).FirstOrCreate(i.db)
plm := entity.NewPhotoLabel(photoId, lm.ID, label.Uncertainty, label.Source).FirstOrCreate(i.db)
// Add categories
for _, category := range label.Categories {
sn := models.NewLabel(category, -1).FirstOrCreate(i.db)
sn := entity.NewLabel(category, -1).FirstOrCreate(i.db)
i.db.Model(&lm).Association("LabelCategories").Append(sn)
}
@ -302,13 +302,13 @@ func (i *Indexer) addLabels(photoId uint, labels Labels) {
}
}
func (i *Indexer) indexLocation(mediaFile *MediaFile, photo *models.Photo, keywords []string, labels Labels, fileChanged bool, o IndexerOptions) ([]string, Labels) {
func (i *Indexer) indexLocation(mediaFile *MediaFile, photo *entity.Photo, keywords []string, labels Labels, fileChanged bool, o IndexerOptions) ([]string, Labels) {
if location, err := mediaFile.Location(); err == nil {
i.db.FirstOrCreate(location, "id = ?", location.ID)
photo.Location = location
photo.LocationEstimated = false
photo.Country = models.NewCountry(location.LocCountryCode, location.LocCountry).FirstOrCreate(i.db)
photo.Country = entity.NewCountry(location.LocCountryCode, location.LocCountry).FirstOrCreate(i.db)
if photo.Country.New {
event.Publish("count.countries", event.Data{
@ -381,8 +381,8 @@ func (i *Indexer) indexLocation(mediaFile *MediaFile, photo *models.Photo, keywo
return keywords, labels
}
func (i *Indexer) estimateLocation(photo *models.Photo) {
var recentPhoto models.Photo
func (i *Indexer) estimateLocation(photo *entity.Photo) {
var recentPhoto entity.Photo
if result := i.db.Unscoped().Order(gorm.Expr("ABS(DATEDIFF(taken_at, ?)) ASC", photo.TakenAt)).Preload("Country").First(&recentPhoto); result.Error == nil {
if recentPhoto.Country != nil {

View file

@ -13,7 +13,7 @@ import (
"time"
"github.com/djherbis/times"
"github.com/photoprism/photoprism/internal/models"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/util"
)
@ -29,7 +29,7 @@ type MediaFile struct {
width int
height int
exifData *Exif
location *models.Location
location *entity.Location
}
// NewMediaFile returns a new MediaFile.

View file

@ -7,7 +7,7 @@ import (
"strconv"
"strings"
"github.com/photoprism/photoprism/internal/models"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/util"
"github.com/pkg/errors"
)
@ -37,12 +37,12 @@ type openstreetmapLocation struct {
}
// Location See https://wiki.openstreetmap.org/wiki/Nominatim#Reverse_Geocoding
func (m *MediaFile) Location() (*models.Location, error) {
func (m *MediaFile) Location() (*entity.Location, error) {
if m.location != nil {
return m.location, nil
}
location := &models.Location{}
location := &entity.Location{}
openstreetmapLocation := &openstreetmapLocation{
Address: &openstreetmapAddress{},

View file

@ -5,7 +5,7 @@ import (
"testing"
"github.com/disintegration/imaging"
"github.com/photoprism/photoprism/internal/models"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/config"
"github.com/stretchr/testify/assert"
@ -162,7 +162,7 @@ func TestThumbnails_ThumbnailFromFile(t *testing.T) {
}
t.Run("valid parameter", func(t *testing.T) {
fileModel := &models.File{
fileModel := &entity.File{
FileName: conf.ExamplesPath() + "/elephants.jpg",
FileHash: "1234568889",
}
@ -173,7 +173,7 @@ func TestThumbnails_ThumbnailFromFile(t *testing.T) {
})
t.Run("hash too short", func(t *testing.T) {
fileModel := &models.File{
fileModel := &entity.File{
FileName: conf.ExamplesPath() + "/elephants.jpg",
FileHash: "123",
}
@ -182,7 +182,7 @@ func TestThumbnails_ThumbnailFromFile(t *testing.T) {
assert.Equal(t, "file hash is empty or too short: 123", err.Error())
})
t.Run("filename too short", func(t *testing.T) {
fileModel := &models.File{
fileModel := &entity.File{
FileName: "xxx",
FileHash: "12367890",
}

View file

@ -5,8 +5,8 @@ import (
"strings"
"time"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/models"
"github.com/photoprism/photoprism/internal/util"
)
@ -26,7 +26,7 @@ type AlbumResult struct {
}
// FindAlbumByUUID returns a Album based on the UUID.
func (s *Repo) FindAlbumByUUID(albumUUID string) (album models.Album, err error) {
func (s *Repo) FindAlbumByUUID(albumUUID string) (album entity.Album, err error) {
if err := s.db.Where("album_uuid = ?", albumUUID).First(&album).Error; err != nil {
return album, err
}
@ -35,7 +35,7 @@ func (s *Repo) FindAlbumByUUID(albumUUID string) (album models.Album, err error)
}
// FindAlbumThumbByUUID returns a album preview file based on the uuid.
func (s *Repo) FindAlbumThumbByUUID(albumUUID string) (file models.File, err error) {
func (s *Repo) FindAlbumThumbByUUID(albumUUID string) (file entity.File, err error) {
// s.db.LogMode(true)
if err := s.db.Where("files.file_primary AND files.deleted_at IS NULL").

View file

@ -1,11 +1,11 @@
package repo
import "github.com/photoprism/photoprism/internal/models"
import "github.com/photoprism/photoprism/internal/entity"
// FindFiles finds files returning maximum results defined by limit
// and finding them from an offest defined by offset.
func (s *Repo) FindFiles(limit int, offset int) (files []models.File, err error) {
if err := s.db.Where(&models.File{}).Limit(limit).Offset(offset).Find(&files).Error; err != nil {
func (s *Repo) FindFiles(limit int, offset int) (files []entity.File, err error) {
if err := s.db.Where(&entity.File{}).Limit(limit).Offset(offset).Find(&files).Error; err != nil {
return files, err
}
@ -13,7 +13,7 @@ func (s *Repo) FindFiles(limit int, offset int) (files []models.File, err error)
}
// FindFilesByUUID
func (s *Repo) FindFilesByUUID(u []string, limit int, offset int) (files []models.File, err error) {
func (s *Repo) FindFilesByUUID(u []string, limit int, offset int) (files []entity.File, err error) {
if err := s.db.Where("(photo_uuid IN (?) AND file_primary = 1) OR file_uuid IN (?)", u, u).Preload("Photo").Limit(limit).Offset(offset).Find(&files).Error; err != nil {
return files, err
}
@ -22,7 +22,7 @@ func (s *Repo) FindFilesByUUID(u []string, limit int, offset int) (files []model
}
// FindFileByPhotoUUID
func (s *Repo) FindFileByPhotoUUID(u string) (file models.File, err error) {
func (s *Repo) FindFileByPhotoUUID(u string) (file entity.File, err error) {
if err := s.db.Where("photo_uuid = ? AND file_primary = 1", u).Preload("Photo").First(&file).Error; err != nil {
return file, err
}
@ -31,7 +31,7 @@ func (s *Repo) FindFileByPhotoUUID(u string) (file models.File, err error) {
}
// FindFileByID returns a mediafile given a certain ID.
func (s *Repo) FindFileByID(id string) (file models.File, err error) {
func (s *Repo) FindFileByID(id string) (file entity.File, err error) {
if err := s.db.Where("id = ?", id).Preload("Photo").First(&file).Error; err != nil {
return file, err
}
@ -40,7 +40,7 @@ func (s *Repo) FindFileByID(id string) (file models.File, err error) {
}
// FindFileByHash finds a file with a given hash string.
func (s *Repo) FindFileByHash(fileHash string) (file models.File, err error) {
func (s *Repo) FindFileByHash(fileHash string) (file entity.File, err error) {
if err := s.db.Where("file_hash = ?", fileHash).Preload("Photo").First(&file).Error; err != nil {
return file, err
}

View file

@ -5,8 +5,8 @@ import (
"strings"
"time"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/models"
"github.com/photoprism/photoprism/internal/util"
)
@ -27,7 +27,7 @@ type LabelResult struct {
}
// FindLabelBySlug returns a Label based on the slug name.
func (s *Repo) FindLabelBySlug(labelSlug string) (label models.Label, err error) {
func (s *Repo) FindLabelBySlug(labelSlug string) (label entity.Label, err error) {
if err := s.db.Where("label_slug = ?", labelSlug).First(&label).Error; err != nil {
return label, err
}
@ -36,7 +36,7 @@ func (s *Repo) FindLabelBySlug(labelSlug string) (label models.Label, err error)
}
// FindLabelThumbBySlug returns a label preview file based on the slug name.
func (s *Repo) FindLabelThumbBySlug(labelSlug string) (file models.File, err error) {
func (s *Repo) FindLabelThumbBySlug(labelSlug string) (file entity.File, err error) {
// s.db.LogMode(true)
if err := s.db.Where("files.file_primary AND files.deleted_at IS NULL").
@ -70,8 +70,8 @@ func (s *Repo) Labels(f form.LabelSearch) (results []LabelResult, err error) {
if f.Query != "" {
var labelIds []uint
var categories []models.Category
var label models.Label
var categories []entity.Category
var label entity.Label
likeString := "%" + strings.ToLower(f.Query) + "%"

View file

@ -6,8 +6,8 @@ import (
"time"
"github.com/gosimple/slug"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/models"
"github.com/photoprism/photoprism/internal/util"
)
@ -133,8 +133,8 @@ func (s *Repo) Photos(f form.PhotoSearch) (results []PhotoResult, err error) {
Joins("LEFT JOIN photos_labels ON photos_labels.photo_id = photos.id").
Where("photos.deleted_at IS NULL AND files.file_missing = 0").
Group("photos.id, files.id")
var categories []models.Category
var label models.Label
var categories []entity.Category
var label entity.Label
var labelIds []uint
if f.Label != "" {
@ -320,7 +320,7 @@ func (s *Repo) Photos(f form.PhotoSearch) (results []PhotoResult, err error) {
}
// FindPhotoByID returns a Photo based on the ID.
func (s *Repo) FindPhotoByID(photoID uint64) (photo models.Photo, err error) {
func (s *Repo) FindPhotoByID(photoID uint64) (photo entity.Photo, err error) {
if err := s.db.Where("id = ?", photoID).First(&photo).Error; err != nil {
return photo, err
}
@ -329,7 +329,7 @@ func (s *Repo) FindPhotoByID(photoID uint64) (photo models.Photo, err error) {
}
// FindPhotoByUUID returns a Photo based on the UUID.
func (s *Repo) FindPhotoByUUID(photoUUID string) (photo models.Photo, err error) {
func (s *Repo) FindPhotoByUUID(photoUUID string) (photo entity.Photo, err error) {
if err := s.db.Where("photo_uuid = ?", photoUUID).First(&photo).Error; err != nil {
return photo, err
}