mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Rename Config.GetDb() to Db(), see #50
This commit is contained in:
@@ -29,7 +29,7 @@ func GetPhotos(router *gin.RouterGroup, conf photoprism.Config) {
|
||||
router.GET("/photos", func(c *gin.Context) {
|
||||
var form forms.PhotoSearchForm
|
||||
|
||||
search := photoprism.NewSearch(conf.GetOriginalsPath(), conf.GetDb())
|
||||
search := photoprism.NewSearch(conf.GetOriginalsPath(), conf.Db())
|
||||
|
||||
c.MustBindWith(&form, binding.Form)
|
||||
|
||||
@@ -52,14 +52,14 @@ func GetPhotos(router *gin.RouterGroup, conf photoprism.Config) {
|
||||
// photoId: int Photo ID as returned by the API
|
||||
func LikePhoto(router *gin.RouterGroup, conf photoprism.Config) {
|
||||
router.POST("/photos/:photoId/like", func(c *gin.Context) {
|
||||
search := photoprism.NewSearch(conf.GetOriginalsPath(), conf.GetDb())
|
||||
search := photoprism.NewSearch(conf.GetOriginalsPath(), conf.Db())
|
||||
|
||||
photoId, err := strconv.ParseUint(c.Param("photoId"), 10, 64)
|
||||
|
||||
if err == nil {
|
||||
photo := search.FindPhotoByID(photoId)
|
||||
photo.PhotoFavorite = true
|
||||
conf.GetDb().Save(&photo)
|
||||
conf.Db().Save(&photo)
|
||||
c.JSON(http.StatusOK, http.Response{})
|
||||
} else {
|
||||
log.Printf("could not find image for id: %s", err.Error())
|
||||
@@ -74,14 +74,14 @@ func LikePhoto(router *gin.RouterGroup, conf photoprism.Config) {
|
||||
// photoId: int Photo ID as returned by the API
|
||||
func DislikePhoto(router *gin.RouterGroup, conf photoprism.Config) {
|
||||
router.DELETE("/photos/:photoId/like", func(c *gin.Context) {
|
||||
search := photoprism.NewSearch(conf.GetOriginalsPath(), conf.GetDb())
|
||||
search := photoprism.NewSearch(conf.GetOriginalsPath(), conf.Db())
|
||||
|
||||
photoId, err := strconv.ParseUint(c.Param("photoId"), 10, 64)
|
||||
|
||||
if err == nil {
|
||||
photo := search.FindPhotoByID(photoId)
|
||||
photo.PhotoFavorite = false
|
||||
conf.GetDb().Save(&photo)
|
||||
conf.Db().Save(&photo)
|
||||
c.JSON(http.StatusOK, http.Response{})
|
||||
} else {
|
||||
log.Printf("could not find image for id: %s", err.Error())
|
||||
|
||||
@@ -32,7 +32,7 @@ func GetThumbnail(router *gin.RouterGroup, conf photoprism.Config) {
|
||||
c.Data(400, "image/svg+xml", photoIconSvg)
|
||||
}
|
||||
|
||||
search := photoprism.NewSearch(conf.GetOriginalsPath(), conf.GetDb())
|
||||
search := photoprism.NewSearch(conf.GetOriginalsPath(), conf.Db())
|
||||
|
||||
file := search.FindFileByHash(fileHash)
|
||||
|
||||
@@ -64,7 +64,7 @@ func GetThumbnail(router *gin.RouterGroup, conf photoprism.Config) {
|
||||
|
||||
// Set missing flag so that the file doesn't show up in search results anymore
|
||||
file.FileMissing = true
|
||||
conf.GetDb().Save(&file)
|
||||
conf.Db().Save(&file)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func importAction(ctx *cli.Context) error {
|
||||
|
||||
tensorFlow := photoprism.NewTensorFlow(conf.GetTensorFlowModelPath())
|
||||
|
||||
indexer := photoprism.NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.GetDb())
|
||||
indexer := photoprism.NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.Db())
|
||||
|
||||
converter := photoprism.NewConverter(conf.GetDarktableCli())
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ func indexAction(ctx *cli.Context) error {
|
||||
|
||||
tensorFlow := photoprism.NewTensorFlow(conf.GetTensorFlowModelPath())
|
||||
|
||||
indexer := photoprism.NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.GetDb())
|
||||
indexer := photoprism.NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.Db())
|
||||
|
||||
indexer.IndexAll()
|
||||
|
||||
|
||||
@@ -427,7 +427,7 @@ func (c *Config) GetPublicBuildPath() string {
|
||||
}
|
||||
|
||||
// GetDb returns the db connection.
|
||||
func (c *Config) GetDb() *gorm.DB {
|
||||
func (c *Config) Db() *gorm.DB {
|
||||
if c.db == nil {
|
||||
c.connectToDatabase()
|
||||
}
|
||||
@@ -437,7 +437,7 @@ func (c *Config) GetDb() *gorm.DB {
|
||||
|
||||
// MigrateDb will start a migration process.
|
||||
func (c *Config) MigrateDb() {
|
||||
db := c.GetDb()
|
||||
db := c.Db()
|
||||
|
||||
db.AutoMigrate(&models.File{},
|
||||
&models.Photo{},
|
||||
@@ -451,7 +451,7 @@ func (c *Config) MigrateDb() {
|
||||
|
||||
// GetClientConfig returns a loaded and set configuration entity.
|
||||
func (c *Config) GetClientConfig() frontend.Config {
|
||||
db := c.GetDb()
|
||||
db := c.Db()
|
||||
|
||||
var cameras []*models.Camera
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ type Config interface {
|
||||
CreateDirectories() error
|
||||
MigrateDb()
|
||||
|
||||
GetDb() *gorm.DB
|
||||
Db() *gorm.DB
|
||||
GetClientConfig() frontend.Config
|
||||
|
||||
GetConfigFile() string
|
||||
|
||||
@@ -65,7 +65,7 @@ func TestContextConfig_SetValuesFromFile(t *testing.T) {
|
||||
func TestTestConfig_ConnectToDatabase(t *testing.T) {
|
||||
c := test.NewConfig()
|
||||
|
||||
db := c.GetDb()
|
||||
db := c.Db()
|
||||
|
||||
assert.IsType(t, &gorm.DB{}, db)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func TestImporter_ImportPhotosFromDirectory(t *testing.T) {
|
||||
|
||||
tensorFlow := NewTensorFlow(conf.GetTensorFlowModelPath())
|
||||
|
||||
indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.GetDb())
|
||||
indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.Db())
|
||||
|
||||
converter := NewConverter(conf.GetDarktableCli())
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ func TestNewImporter(t *testing.T) {
|
||||
|
||||
tensorFlow := NewTensorFlow(conf.GetTensorFlowModelPath())
|
||||
|
||||
indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.GetDb())
|
||||
indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.Db())
|
||||
|
||||
converter := NewConverter(conf.GetDarktableCli())
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestImporter_GetDestinationFilename(t *testing.T) {
|
||||
|
||||
tensorFlow := NewTensorFlow(conf.GetTensorFlowModelPath())
|
||||
|
||||
indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.GetDb())
|
||||
indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.Db())
|
||||
|
||||
converter := NewConverter(conf.GetDarktableCli())
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestSearch_Photos_Query(t *testing.T) {
|
||||
|
||||
conf.InitializeTestData(t)
|
||||
|
||||
search := NewSearch(conf.GetOriginalsPath(), conf.GetDb())
|
||||
search := NewSearch(conf.GetOriginalsPath(), conf.Db())
|
||||
|
||||
var form forms.PhotoSearchForm
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestSearch_Photos_Camera(t *testing.T) {
|
||||
|
||||
conf.InitializeTestData(t)
|
||||
|
||||
search := NewSearch(conf.GetOriginalsPath(), conf.GetDb())
|
||||
search := NewSearch(conf.GetOriginalsPath(), conf.Db())
|
||||
|
||||
var form forms.PhotoSearchForm
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestCreateThumbnailsFromOriginals(t *testing.T) {
|
||||
|
||||
tensorFlow := NewTensorFlow(conf.GetTensorFlowModelPath())
|
||||
|
||||
indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.GetDb())
|
||||
indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.Db())
|
||||
|
||||
converter := NewConverter(conf.GetDarktableCli())
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ func (c *Config) GetPublicBuildPath() string {
|
||||
}
|
||||
|
||||
// GetDb gets a db connection. If it already is estabilished it will return that.
|
||||
func (c *Config) GetDb() *gorm.DB {
|
||||
func (c *Config) Db() *gorm.DB {
|
||||
if c.db == nil {
|
||||
c.connectToDatabase()
|
||||
}
|
||||
@@ -294,7 +294,7 @@ func (c *Config) GetDb() *gorm.DB {
|
||||
|
||||
// MigrateDb will start a migration process.
|
||||
func (c *Config) MigrateDb() {
|
||||
db := c.GetDb()
|
||||
db := c.Db()
|
||||
|
||||
db.AutoMigrate(&models.File{},
|
||||
&models.Photo{},
|
||||
@@ -308,7 +308,7 @@ func (c *Config) MigrateDb() {
|
||||
|
||||
// GetClientConfig returns a loaded and set configuration entity.
|
||||
func (c *Config) GetClientConfig() frontend.Config {
|
||||
db := c.GetDb()
|
||||
db := c.Db()
|
||||
|
||||
var cameras []*models.Camera
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestNewConfig(t *testing.T) {
|
||||
func TestConfig_ConnectToDatabase(t *testing.T) {
|
||||
c := NewConfig()
|
||||
|
||||
db := c.GetDb()
|
||||
db := c.Db()
|
||||
|
||||
assert.IsType(t, &gorm.DB{}, db)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user