feat: add posts
This commit is contained in:
@@ -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