infoalloggi-monorepo/apps/backend/queries/images.go
Marco Pedone 1ac2d4b3ab Refactor storage handlers to use centralized configuration
- Updated `fs.go` and `minio.go` to replace hardcoded storage paths with values from the new config package.
- Introduced a new `config` package to manage application configuration, including database and storage settings.
- Removed the `models.go` file from `typedefs` as it was no longer needed.
- Added a new `config.go` file to handle loading environment variables and application settings.
- Created a new `types.go` file in `typedefs` to define storage strategies.
- Updated `storage_handler.go` to utilize the new configuration structure.
2025-08-22 12:57:33 +02:00

44 lines
1.1 KiB
Go

package queries
import (
"backend/typesdefs"
"fmt"
"github.com/georgysavva/scany/v2/pgxscan"
"github.com/jackc/pgx/v5"
)
func ImagesGetAll() ([]typesdefs.MiogestImagesRef_Table, error) {
var images []typesdefs.MiogestImagesRef_Table
err := pgxscan.Select(Db.Ctx, Db.Dbpool, &images, "SELECT * FROM public.miogest_images_ref")
if err != nil && err != pgx.ErrNoRows {
return nil, fmt.Errorf("failed to get all images: %w", err)
}
return images, nil
}
func ImagesBatchInsert(annunci *typesdefs.AnnunciXML) error {
batch := &pgx.Batch{}
for _, annuncio := range annunci.Annuncio {
batch.Queue(`
INSERT INTO public.miogest_images_ref (codice, foto)
VALUES ($1, $2)
ON CONFLICT (codice) DO UPDATE SET foto = $2
`, &annuncio.Codice, &annuncio.Foto)
}
if err := Db.Dbpool.SendBatch(Db.Ctx, batch).Close(); err != nil {
return fmt.Errorf("failed to insert/update images batch: %w", err)
}
return nil
}
func ImagesClear() error {
_, err := Db.Dbpool.Exec(Db.Ctx, "DELETE FROM public.miogest_images_ref")
if err != nil {
return fmt.Errorf("failed to clear images: %w", err)
}
return nil
}