mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-04 19:02:33 -06:00
добавил архив фото, откуда можно удалить и посмотреть
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"rmser/internal/domain/invoices"
|
||||
"rmser/internal/domain/ocr"
|
||||
"rmser/internal/domain/operations"
|
||||
"rmser/internal/domain/photos"
|
||||
"rmser/internal/domain/recipes"
|
||||
"rmser/internal/domain/recommendations"
|
||||
"rmser/internal/domain/suppliers"
|
||||
@@ -68,6 +69,7 @@ func NewPostgresDB(dsn string) *gorm.DB {
|
||||
&recommendations.Recommendation{},
|
||||
&ocr.ProductMatch{},
|
||||
&ocr.UnmatchedItem{},
|
||||
&photos.ReceiptPhoto{},
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("ошибка миграции БД: %v", err))
|
||||
|
||||
70
internal/infrastructure/repository/photos/postgres.go
Normal file
70
internal/infrastructure/repository/photos/postgres.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package photos
|
||||
|
||||
import (
|
||||
"rmser/internal/domain/photos"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type pgRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewRepository(db *gorm.DB) photos.Repository {
|
||||
return &pgRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *pgRepository) Create(photo *photos.ReceiptPhoto) error {
|
||||
return r.db.Create(photo).Error
|
||||
}
|
||||
|
||||
func (r *pgRepository) GetByID(id uuid.UUID) (*photos.ReceiptPhoto, error) {
|
||||
var photo photos.ReceiptPhoto
|
||||
err := r.db.First(&photo, id).Error
|
||||
return &photo, err
|
||||
}
|
||||
|
||||
func (r *pgRepository) GetByServerID(serverID uuid.UUID, page, limit int) ([]photos.ReceiptPhoto, int64, error) {
|
||||
var items []photos.ReceiptPhoto
|
||||
var total int64
|
||||
|
||||
offset := (page - 1) * limit
|
||||
|
||||
err := r.db.Model(&photos.ReceiptPhoto{}).
|
||||
Where("rms_server_id = ?", serverID).
|
||||
Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = r.db.Where("rms_server_id = ?", serverID).
|
||||
Order("created_at DESC").
|
||||
Offset(offset).
|
||||
Limit(limit).
|
||||
Find(&items).Error
|
||||
|
||||
return items, total, err
|
||||
}
|
||||
|
||||
func (r *pgRepository) UpdateDraftLink(photoID uuid.UUID, draftID *uuid.UUID) error {
|
||||
return r.db.Model(&photos.ReceiptPhoto{}).
|
||||
Where("id = ?", photoID).
|
||||
Update("draft_id", draftID).Error
|
||||
}
|
||||
|
||||
func (r *pgRepository) UpdateInvoiceLink(photoID uuid.UUID, invoiceID *uuid.UUID) error {
|
||||
return r.db.Model(&photos.ReceiptPhoto{}).
|
||||
Where("id = ?", photoID).
|
||||
Update("invoice_id", invoiceID).Error
|
||||
}
|
||||
|
||||
func (r *pgRepository) ClearDraftLinkByDraftID(draftID uuid.UUID) error {
|
||||
return r.db.Model(&photos.ReceiptPhoto{}).
|
||||
Where("draft_id = ?", draftID).
|
||||
Update("draft_id", nil).Error
|
||||
}
|
||||
|
||||
func (r *pgRepository) Delete(id uuid.UUID) error {
|
||||
return r.db.Delete(&photos.ReceiptPhoto{}, id).Error
|
||||
}
|
||||
Reference in New Issue
Block a user