feat: add image management functionality
- Implemented image folder repository with CRUD operations. - Added image reference repository for managing image references to articles. - Created image repository for handling image assets, including listing, inserting, updating, and deleting images. - Introduced image usage repository to track storage usage and quotas for tenants. - Added SQL queries for image assets, folders, references, and usage. - Developed image handler for HTTP endpoints to manage images and folders. - Created database migration scripts for image-related tables and structures.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/shared/messaging/rabbitmq"
|
||||
)
|
||||
|
||||
const (
|
||||
imageAssetTaskKindFinalizeUpload = "finalize_upload"
|
||||
imageAssetTaskKindFinalizeDelete = "finalize_delete"
|
||||
)
|
||||
|
||||
type imageAssetTaskEnvelope struct {
|
||||
Kind string `json:"kind"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
AssetID int64 `json:"asset_id"`
|
||||
}
|
||||
|
||||
type ImageAssetTaskEnvelope struct {
|
||||
Kind string `json:"kind"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
AssetID int64 `json:"asset_id"`
|
||||
}
|
||||
|
||||
func publishImageAssetTask(ctx context.Context, client *rabbitmq.Client, envelope imageAssetTaskEnvelope) error {
|
||||
if client == nil {
|
||||
return fmt.Errorf("rabbitmq client is not configured")
|
||||
}
|
||||
|
||||
payload, err := json.Marshal(envelope)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal image asset task envelope: %w", err)
|
||||
}
|
||||
|
||||
if err := client.PublishImageAssetTask(ctx, payload); err != nil {
|
||||
return fmt.Errorf("publish image asset task: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func decodeImageAssetTaskEnvelope(payload []byte) (*imageAssetTaskEnvelope, error) {
|
||||
var envelope imageAssetTaskEnvelope
|
||||
if err := json.Unmarshal(payload, &envelope); err != nil {
|
||||
return nil, fmt.Errorf("decode image asset task envelope: %w", err)
|
||||
}
|
||||
if envelope.TenantID <= 0 || envelope.AssetID <= 0 {
|
||||
return nil, fmt.Errorf("image asset task envelope is incomplete")
|
||||
}
|
||||
switch envelope.Kind {
|
||||
case imageAssetTaskKindFinalizeUpload, imageAssetTaskKindFinalizeDelete:
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported image asset task kind %q", envelope.Kind)
|
||||
}
|
||||
return &envelope, nil
|
||||
}
|
||||
|
||||
func DecodeImageAssetTaskEnvelope(payload []byte) (*ImageAssetTaskEnvelope, error) {
|
||||
envelope, err := decodeImageAssetTaskEnvelope(payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ImageAssetTaskEnvelope{
|
||||
Kind: envelope.Kind,
|
||||
TenantID: envelope.TenantID,
|
||||
AssetID: envelope.AssetID,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user