feat: add posts
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user