feat: add posts

This commit is contained in:
Rogee
2025-01-15 14:47:10 +08:00
parent ab827715fb
commit 9002862415
13 changed files with 374 additions and 104 deletions

View File

@@ -70,8 +70,8 @@ func (ctl *Controller) Upload(ctx fiber.Ctx, claim *jwt.Claims, tenantSlug strin
TenantID: tenant.ID,
UserID: claim.UserID,
StorageID: defaultStorage.ID,
Hash: uploadedFile.Hash,
Name: uploadedFile.Name,
UUID: uploadedFile.Hash,
MimeType: uploadedFile.MimeType,
Size: uploadedFile.Size,
Path: uploadedFile.Path,

View File

@@ -9,6 +9,7 @@ import (
"backend/providers/otel"
. "github.com/go-jet/jet/v2/postgres"
"github.com/samber/lo"
log "github.com/sirupsen/logrus"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
)
@@ -40,3 +41,34 @@ func (svc *Service) Create(ctx context.Context, m *model.Medias) (*model.Medias,
}
return &ret, nil
}
// GetMediasByHash
func (svc *Service) GetMediasByHash(ctx context.Context, tenantID, userID int64, hashes []string) ([]*model.Medias, error) {
_, span := otel.Start(ctx, "medias.service.GetMediasByHash")
defer span.End()
hashExpr := lo.Map(hashes, func(item string, index int) Expression { return String(item) })
tbl := table.Medias
stmt := tbl.
SELECT(tbl.AllColumns).
WHERE(
tbl.TenantID.
EQ(Int64(tenantID)).
AND(
tbl.UserID.EQ(Int64(userID)),
).
AND(
tbl.Hash.IN(hashExpr...),
),
)
span.SetAttributes(semconv.DBStatementKey.String(stmt.DebugSql()))
var ret []model.Medias
if err := stmt.QueryContext(ctx, svc.db, &ret); err != nil {
return nil, err
}
return lo.Map(ret, func(item model.Medias, _ int) *model.Medias {
return &item
}), nil
}