Rename Config.GetDb() to Db(), see #50

This commit is contained in:
Michael Mayer
2018-12-21 02:37:16 +01:00
parent 9e4c134e29
commit 0f12aac73b
13 changed files with 24 additions and 24 deletions

View File

@@ -29,7 +29,7 @@ func GetPhotos(router *gin.RouterGroup, conf photoprism.Config) {
router.GET("/photos", func(c *gin.Context) { router.GET("/photos", func(c *gin.Context) {
var form forms.PhotoSearchForm var form forms.PhotoSearchForm
search := photoprism.NewSearch(conf.GetOriginalsPath(), conf.GetDb()) search := photoprism.NewSearch(conf.GetOriginalsPath(), conf.Db())
c.MustBindWith(&form, binding.Form) 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 // photoId: int Photo ID as returned by the API
func LikePhoto(router *gin.RouterGroup, conf photoprism.Config) { func LikePhoto(router *gin.RouterGroup, conf photoprism.Config) {
router.POST("/photos/:photoId/like", func(c *gin.Context) { 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) photoId, err := strconv.ParseUint(c.Param("photoId"), 10, 64)
if err == nil { if err == nil {
photo := search.FindPhotoByID(photoId) photo := search.FindPhotoByID(photoId)
photo.PhotoFavorite = true photo.PhotoFavorite = true
conf.GetDb().Save(&photo) conf.Db().Save(&photo)
c.JSON(http.StatusOK, http.Response{}) c.JSON(http.StatusOK, http.Response{})
} else { } else {
log.Printf("could not find image for id: %s", err.Error()) 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 // photoId: int Photo ID as returned by the API
func DislikePhoto(router *gin.RouterGroup, conf photoprism.Config) { func DislikePhoto(router *gin.RouterGroup, conf photoprism.Config) {
router.DELETE("/photos/:photoId/like", func(c *gin.Context) { 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) photoId, err := strconv.ParseUint(c.Param("photoId"), 10, 64)
if err == nil { if err == nil {
photo := search.FindPhotoByID(photoId) photo := search.FindPhotoByID(photoId)
photo.PhotoFavorite = false photo.PhotoFavorite = false
conf.GetDb().Save(&photo) conf.Db().Save(&photo)
c.JSON(http.StatusOK, http.Response{}) c.JSON(http.StatusOK, http.Response{})
} else { } else {
log.Printf("could not find image for id: %s", err.Error()) log.Printf("could not find image for id: %s", err.Error())

View File

@@ -32,7 +32,7 @@ func GetThumbnail(router *gin.RouterGroup, conf photoprism.Config) {
c.Data(400, "image/svg+xml", photoIconSvg) 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) 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 // Set missing flag so that the file doesn't show up in search results anymore
file.FileMissing = true file.FileMissing = true
conf.GetDb().Save(&file) conf.Db().Save(&file)
} }
}) })
} }

View File

@@ -29,7 +29,7 @@ func importAction(ctx *cli.Context) error {
tensorFlow := photoprism.NewTensorFlow(conf.GetTensorFlowModelPath()) 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()) converter := photoprism.NewConverter(conf.GetDarktableCli())

View File

@@ -29,7 +29,7 @@ func indexAction(ctx *cli.Context) error {
tensorFlow := photoprism.NewTensorFlow(conf.GetTensorFlowModelPath()) tensorFlow := photoprism.NewTensorFlow(conf.GetTensorFlowModelPath())
indexer := photoprism.NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.GetDb()) indexer := photoprism.NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.Db())
indexer.IndexAll() indexer.IndexAll()

View File

@@ -427,7 +427,7 @@ func (c *Config) GetPublicBuildPath() string {
} }
// GetDb returns the db connection. // GetDb returns the db connection.
func (c *Config) GetDb() *gorm.DB { func (c *Config) Db() *gorm.DB {
if c.db == nil { if c.db == nil {
c.connectToDatabase() c.connectToDatabase()
} }
@@ -437,7 +437,7 @@ func (c *Config) GetDb() *gorm.DB {
// MigrateDb will start a migration process. // MigrateDb will start a migration process.
func (c *Config) MigrateDb() { func (c *Config) MigrateDb() {
db := c.GetDb() db := c.Db()
db.AutoMigrate(&models.File{}, db.AutoMigrate(&models.File{},
&models.Photo{}, &models.Photo{},
@@ -451,7 +451,7 @@ func (c *Config) MigrateDb() {
// GetClientConfig returns a loaded and set configuration entity. // GetClientConfig returns a loaded and set configuration entity.
func (c *Config) GetClientConfig() frontend.Config { func (c *Config) GetClientConfig() frontend.Config {
db := c.GetDb() db := c.Db()
var cameras []*models.Camera var cameras []*models.Camera

View File

@@ -12,7 +12,7 @@ type Config interface {
CreateDirectories() error CreateDirectories() error
MigrateDb() MigrateDb()
GetDb() *gorm.DB Db() *gorm.DB
GetClientConfig() frontend.Config GetClientConfig() frontend.Config
GetConfigFile() string GetConfigFile() string

View File

@@ -65,7 +65,7 @@ func TestContextConfig_SetValuesFromFile(t *testing.T) {
func TestTestConfig_ConnectToDatabase(t *testing.T) { func TestTestConfig_ConnectToDatabase(t *testing.T) {
c := test.NewConfig() c := test.NewConfig()
db := c.GetDb() db := c.Db()
assert.IsType(t, &gorm.DB{}, db) assert.IsType(t, &gorm.DB{}, db)
} }

View File

@@ -15,7 +15,7 @@ func TestImporter_ImportPhotosFromDirectory(t *testing.T) {
tensorFlow := NewTensorFlow(conf.GetTensorFlowModelPath()) tensorFlow := NewTensorFlow(conf.GetTensorFlowModelPath())
indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.GetDb()) indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.Db())
converter := NewConverter(conf.GetDarktableCli()) converter := NewConverter(conf.GetDarktableCli())

View File

@@ -12,7 +12,7 @@ func TestNewImporter(t *testing.T) {
tensorFlow := NewTensorFlow(conf.GetTensorFlowModelPath()) tensorFlow := NewTensorFlow(conf.GetTensorFlowModelPath())
indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.GetDb()) indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.Db())
converter := NewConverter(conf.GetDarktableCli()) converter := NewConverter(conf.GetDarktableCli())
@@ -27,7 +27,7 @@ func TestImporter_GetDestinationFilename(t *testing.T) {
tensorFlow := NewTensorFlow(conf.GetTensorFlowModelPath()) tensorFlow := NewTensorFlow(conf.GetTensorFlowModelPath())
indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.GetDb()) indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.Db())
converter := NewConverter(conf.GetDarktableCli()) converter := NewConverter(conf.GetDarktableCli())

View File

@@ -14,7 +14,7 @@ func TestSearch_Photos_Query(t *testing.T) {
conf.InitializeTestData(t) conf.InitializeTestData(t)
search := NewSearch(conf.GetOriginalsPath(), conf.GetDb()) search := NewSearch(conf.GetOriginalsPath(), conf.Db())
var form forms.PhotoSearchForm var form forms.PhotoSearchForm
@@ -47,7 +47,7 @@ func TestSearch_Photos_Camera(t *testing.T) {
conf.InitializeTestData(t) conf.InitializeTestData(t)
search := NewSearch(conf.GetOriginalsPath(), conf.GetDb()) search := NewSearch(conf.GetOriginalsPath(), conf.Db())
var form forms.PhotoSearchForm var form forms.PhotoSearchForm

View File

@@ -17,7 +17,7 @@ func TestCreateThumbnailsFromOriginals(t *testing.T) {
tensorFlow := NewTensorFlow(conf.GetTensorFlowModelPath()) tensorFlow := NewTensorFlow(conf.GetTensorFlowModelPath())
indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.GetDb()) indexer := NewIndexer(conf.GetOriginalsPath(), tensorFlow, conf.Db())
converter := NewConverter(conf.GetDarktableCli()) converter := NewConverter(conf.GetDarktableCli())

View File

@@ -284,7 +284,7 @@ func (c *Config) GetPublicBuildPath() string {
} }
// GetDb gets a db connection. If it already is estabilished it will return that. // 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 { if c.db == nil {
c.connectToDatabase() c.connectToDatabase()
} }
@@ -294,7 +294,7 @@ func (c *Config) GetDb() *gorm.DB {
// MigrateDb will start a migration process. // MigrateDb will start a migration process.
func (c *Config) MigrateDb() { func (c *Config) MigrateDb() {
db := c.GetDb() db := c.Db()
db.AutoMigrate(&models.File{}, db.AutoMigrate(&models.File{},
&models.Photo{}, &models.Photo{},
@@ -308,7 +308,7 @@ func (c *Config) MigrateDb() {
// GetClientConfig returns a loaded and set configuration entity. // GetClientConfig returns a loaded and set configuration entity.
func (c *Config) GetClientConfig() frontend.Config { func (c *Config) GetClientConfig() frontend.Config {
db := c.GetDb() db := c.Db()
var cameras []*models.Camera var cameras []*models.Camera

View File

@@ -19,7 +19,7 @@ func TestNewConfig(t *testing.T) {
func TestConfig_ConnectToDatabase(t *testing.T) { func TestConfig_ConnectToDatabase(t *testing.T) {
c := NewConfig() c := NewConfig()
db := c.GetDb() db := c.Db()
assert.IsType(t, &gorm.DB{}, db) assert.IsType(t, &gorm.DB{}, db)
} }