dana-medical-site/internal/storage/media.go
2026-10-14 13:33:13 +00:00

34 lines
1.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package storage
import "context"
// CreateMedia регистрирует уже сохранённый на диск файл. width/height могут быть
// nil, если размер картинки определить не удалось.
func (s *Storage) CreateMedia(ctx context.Context, path, mime string, size int64,
width, height *int, alt string) (int64, error) {
var id int64
err := s.pool.QueryRow(ctx, `
INSERT INTO media (path, mime, size, width, height, alt)
VALUES ($1,$2,$3,$4,$5,$6) RETURNING id`,
path, mime, size, width, height, alt).Scan(&id)
return id, err
}
// CreateSiteReview кладёт отзыв, оставленный на сайте, в очередь модерации.
// На сайте он появится только после публикации в админке.
func (s *Storage) CreateSiteReview(ctx context.Context, author, text string,
rating *int, doctorID *int64) error {
_, err := s.pool.Exec(ctx, `
INSERT INTO reviews (author_name, rating, text, doctor_id, source, status)
VALUES ($1, $2, $3, $4, 'site', 'pending')`,
author, rating, text, doctorID)
return err
}
// MediaMime отдаёт тип файла из медиатеки: админка проверяет, что в поле картинки не попал PDF.
func (s *Storage) MediaMime(ctx context.Context, id int64) (string, error) {
var mime string
err := s.pool.QueryRow(ctx, `SELECT mime FROM media WHERE id=$1`, id).Scan(&mime)
return mime, wrapNotFound(err)
}