добавил архив фото, откуда можно удалить и посмотреть

This commit is contained in:
2026-01-19 05:17:15 +03:00
parent bc036197cf
commit 323fc67cd5
12 changed files with 648 additions and 26 deletions

View 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
}